workflow: resize, watermark, caption

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?".
emax
Posts: 21
Joined: 2018-02-19T03:23:45-07:00
Authentication code: 1152

workflow: resize, watermark, caption

Post by emax » 2018-02-19T04:03:33-07:00

Hi all!

Though I have been an imagemagick user since some years, I only know how make simple processing with it. But now, I am facing a complex task (at least for me) and I'd appreciate some help for that. The documentation shows examples which I have studied, and I found a solution for eah single step. But I failed in trying the parenthesis feature to get to a one-shot processing.

I have tried with the parenthesis feature but had no luck.

So here is my problem:
  1. I have a starting picture with an un knwon size.
  2. The picture shall be resized to a defined width.
  3. A watermark from an individual text shall be overlayed at the bottom.
  4. A caption individual to thje picture shall be appended to the bottem.
I know how to do each single step, but do not want to have temporary files laying around. A one-shot processing is furthermore faster, I guess.

For each step, I have a sample picture. I can however no show a 'real' "Step A" example sinve the upload-space only allows a width of 800 pixels.

This is the step A example. Due to webspace limitations in 800x size, so just assume1024x size instead.
This is the step B example. The same picture, but resized to 800x size.
This is the step C example. Now with an overlayed watermark.
This is the step D example. And finally with a caption appended to the south.

What I would like to have (and to understand) is a command similar to (just meta-syntax):

Code: Select all

$ convert stepA.jpg -resize 800x &&  \
   overlayWatermark("with this text", size=800*0.9) && \
   appendCaption("caption text", background=black, foreground=white, width=800px) \
   into stepD.jpg
My os is linux.

Any help is very much appreciated. :-)

snibgo
Posts: 10955
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: workflow: resize, watermark, caption

Post by snibgo » 2018-02-19T04:21:30-07:00

emax wrote:I know how to do each single step, but do not want to have temporary files laying around. A one-shot processing is furthermore faster, I guess.
If you show us each single step, we can probably show how to combine them.

Please also state the version of IM, and your platform.
snibgo's IM pages: im.snibgo.com

emax
Posts: 21
Joined: 2018-02-19T03:23:45-07:00
Authentication code: 1152

Re: workflow: resize, watermark, caption

Post by emax » 2018-02-19T05:46:04-07:00

Hi snibgo,

thanks for your help! :-)

Platform: as said before: Linux.

Code: Select all

$ uname -a
Linux summini 4.9.0-5-amd64 #1 SMP Debian 4.9.65-3+deb9u2 (2018-01-04) x86_64 GNU/Linux
IM:

Code: Select all

$ convert -version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib

Here is how I do it:

StepA: get the original file

StepB: resize to stepB:

Code: Select all

convert -resize 600x stepA.jpg stepB.jpg:

StepC, overlay watermark into stepC.jpg:
In this step, I have an existsing watermark file which is in fact not an option: The watermark texts differ, so I'd prefer to have this created on the fly. An additional problem is that the size of the watermark file must individually fit the images output-size.

Code: Select all

convert stepB.jpg watermark.png -gravity south -compose overlay  -composite  stepC.jpg

StepD: append caption into stepD.jpg

Code: Select all

convert stepC.jpg  -size 600x -background black -font DejaVu-Sans -fill yellow -pointsize 18 -gravity southwest caption:"This is the caption text" -append stepD.jpg

snibgo
Posts: 10955
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: workflow: resize, watermark, caption

Post by snibgo » 2018-02-19T06:59:56-07:00

emax wrote:convert -resize 600x stepA.jpg stepB.jpg:
The order should be: read the input, process it, write the output. And the final ":" is wrong. So that should be:

Code: Select all

convert stepA.jpg -resize 600x stepB.jpg
Then, combining them is easy. Just chain them together without the intermediate files:

Code: Select all

convert \
  stepA.jpg -resize 600x \
  watermark.png -gravity south -compose overlay -composite \
  -size 600x \
  -background black -font DejaVu-Sans -fill yellow -pointsize 18 \
  -gravity southwest caption:"This is the caption text" \
  -append stepD.jpg 
Does that work?
snibgo's IM pages: im.snibgo.com

emax
Posts: 21
Joined: 2018-02-19T03:23:45-07:00
Authentication code: 1152

Re: workflow: resize, watermark, caption

Post by emax » 2018-02-19T07:43:26-07:00

Wow, thank you! :-)

I will try it. May take a day, but I will tell.

> And the final ":" is wrong.
Yes, you're right. It was a typo.

emax
Posts: 21
Joined: 2018-02-19T03:23:45-07:00
Authentication code: 1152

Re: workflow: resize, watermark, caption

Post by emax » 2018-02-19T07:48:27-07:00

Hey, I was so curious and tried immediately: YES, it works, very, very nice!

However: The watermark-file is so to say a 'fixed' file. Since I can never be sure whether the watermark-file fits into the picture (the picture-widths are arbitrary), it would be great to create the watermark on the fly. I could do this before in a single step. But to do it in one wash would be really cool.

I am quite sure this is possible - but I have no idea how.

snibgo
Posts: 10955
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: workflow: resize, watermark, caption

Post by snibgo » 2018-02-19T07:55:13-07:00

