Page 1 of 1
Composite over another image
Posted: 2016-06-01T21:48:37-07:00
by agriz
I want to display some of photos inside the lens.
I can do this in photoshop. But i am not able to find a proper way to do this in imagemagick.
Please tell me how to do
Re: Composite over another image
Posted: 2016-06-01T22:02:13-07:00
by fmw42
Make the inside of the lens (where it is white) into transparent. Then resize and crop your other image to the same size as this one. Or extend it if small to the same size as this one. Then composite them. Below is Unix syntax. Remove the \ before the parens and escape the ^ as ^^ for Windows syntax (I think that is correct).
Code: Select all
convert lens.jpg -fuzz 5% -fill none -draw "matte 50,50 floodfill" magnifier.png
Code: Select all
convert rose: -resize 180x180! rose.png
Code: Select all
convert rose.png magnifier.png -compose over -composite result.png
or
Code: Select all
convert -size 180x180 xc:black \( rose: -resize 90x90^ \) -compose over -composite rose2.png
Code: Select all
convert rose2.png magnifier.png -compose over -composite result2.png

Re: Composite over another image
Posted: 2016-06-01T22:22:55-07:00
by agriz
Sir, The magnifier is completely transparent image. There is a group photo. I want to apply this magnifier on that photo. so it is completely transparent. Can we just find and replace the white place in this magnifier with another image?
Re: Composite over another image
Posted: 2016-06-01T23:02:02-07:00
by fmw42
agriz wrote:Can we just find and replace the white place in this magnifier with another image?
That is what I have done in the result.png images. I made the circle of the magnifier transparent. Then I put the rose image behind this image so that is shows inside the magnifier circle.
Perhaps I do not understand your problem. You need to have a transparent circle in the white area of the magnifier so that another image will show behind it.
Please post your other image that you want to show in the magnifier. And explain further what you want to do with that image in relation to the magnifier.
Note: the concept is not to cut out a circle image and place it over the white area of the magnifier. It is to cut out (make transparent) the white area in the magnifier, so that it allows a background image to show within the transparent region. It can be done this other way, but it is a little more complicated.
Code: Select all
convert lens.jpg rose2.png \( magnifier.png -alpha extract -negate \) -compose over -composite result3.png

Re: Composite over another image
Posted: 2016-06-02T01:58:45-07:00
by agriz
This is the right image. The magnifier became jpg and lost the transparency
Re: Composite over another image
Posted: 2016-06-02T04:12:27-07:00
by agriz
Sir,
Code: Select all
exec($im."\convert my_room.jpg -resize x115 ( +clone -threshold -1 -negate -fill white -draw \"circle 55,55 55,0\" ) -alpha off -compose copy_opacity -composite my_room_mini.png");
By using the above code i changed my room pic to round shape and composite the rounded room to magnifier.
But i am not sure how the code shapes the picture round and circle's first two parameters are understandable and the last two are confusing.
Can you please explain me the above code?
I will be very thankful for you.
Thanks
Re: Composite over another image
Posted: 2016-06-02T04:41:02-07:00
by Bonzo
55,55 is the centre of the circle and the 55,0 is a point on the circumference which sets the diameter.
Re: Composite over another image
Posted: 2016-06-02T05:03:40-07:00
by agriz
gives perfect circle but,
fails to create perfect circle. Right and Bottom of the circle is little bit gone. (1px might be missing on that circle.)
Re: Composite over another image
Posted: 2016-06-02T05:07:33-07:00
by agriz
Code: Select all
convert my_room.jpg -resize x115 ( +clone -threshold -1 -negate -fill white -draw \"circle 55,55 55,0\" ) -alpha off -compose copy_opacity -composite my_room_mini.png
convert my_family_photo.jpg my_room_mini.png -geometry +0+0 -composite family_room.jpg
If i try to combine these two commands, picture became 100px or so.
How can i combine these two convert commands?
Re: Composite over another image
Posted: 2016-06-02T09:33:14-07:00
by fmw42
If the two separate commands work, then try
Code: Select all
convert my_room.jpg -resize x115 ^
( +clone -threshold -1 -negate -fill white -draw \"circle 55,55 55,0\" ) ^
-alpha off -compose copy_opacity -composite ^
my_family_photo.jpg +swap -compose over -composite family_room.jpg
If that does not work, then post your two input images and the working output image, so we can test properly on your images to see what is happening.
Re: Composite over another image
Posted: 2016-06-05T02:07:55-07:00
by agriz
Sir, thanks for the code. i will check it out and let you know. Is there any book to study imagemagick in details?
Thanks for your help
Re: Composite over another image
Posted: 2016-06-05T10:55:13-07:00
by fmw42
Re: Composite over another image
Posted: 2016-06-05T21:32:33-07:00
by agriz
Thank you sir.
Your script is working beautifully!
convert rose.jpg -resize 109x109^ -gravity center -extent 109x109 -crop 109x109+0+0 rose_cropped.png
convert maginfier.png rose_cropped.png -geometry +10+10 -compose DstOver -composite magifier_rose.png
How can we use -alpha to remove the visible edges of rose from the magnifier?
Re: Composite over another image
Posted: 2016-06-06T10:42:59-07:00
by fmw42
try this, where lens.jpg is your original opaque magnifier image.
Code: Select all
convert lens.jpg -fuzz 5% -fill none -draw "matte 50,50 floodfill" \
-alpha extract -blur 0x1 -level 50x100% mask_inner.png
color=`convert lens.jpg -format "%[pixel:u.p{0,0}]" info:`
convert lens.jpg \
\( -clone 0 -bordercolor "$color" -border 5 -fuzz 5% -fill none \
-draw "matte 0,0 floodfill" -alpha extract -shave 5x5 -blur 0x1 -level 0x50% \) \
-alpha off -compose copy_opacity -composite lens_outer.png
convert rose.jpg -resize 109x109^ -gravity center -extent 109x109 -crop 109x109+0+0 rose_cropped.png
convert rose_cropped.png \( mask_inner.png -negate \) -alpha off -compose copy_opacity -composite rose_cropped_trans.png
convert lens_outer.png rose_cropped_trans.png -compose over -composite x: