Inator
Inator

Reputation: 1024

imagemagick square to circle crop and merge as icon

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.

Upvotes: 1

Views: 2198

Answers (1)

Pekka
Pekka

Reputation: 449435

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.

Upvotes: 1

Related Questions