I have many images that I am trying to overlay another image on top of at different distortions. To illustrate, please take a look at the image at this link:
http://www.bodymindsystems.com/sites/bm ... verlay.jpg
I have been using 'rotate' and 'shear' with different angle parameters to accomplish this somewhat successfully, ultimately running the following command (with different angle parameters of course):
convert candyimage.png \( IBM.eps -resample 144x144 -trim -resize 90x40\> -matte -background none -rotate -20 -shear 35x35 \) -geometry +186+65 -composite candyimage-result.png
Now however, I am trying to do harder distortions like the image in the bottom left of the link image above. There, I am unable to place the IBM logo with a distortion that needs to look sort of like a perspective because of how the angle of that container is on which IBM logo needs to rest on. To the end user looking at the image, it must look like as if the IBM logo was imprinted on top of the container.
Researching imageMagick, I found 'distort Affine' and my question is if there is any way to successfully do so? Secondly, can I use it for all of my images getting rid off 'rotate' and 'shear' which I find too consuming to configure. (I am trying to have one single command list that can be applied to all images to make it as efficient as possible to configure each -- distort Affine feels like it should be able to do the job and cover all of my needs -- can it?)
When I try the following 'distort Affine' on the image in the bottom left, I get the logo unchanged even though the image is converted to 49x20 so I am shifting it which should be resulting in a distortion.
convert candyimage.png \( IBM.eps -resample 72x72 -trim -resize 49x20\> -matte -background none -distort Affine '0,20 39,20 20,0' \) -geometry +186+65 -composite candyimage-result.png
Lastly, once distorted, it seems the resulting image gets cut off. How do I adjust the command to make sure that it correctly resizes the image to make room for now distorted image of new size?
overlaying images with another image at different distortion
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: overlaying images with another image at different distor
You likely need to put the -distort Affine inside the parens for the text image.
-distort Affine should be able to do translation, scale, rotation and shear all at once, if you provide the correct arguments. However, you may need to use -distort perspective to get the text to look more proper in perspective than -distort affine can provide.
can you provide a link to your two input images? others may be able to help tune up your command for you.
see
http://www.imagemagick.org/Usage/distorts/#affine
http://www.imagemagick.org/Usage/distorts/#perspective
-distort Affine should be able to do translation, scale, rotation and shear all at once, if you provide the correct arguments. However, you may need to use -distort perspective to get the text to look more proper in perspective than -distort affine can provide.
can you provide a link to your two input images? others may be able to help tune up your command for you.
see
http://www.imagemagick.org/Usage/distorts/#affine
http://www.imagemagick.org/Usage/distorts/#perspective
Re: overlaying images with another image at different distor
Thanks for your input. There is no text involved here. That is the base image and the overlay image are both just a .png images. Furthermore, enclosing in parenthesis does not seem to make any change.
Here are the links to the individual image files:
base image 1: http://www.bodymindsystems.com/sites/bm ... mg/jbimage
base image 2: http://www.bodymindsystems.com/sites/bm ... yimage.png
base image 3: http://www.bodymindsystems.com/sites/bm ... timage.png
overlay image: http://www.bodymindsystems.com/sites/bm ... mg/IBM.png
mockup of desired result: http://www.bodymindsystems.com/sites/bm ... verlay.jpg (more examples are shown here in total)
Basically, I am looking for a single command set that I can use for all three base images deriving different distortions depending on what each base image requires in order for the final image to look as realistic as possible
Here are the links to the individual image files:
base image 1: http://www.bodymindsystems.com/sites/bm ... mg/jbimage
base image 2: http://www.bodymindsystems.com/sites/bm ... yimage.png
base image 3: http://www.bodymindsystems.com/sites/bm ... timage.png
overlay image: http://www.bodymindsystems.com/sites/bm ... mg/IBM.png
mockup of desired result: http://www.bodymindsystems.com/sites/bm ... verlay.jpg (more examples are shown here in total)
Basically, I am looking for a single command set that I can use for all three base images deriving different distortions depending on what each base image requires in order for the final image to look as realistic as possible
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: overlaying images with another image at different distor
You are pretty close. A few minor changes. Reverse the order of the rotate and shear. Change some parameter values. Be sure to set the compose method as some options may change that (just in case). Try putting -write statements after each step so you can see what is happened along the way and change values. Try this.
convert candyimage.png \
\( IBM.png -matte -resample 144x144 -trim -write tmp1.png -resize "40x40>" -write tmp2.png \
-background none -shear 35x35 -write tmp3.png -rotate -20 -write tmp4.png \) \
-geometry +150+50 -compose over -composite tmp_result.png
convert candyimage.png \
\( IBM.png -matte -resample 144x144 -trim -write tmp1.png -resize "40x40>" -write tmp2.png \
-background none -shear 35x35 -write tmp3.png -rotate -20 -write tmp4.png \) \
-geometry +150+50 -compose over -composite tmp_result.png
Re: overlaying images with another image at different distor
Thank you for your feedback.
So do you think that I am better off just using rotate and shear as oppose to '-distort Affine'? Since I have tons of these images, I would like to find a single, least time consuming method to configure these. Also, is there any tool/process you can suggest to me to expedite the configuration of these. Currently it is trial and error and it takes me 20min+ to configure imageMagick overlay just right for each of these images.
So do you think that I am better off just using rotate and shear as oppose to '-distort Affine'? Since I have tons of these images, I would like to find a single, least time consuming method to configure these. Also, is there any tool/process you can suggest to me to expedite the configuration of these. Currently it is trial and error and it takes me 20min+ to configure imageMagick overlay just right for each of these images.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: overlaying images with another image at different distor
I would make a measurement of where I want the 4 corners of the IBM image to be located in the base image and then use distort perspective
see
http://www.imagemagick.org/Usage/distorts/#perspective
see
http://www.imagemagick.org/Usage/distorts/#perspective
Re: overlaying images with another image at different distor
Hmmm, I see. Would you be able to show me the example command analogous what you did with rotate and shear? I am still confused how you apply the four corner coordinates and the example would help a lot.
Thanks again for all your help on this!
Thanks again for all your help on this!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: overlaying images with another image at different distor
rs13 wrote:Hmmm, I see. Would you be able to show me the example command analogous what you did with rotate and shear? I am still confused how you apply the four corner coordinates and the example would help a lot.
Thanks again for all your help on this!
Try this:
You have to measure your coordinate where you want the IBM corners to be on the candyimage and use the corners of the IBM image together as pairs (IBM coordinate, Candy coordinate for each corner). See http://www.imagemagick.org/Usage/distorts/#perspective (the use of +distort and -layers merge on the page)
convert candyimage.png \
\( IBM.png -matte -virtual-pixel transparent +distort perspective "0,0 168,66 200,0 200,68 200,81 203,83 0,81 161,82" \) \
-layers merge tmp_result2.png
Re: overlaying images with another image at different distor
Let me give that a try.
Thank you for all your help!
Thank you for all your help!
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: overlaying images with another image at different distor
See the example I have published in...fmw42 wrote:I would make a measurement of where I want the 4 corners of the IBM image to be located in the base image and then use distort perspective
see
http://www.imagemagick.org/Usage/distorts/#perspective
viewtopic.php?f=1&t=19724#p77766
This basically did exactly what was described. Four corner positions were found, and a new image distorted and overlayed at that location. The input image is resized and positioned as part of the distort process, and with use of % in the distort string, I don't even have to know the size of the input image!
One final word of note. The coordinates are NOT integer pixel coordinates, but floating point image coordinates. That is 0,0 is the left hand edge, not the center of the top left pixel (which is at 0.5,0.5). That is those numbers are NOT integers, you can fine-tune top image to sub-pixel positions! So don't limit yourself by just thinking in terms of integers!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/