Overlay and resize image in area

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
aggrosoft
Posts: 3
Joined: 2017-03-14T07:56:38-07:00
Authentication code: 1151

Overlay and resize image in area

Post by aggrosoft »

Hi there,

I want to combine two images, both of them have different sizes. I want to define an are before overlaying one image on the other while resizing the second one. See the following example:

Image

Which is produced by running:

Code: Select all

convert my-shirt.jpg logo-test.png -geometry 1100x900+500+330 -composite result.jpg
I am doing another run after that to draw that exact rectangle I want to place the overlay into. I want that image to be centered depending on its dimensions. Shouldn't the geometry setting be able to resize my picture and center it at the same time?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Overlay and resize image in area

Post by snibgo »

I think default "-gravity" is "NorthWest". If you want centred, insert "-gravity centre".

Personally, I never use the XxY components of "-geometry", I use just +X+Y. For resizing, I explicitly "-resize XxY" first.
snibgo's IM pages: im.snibgo.com
aggrosoft
Posts: 3
Joined: 2017-03-14T07:56:38-07:00
Authentication code: 1151

Re: Overlay and resize image in area

Post by aggrosoft »

If I try to use the following:

Code: Select all

convert my-shirt.jpg logo-teset.png -gravity Center -geometry +500+330 -resize 570x990 -composite result.jpg
it will be totally off, I want to keep the original dimensions from my-shirt.jpg and just put a resized version of logo-test.png on top of it on a defined area.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Overlay and resize image in area

Post by fmw42 »

Put the -resize before -gravity (right after your second image) and with parens for the second image. Otherwise you will resize both images.. Your -geometry is probably not needed if you have -gravity center. If it is needed, then it will need much smaller +X+Y values. Start with +0+0 and then adjust as needed.

Code: Select all

convert my-shirt.jpg \( logo-teset.png -resize 570x990  \) -gravity Center -geometry +X+Y -composite result.jpg
See
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/layers/#convert
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Overlay and resize image in area

Post by fmw42 »

See new edits to the above.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Overlay and resize image in area

Post by fmw42 »

Please always provide your IM version and platform, since syntax may vary between Unix and Windows.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Overlay and resize image in area

Post by fmw42 »

If on Unix, then you may want to take a look at my scripts, tshirt and tshirtwarp, at my link below.
aggrosoft
Posts: 3
Joined: 2017-03-14T07:56:38-07:00
Authentication code: 1151

Re: Overlay and resize image in area

Post by aggrosoft »

Thanks Fred, I wasn't aware of the Parenthesis stuff. I got it to work with this command (for convenience I did not replace the php $ variables) :

Code: Select all


//example
//$resize = 150x150
//$geometry = 200+200

convert $product \\( $logo -scale $resize -gravity Center -background none -extent $resize  \\) -gravity NorthWest -geometry +$geometry -composite $path/result.jpg
This will scale the logo in the sub routine and I just used -extent to get it to center in the whole rectangular area needed, after that I just put the result onto the jpg.
Post Reply