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
How to make a image in desired shape in imagemagick?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to make a image in desired shape in imagemagick?
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/
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?
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to make a image in desired shape in imagemagick?
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
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?
It works OK for me on my localhost.
Are you using windows ? If so change the ' to " and escape the " with \
Depending on your setup you may not need to escape the ()
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");
Re: How to make a image in desired shape in imagemagick?
Hello fmw & Bonzo
I am very thankful to you guys...
Its working for me ...thanks for your replies...
Cheers
jokepondy
I am very thankful to you guys...
Its working for me ...thanks for your replies...
Cheers
jokepondy
-
- Posts: 1
- Joined: 2019-09-15T01:42:08-07:00
- Authentication code: 1152
Re: How to make a image in desired shape in imagemagick?
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
"%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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to make a image in desired shape in imagemagick?
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/
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/
snibgo's IM pages: im.snibgo.com