imagemagick 方形到圆形裁剪并合并为图标
我通过 PHP 使用 ImageMagick 并希望扩展此资源:
http:// /joedesigns.com/v22/?page=scripts_widgets&id=15
<?php
function sqThm($src,$dest,$size=75){
$squareSize = 70;
list($w,$h) = getimagesize($src);
if($w > $h){
exec("convert ".$src." -resize x".$size." -quality 100 ".$dest);
}else{
exec("convert ".$src." -resize ".$size." -quality 100 ".$dest);
}
exec("convert ".$dest." -gravity Center -crop ".$size."x".$size."+0+0 ".$dest);
}
if(!$_GET[imgtosquare]){
print "
<p>Click on the image you want to conver to a square.</p>
<p><a href='index.php?imgtosquare=1'><img src='gfx/1.jpg' border='0'></a></p>
<p><a href='index.php?imgtosquare=2'><img src='gfx/2.jpg' border='0'></a></p>
";
}else{
if($_GET[imgtosquare] != '1' && $_GET[imgtosquare] != '2'){ exit; }
sqThm("gfx/".$_GET[imgtosquare].".jpg","gfx/".$_GET[imgtosquare]."_squared.jpg");
print "
<p>Here is your squared image.</p>
<p><img src='gfx/".$_GET[imgtosquare]."_squared.jpg' border='0'></p>
";
}
?>
...它获取图像并生成我想要的 flickr 风格的方形图像仍然保存,但还进一步处理以获取此:
并将其生成为附加保存文件:
(注意方格区域是透明的)
我将如何修改脚本来执行此操作?另外,请注意,我预计要处理大量这些图像,因此执行效率也很重要。最后 - 尽管输入文件可能是 JPG,但所有结果图像的格式均为 PNG。
I'm using ImageMagick via PHP and would like to extend on this resource:
http://joedesigns.com/v22/?page=scripts_widgets&id=15
<?php
function sqThm($src,$dest,$size=75){
$squareSize = 70;
list($w,$h) = getimagesize($src);
if($w > $h){
exec("convert ".$src." -resize x".$size." -quality 100 ".$dest);
}else{
exec("convert ".$src." -resize ".$size." -quality 100 ".$dest);
}
exec("convert ".$dest." -gravity Center -crop ".$size."x".$size."+0+0 ".$dest);
}
if(!$_GET[imgtosquare]){
print "
<p>Click on the image you want to conver to a square.</p>
<p><a href='index.php?imgtosquare=1'><img src='gfx/1.jpg' border='0'></a></p>
<p><a href='index.php?imgtosquare=2'><img src='gfx/2.jpg' border='0'></a></p>
";
}else{
if($_GET[imgtosquare] != '1' && $_GET[imgtosquare] != '2'){ exit; }
sqThm("gfx/".$_GET[imgtosquare].".jpg","gfx/".$_GET[imgtosquare]."_squared.jpg");
print "
<p>Here is your squared image.</p>
<p><img src='gfx/".$_GET[imgtosquare]."_squared.jpg' border='0'></p>
";
}
?>
...which takes an image and produces a flickr style squared image that I want to still save but also further process to take this:
and produce this as an additional saved file:
(Note the checkered areas are transparent)
How would I modify the script to do this? Also, please note that I expect a large volume of these images to be processed, so execution efficiency is also important. Finally - the format for all resulting images will be PNG, although input file may be JPG.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例书包含所有可以想象到的关于 ImageMagick 使用的示例。检查一下。
蒙版一章应该有助于实现您的目标,尽管它可能需要您编辑粉红色进一步的原始图像。
The examples book has every imaginable example on ImageMagick usage. Check them out.
The Masks chapter should help achieving your goal, although it may require you to edit your pink original image further.