How do you create the watermark image? What is the "convert" command?
snibgo's IM pages: im.snibgo.com

Bonzo
Posts: 2970
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: workflow: resize, watermark, caption

Post by Bonzo » 2018-02-19T07:58:39-07:00

If you were using V7 you could do it all on one line. With V6 you would have to read the image dimensions with identify then calculate the size of your watermark to use in your command.

emax
Posts: 21
Joined: 2018-02-19T03:23:45-07:00
Authentication code: 1152

Re: workflow: resize, watermark, caption

Post by emax » 2018-02-19T09:33:12-07:00

> How do you create the watermark image?

Here it is:

Code: Select all

convert -size 600x100 -background none -font DejaVu-Sans -fill white -gravity center caption:'The watermark text' -shade 240x40 watermark.png

snibgo
Posts: 10955
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: workflow: resize, watermark, caption

Post by snibgo » 2018-02-19T09:40:56-07:00

Just put those operations in place of "watermark.png", in the command I showed above. Put them inside parentheses to stop the "-shade" from also processing the resized stepA.jpg.

Code: Select all

convert stepA.jpg -resize 600x \
  ( -size 600x100 -background none -font DejaVu-Sans -fill white \
    -gravity center \
    caption:'The watermark text' -shade 240x40 \
  ) \
  -gravity south -compose overlay -composite \
  -size 600x \
  -background black -font DejaVu-Sans -fill yellow -pointsize 18 -gravity southwest \
  caption:"This is the caption text" -append \
  stepD.jpg 
snibgo's IM pages: im.snibgo.com

User avatar
GeeMack
Posts: 653
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: workflow: resize, watermark, caption

Post by GeeMack » 2018-02-19T10:08:49-07:00

emax wrote:
2018-02-19T07:48:27-07:00
The watermark-file is so to say a 'fixed' file. Since I can never be sure whether the watermark-file fits into the picture (the picture-widths are arbitrary), it would be great to create the watermark on the fly. I could do this before in a single step. But to do it in one wash would be really cool.
Within a single command you can scale a watermark image to a particular proportion of the main input image with a command something like this...

Code: Select all

convert input.png watermark.png +distort SRT "%[fx:t==0?1:(u.w*0.1)/v.w] 0" -shave 1x1 output.png
That reads both images into the command, then scales the watermark so its width is 10% the width of the main input. Change the "0.1" in the FX expression to whatever scale you want. With a little tweaking of the FX expression you could scale the watermark with a more complex criteria, like for example 10% of the maximum of the width and height of the main input image.

emax
Posts: 21
Joined: 2018-02-19T03:23:45-07:00
Authentication code: 1152

Re: workflow: resize, watermark, caption

Post by emax » 2018-02-19T10:11:46-07:00

@snibgo

Thank you so much!

So if I got this right, the term expressed by the parenthesis is thus nothing else but a file-substitute - whatever I do within the parensthesis?

emax
Posts: 21
Joined: 2018-02-19T03:23:45-07:00
Authentication code: 1152

Re: workflow: resize, watermark, caption

Post by emax » 2018-02-19T10:17:59-07:00

@GeeMack

this is VERY advanced. I will tinker with that in the next days. And if I understand it, I will put it in my secret "box of magic".

This imageMagick thing is indeed a real power-tool, and that's why it sometimes causes quite some headache: There is no "one and single" way to do things.

I will try with those solutions and report asap. Thank you all! :-)

snibgo
Posts: 10955
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: workflow: resize, watermark, caption

Post by snibgo » 2018-02-19T10:37:12-07:00

emax wrote:So if I got this right, the term expressed by the parenthesis is thus nothing else but a file-substitute - whatever I do within the parensthesis?
Well, I have simply taken the operations that made the image, put them inside parentheses, and used that as a substitute for the filename.

In general we can always do this, but there is an important "gotcha". Any settings made in the new long command before this substitute might affect the substitute, and any settings made within the new parentheses can effect the rest of the command after the parentheses. Looking at the command, this didn't seem to be a problem, but we should always test the long command to ensure it does the same as the sequence of separate commands.

Doing all the work in one command is faster because there are no intermediate files and only one program is executed. Very usefully, as GeeMack shows, we can use information about one image to influence the processing of a different image, within a single command.
emax wrote:There is no "one and single" way to do things.
Correct!
snibgo's IM pages: im.snibgo.com

emax
Posts: 21
Joined: 2018-02-19T03:23:45-07:00
Authentication code: 1152

Re: workflow: resize, watermark, caption

Post by emax » 2018-02-19T12:13:26-07:00

I am getting ahead with my little project here.

It is a small java program which
- reads jpg-images from an inout-directory and for each jpg found
-- displays a preview
-- allows to write a caption or take over the previous one
-- allows to define a width or takes over the previous one
-- and writes the file together with a watermark, the caption and an optional new size in an output directory

That way, it is very easy and a very fast workflow to process dozenzs of images and make them all the same size, the same watermark, and have individual captions. A tool for forum-users to get quickly some uploadable pics with a reasonable caption.

Once it is ready, I will put it somewhere and come back to this thread to tell you where.

Thank you again!

Post Reply