Page 1 of 1

Overlay and resize image in area

Posted: 2017-03-14T08:06:32-07:00
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?

Re: Overlay and resize image in area

Posted: 2017-03-14T09:13:02-07:00
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.

Re: Overlay and resize image in area

Posted: 2017-03-14T09:28:10-07:00
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.

Re: Overlay and resize image in area

Posted: 2017-03-14T09:33:06-07:00
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

Re: Overlay and resize image in area

Posted: 2017-03-14T09:36:23-07:00
by fmw42
See new edits to the above.

Re: Overlay and resize image in area

Posted: 2017-03-14T09:38:37-07:00
by fmw42
Please always provide your IM version and platform, since syntax may vary between Unix and Windows.

Re: Overlay and resize image in area

Posted: 2017-03-14T12:06:30-07:00
by fmw42
If on Unix, then you may want to take a look at my scripts, tshirt and tshirtwarp, at my link below.

Re: Overlay and resize image in area

Posted: 2017-03-15T02:35:03-07:00
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.