Composite over another image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Composite over another image

Post by agriz »

Image

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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composite over another image

Post 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
Image

Code: Select all

convert rose: -resize 180x180! rose.png
Image

Code: Select all

convert rose.png magnifier.png -compose over -composite result.png
Image

or

Code: Select all

convert -size 180x180 xc:black \( rose: -resize 90x90^ \) -compose over -composite rose2.png
Image

Code: Select all

convert rose2.png magnifier.png -compose over -composite result2.png
Image
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Composite over another image

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composite over another image

Post 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
Image
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Composite over another image

Post by agriz »

Image

This is the right image. The magnifier became jpg and lost the transparency
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Composite over another image

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Composite over another image

Post by Bonzo »

55,55 is the centre of the circle and the 55,0 is a point on the circumference which sets the diameter.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Composite over another image

Post by agriz »

Code: Select all

-resize x115
gives perfect circle but,

Code: Select all

-resize x110
fails to create perfect circle. Right and Bottom of the circle is little bit gone. (1px might be missing on that circle.)
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Composite over another image

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composite over another image

Post 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.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Composite over another image

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composite over another image

Post by fmw42 »

agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Composite over another image

Post by agriz »

Thank you sir.
Your script is working beautifully!

Image
Image
Image


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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composite over another image

Post 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:
Post Reply