Composite two images with different sizes without cropping. (solved)

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
Montfrooij
Posts: 2
Joined: 2016-03-22T01:21:57-07:00
Authentication code: 1151

Composite two images with different sizes without cropping. (solved)

Post by Montfrooij »

Hello,

I'm using IM 6.9.3-6 on a Windows 10 X64 machine, using the command line.

I would like to add a watermark to the bottom right position of my image AND do a resize.
I did try and find a solution but so far none of the existing questions were giving the desired result.

What I've achieved so far is doing the resize:

Code: Select all

convert source.jpg -resize "681^>"  -quality 70% -strip  target.jpg
This works perfectly, resizing the image based on the short side and saving it with the desired quality and strip the 'overhead' (metadata).

Now I would like to add a watermark to the bottom right of this image.
This watermark is a png with a fixed size of 380 x 87.

I found this command and tested it

Code: Select all

composite  -dissolve 25% -gravity south source.jpg wm.png target.jpg
It does add a watermark, but the size of target.jpg is now 380 x 87 (essentially cropping the rest of the souce image).

Somebody suggested to add -resize "1x1<" after the composite to disable resizing, but that did not work either.

Code: Select all

composite -resize "1x1<" -dissolve 25% -gravity south source.jpg wm.png target.jpg


So my first 'problem' is getting the composite to result in the 'source' image size.
Two other 'problems' I have to fix as wel are the location of the watermark (south is not bottom, right) and do both actions in one command.

Thanks in advance for your help!

Peter
Last edited by Montfrooij on 2016-03-22T06:49:08-07:00, edited 1 time in total.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Composite two images with different sizes without cropping.

Post by GeeMack »

Montfrooij wrote:I would like to add a watermark to the bottom right position of my image AND do a resize. [...] Two other 'problems' I have to fix as wel are the location of the watermark (south is not bottom, right) and do both actions in one command.
Try this using just the "convert" command...

Code: Select all

convert ^
   source.jpg ^
   -strip ^
   -resize "681^>" ^
   wm.png ^
   -compose dissolve ^
   -define compose:args=25 ^
   -gravity southeast ^
   -geometry +20+20 ^
   -composite ^
   -quality 70 ^
      target.jpg
That starts by bringing in your background image, stripping the metadata, and resizing it as you like.

Then you bring in the watermark image which will be overlaid on the background.

After that you select a compose method of "dissolve".

Using "-define compose:args=25" you specify that it will composite the watermark at 25% opaque.

The "-gravity southeast" tells the command to place the watermark in the lower right corner.

If you want the watermark up and away from that corner you can use something like "-geometry +20+20" to move it up 20 pixels and over 20 pixels from the corner.

Now with all those details specified you "-composite" the watermark over the background image.

Set the JPG quality at 70%, name the output image, and you're done.
Montfrooij
Posts: 2
Joined: 2016-03-22T01:21:57-07:00
Authentication code: 1151

Re: Composite two images with different sizes without cropping.

Post by Montfrooij »

Thanks a lot!
Looks like you've solved my problems at once!
:D

Peter
Post Reply