imagemagick 方形到圆形裁剪并合并为图标

发布于 2024-12-04 11:09:01 字数 1686 浏览 0 评论 0原文

我通过 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 风格的方形图像仍然保存,但还进一步处理以获取此:

icon base

并将其生成为附加保存文件:

end result

(注意方格区域是透明的)

我将如何修改脚本来执行此操作?另外,请注意,我预计要处理大量这些图像,因此执行效率也很重要。最后 - 尽管输入文件可能是 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:

icon base

and produce this as an additional saved file:

end result

(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↙厌世 2024-12-11 11:09:01

示例书包含所有可以想象到的关于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文