How to make a image in desired shape in imagemagick?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.

How to make a image in desired shape in imagemagick?

Postby jokepondy » 2010-02-02T20:08:49+00:00

Hello Guys..

This is my first post .very happy to see u all genious. I have small doubt. anyone can help ?

How can i make a image to specified shape like cricle,oval,heart shape,diamond. I am not asking the line images ..just i want to make the user image in to circle or some different shape for user profile. Ur help precious for me
jokepondy
 
Posts: 8
Joined: 2010-02-02T19:52:37+00:00

Re: How to make a image in desired shape in imagemagick?

Postby fmw42 » 2010-02-02T20:36:08+00:00

you make the shape as a black and white mask and then composite it with the image into the alpha channel so that the outside of the shape (which is black) becomes transparent and the inside of the shape (which is white) maintains the image color.

Image

convert zelda3.jpg \
\( +clone -threshold -1 -negate -fill white -draw "circle 64,64 64,0" \) \
-alpha off -compose copy_opacity -composite zelda3_circ.gif

Image

the second line copies the image (+clone), then thresholds it to white, then negates it to black, then draws a white circle on it.
the third line puts the mask from the second line into the alpha channel of the original image in line 1

see
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/compose/#copyopacity
http://www.imagemagick.org/Usage/draw/

good reading and lots of examples at
http://www.imagemagick.org/Usage/
User avatar
fmw42
 
Posts: 14587
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: How to make a image in desired shape in imagemagick?

Postby jokepondy » 2010-02-02T22:49:09+00:00

Hello Frnd

Thanks for your reply really looking nice. but i have few problem when i execute your code .. i place this what i proceed with myself.

$samp7 = "images/test1.jpg";
$samp101 = "images/circles.gif";

exec('convert $samp7 \( +clone -threshold -1 -negate -fill white -draw "circle 64,64 64,0" \) -alpha off -compose copy_opacity -composite $samp101');

but i got empty image ..i think something wrong in my code ..can u help me with this
jokepondy
 
Posts: 8
Joined: 2010-02-02T19:52:37+00:00

Re: How to make a image in desired shape in imagemagick?

Postby fmw42 » 2010-02-03T10:15:21+00:00

I really don't program much in PHP and am not sure of the issue with quotes and parenthesis. But note that my test image was 128x128 and the circle was designed for that size.

The biggest issue that I know is that you have to provide the full path to convert. typically /usr/local/bin/convert or /usr/bin/convert

try

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

this should report your IM version.

also for a good site on PHP and IM, see http://www.rubblewebs.co.uk/index.php
User avatar
fmw42
 
Posts: 14587
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: How to make a image in desired shape in imagemagick?

Postby Bonzo » 2010-02-03T10:51:38+00:00

It works OK for me on my localhost.
Are you using windows ? If so change the ' to " and escape the " with \

Code: Select all
$samp7 = "images/test1.jpg";
$samp101 = "images/circles.gif";

exec("convert $samp7 \( +clone -threshold -1 -negate -fill white -draw \"circle 64,64 64,0\" \) -alpha off -compose copy_opacity -composite $samp101");


Depending on your setup you may not need to escape the ()
Bonzo
 
Posts: 2187
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: How to make a image in desired shape in imagemagick?

Postby jokepondy » 2010-02-03T20:28:49+00:00

Hello fmw & Bonzo

I am very thankful to you guys...

Its working for me ...thanks for your replies...

Cheers
jokepondy
jokepondy
 
Posts: 8
Joined: 2010-02-02T19:52:37+00:00


Return to Developers

Who is online

Users browsing this forum: No registered users and 2 guests