Insert image into another Image with max size

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
Optis
Posts: 4
Joined: 2019-02-23T12:27:10-07:00
Authentication code: 1152

Insert image into another Image with max size

Post by Optis »

Hello guys,
I'm trying to insert a random width / hight pixel image into part of a fix background.
The point is , I want to add my png image into the left corner of the iMac image with max height for second image.
I mean i want to add the skull image with MAX height and dog image with MAX size into the iMac front bar.
I've attached some file that I did with photoshop. I want to make it with IM.

I would be grateful if you guys help me with this :)

Image
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Insert image into another Image with max size

Post by fmw42 »

Post your ImageMagick version and platform and your two original images. That way we can show you how to do it with your data.

Basically pick the 4 corner coordinates of the screen in the background image and the corresponding 4 corner coordinates of the image to be overlaid. Then use +distort perspective with the 4 pairs of corresponding coordinates. Then composite one over the other.

See https://imagemagick.org/Usage/distorts/#perspective

__________________________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Insert image into another Image with max size

Post by fmw42 »

Here are two example methods.

Image:
Image

Background screen:
Image


Method 1: overlay the barn image over the screen

Code: Select all

convert \
screen.jpeg \
\( barn.jpg \
-background none -virtual-pixel none \
+distort perspective \
"0,0 203,153  399,0 541,153  399,299 541,355  0,298 203,355" \) \
-background none -layers merge \
screen_barn.jpg
Image


Method 2: Make the screen are transparent and put the screen image over the barn image:

Code: Select all

convert \
\( screen.jpeg \
-fuzz 20% -fill none -draw "matte 350,270 floodfill" \) \
\( barn.jpg \
-background none -virtual-pixel none \
+distort perspective \
"0,0 203,153  399,0 541,153  399,299 541,355  0,298 203,355" \) \
+swap -background none -layers merge \
screen_barn2.jpg
Image

See
https://imagemagick.org/Usage/distorts/#box3d
https://imagemagick.org/Usage/layers/#merge
https://imagemagick.org/Usage/draw/#matte
https://imagemagick.org/Usage/basics/#swap
Optis
Posts: 4
Joined: 2019-02-23T12:27:10-07:00
Authentication code: 1152

Re: Insert image into another Image with max size

Post by Optis »

fmw42 wrote: 2019-02-23T13:25:16-07:00 Post your ImageMagick version and platform and your two original images. That way we can show you how to do it with your data.

Basically pick the 4 corner coordinates of the screen in the background image and the corresponding 4 corner coordinates of the image to be overlaid. Then use +distort perspective with the 4 pairs of corresponding coordinates. Then composite one over the other.

See https://imagemagick.org/Usage/distorts/#perspective

__________________________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
Thanks for your answer,
I'm using osX and IM version : ImageMagick 7.0.8-14 Q16 x86_64 2018-10-2

I used this commend for resize my 2nd image and insert on the iMac panel :

Code: Select all

convert 1.jpg "(" 2.png -resize x110 -gravity southeast ")" -gravity Center -geometry -350+216 -composite Pro.jpg
But as you now this will resize height to 110px on any images; but i just want to resize at the max height for iMac panel for different png images.
Optis
Posts: 4
Joined: 2019-02-23T12:27:10-07:00
Authentication code: 1152

Re: Insert image into another Image with max size

Post by Optis »

fmw42 wrote: 2019-02-23T13:44:10-07:00 Here are two example methods.
.
.
.
Thanks again !
but i dont want to add an background into the monitor's screen.
I want to insert a png transparent file into the front panel ( left corner at apple logo ). I mean the white space panel. but my png files has different heights. I want to add them at maximum hight in front panel.

When i use the

Code: Select all

convert 1.jpg "(" 2.png -resize 110 -gravity southeast ")" -gravity Center -geometry -350+216 -composite Pro.jpg
comment, it work for some images, but it wont work for high images. I've attached two examples.

Image
Image
Last edited by Optis on 2019-02-23T16:13:02-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Insert image into another Image with max size

Post by fmw42 »

try adding x to 110 (x100) as per WxH without the W. When you leave it off, it tries to use either W or H whichever the aspect ratio decides is larger

Code: Select all

convert 1.jpg "(" 2.png -resize x110 -gravity southeast ")" -gravity Center -geometry -350+216 -composite Pro.jpg
See https://imagemagick.org/script/command- ... p#geometry

P.S. Best not to quote the whole previous message, especially when there are images.
Optis
Posts: 4
Joined: 2019-02-23T12:27:10-07:00
Authentication code: 1152

Re: Insert image into another Image with max size

Post by Optis »

Thank you dear fmw42,
now it works. <3
Post Reply