Page 1 of 1
How to make a image in desired shape in imagemagick?
Posted: 2010-02-02T20:08:49-07:00
by jokepondy
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
Re: How to make a image in desired shape in imagemagick?
Posted: 2010-02-02T20:36:08-07:00
by fmw42
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.
convert zelda3.jpg \
\( +clone -threshold -1 -negate -fill white -draw "circle 64,64 64,0" \) \
-alpha off -compose copy_opacity -composite zelda3_circ.gif
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/
Re: How to make a image in desired shape in imagemagick?
Posted: 2010-02-02T22:49:09-07:00
by jokepondy
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
Re: How to make a image in desired shape in imagemagick?
Posted: 2010-02-03T10:15:21-07:00
by fmw42
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
Re: How to make a image in desired shape in imagemagick?
Posted: 2010-02-03T10:51:38-07:00
by Bonzo
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 ()
Re: How to make a image in desired shape in imagemagick?
Posted: 2010-02-03T20:28:49-07:00
by jokepondy
Hello fmw & Bonzo
I am very thankful to you guys...
Its working for me ...thanks for your replies...
Cheers
jokepondy
Re: How to make a image in desired shape in imagemagick?
Posted: 2019-09-15T01:59:26-07:00
by manversman
HI guys. This thread is really helpful, but when I run this:
"%ProgramFiles%\ImageMagick\convert.exe" convert zelda3.jpg \ \( +clone -threshold -1 -negate -fill white -draw 'circle 64,64 64,0' \) \ -alpha off -compose copy_opacity -composite zelda3_circ.gif (nothing happened at all until I took out all the line breaks)
I do get zelda3_circ.gif OK, but it is just a black square (which I do want) with a plain white circle (which I don't!). The original picture in zelda3.jpg is nowhere to be seen! Any ideas what am I doing wrong here?? (I did use your image).
Thanks
Re: How to make a image in desired shape in imagemagick?
Posted: 2019-09-15T04:30:35-07:00
by snibgo
What version of IM, on what platform?
Your "%ProgramFiles%" suggests you are using Windows, but you escape \( and \) which suggests you are using bash. That is a problem. If you use Windows, see
http://www.imagemagick.org/Usage/windows/