Applying two images to the third one (with transforms)

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
dmr
Posts: 2
Joined: 2018-03-10T04:12:49-07:00
Authentication code: 1152

Applying two images to the third one (with transforms)

Post by dmr »

Hello! IM version - 7.0.7, CentOS, console.
I have one big image, to which I want to place two watermark. First of all, I need to resize this image (BEFORE appending other images). Then I need to place one more image on the bottom left, changing its size. Another image at the bottom right - is the vertical caption with my own font. These additional images should be partially transparent. I'm new to IM and have already broken my head, trying to solve this problem.

I guess there should be something like this (pseudocode):

Code: Select all

magick  \( base-image.jpg -resize 70% \) \
    \( logo.png -resize 120x \) -gravity southwest  \
    \( -background none -fill "rgba(102,102,102,.40)" -gravity center \
        -font 8508.otf -size 260x -kerning 1.5 label:"Some text" ) -gravity southeast  \
    -flatten result.jpg
In the end, I need something like this. I want to do this in one command so that I do not have to save jpeg multiple times.

Sorry for my English! Thanks!
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Applying two images to the third one (with transforms)

Post by GeeMack »

dmr wrote: 2018-03-10T05:19:59-07:00I have one big image, to which I want to place two watermark. First of all, I need to resize this image (BEFORE appending other images). Then I need to place one more image on the bottom left, changing its size. Another image at the bottom right - is the vertical caption with my own font. These additional images should be partially transparent. I'm new to IM and have already broken my head, trying to solve this problem.
You can modify your overlays independently inside parentheses, and composite them onto your main image in separate operations as the command progresses. This example command should work, but you'll have to adjust it to your exact requirements.

Code: Select all

magick base-image.jpg -resize 70% \
    \( logo.png -resize 120x -channel A -evaluate multiply 0.4 +channel \) \
    -gravity southwest -composite \
    \( -background none -fill "rgba(102,102,102,0.4)" \
        -font arial -kerning 1.5 label:"Some text" -rotate -90 \) \
   -gravity southeast -composite \
   result.jpg
That reads in your main image and resizes it to 70%.

Then inside the first parentheses it reads in your logo image, resizes it to 120 pixels wide, and makes it 40% opaque.

Next it sets the gravity to southwest and composites the logo image in the lower left corner. Now it's just one image with the logo already applied.

After that, inside the next parentheses it creates the label with your fill, spacing, font, etc., and rotates it -90 degrees to make it vertical.

Then it sets the gravity to southeast, composites the label in the lower right corner, and writes the output image.

You can use "-geometry +X+Y" right before each "-gravity ... -composite" if you want to apply the overlays a particular distance from the corners. Change the X and Y to the number of pixels you need.
I want to do this in one command so that I do not have to save jpeg multiple times.
Working the entire operation as a single command prevents writing intermediate files, but when that's not possible, there are several ways to avoid lossy writing and re-writing. Probably the simplest way is to output any intermediate files as PNGs instead of JPGs.
dmr
Posts: 2
Joined: 2018-03-10T04:12:49-07:00
Authentication code: 1152

Re: Applying two images to the third one (with transforms)

Post by dmr »

Thank you! This is exactly what I need! Only I do not understand, when it's better to use method "-composite", and when "-layers flatten" (is it even possible?). According to the description, they do the same thing.
Post Reply