Animation with images and their title

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
Amy
Posts: 3
Joined: 2015-12-04T02:15:15-07:00
Authentication code: 1151

Animation with images and their title

Post by Amy »

Hi everybody,

do you think it’s possible to create an animation in which for each image, its filename is also drawn.
It means, creating an animation with -draw "text ....MYTEXT" knowing that MYTEXT will be different for each image of the animation.

Sorry for my english... Thank you for your help :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Animation with images and their title

Post by fmw42 »

It is possible. Do you want the filename in the image or below it? What platform are you using and what version of Imagemagick.

Are there images onto which you want the text draw or is it just a colored background with text drawn on it.

Please read viewtopic.php?f=1&t=9620
Amy
Posts: 3
Joined: 2015-12-04T02:15:15-07:00
Authentication code: 1151

Re: Animation with images and their title

Post by Amy »

Thanks;
I'd rather get the filename below each image.
I am on linux ubuntu and I use ImageMagick 6.5.4-7 . For the moment, I create the animation with this command:

Code: Select all

convert -delay 50 -resize 640x480 -loop 2 ${Inputs[*]} $OutGif 
"Inputs" is my list of real jpg images, not just colored backgrounds.
Thank you very much.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Animation with images and their title

Post by fmw42 »

try this

Code: Select all

montage -label "%f" ${Inputs[*]} -resize 640x480 -geometry +0+0 -tile 1x1 miff:- |\
convert -delay 50 - -loop 2 $OutGif 
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animation with images and their title

Post by anthony »

You can modify each image, before creating the animation
So have a look at image annotation...
http://www.imagemagick.org/Usage/annotating/

Finally you can do this on the fly by looping over the input images and outputing the result as a MIFF:- pipeline into the animation generating image. A simple example of this using montage was given by Fred (above), but using a loop will allow you to do more complex processing, one image at a time. This is detailed in
http://www.imagemagick.org/Usage/files/#miff_stream

Example based on given code...

Code: Select all

for image in "${Inputs[@]}"; do
   convert  "$image" {annotate the image} -resize 640x480  miff:-
done |
   convert miff:- -set delay 50 -loop 2 $OutGif
ASIDE: Note the shell scripting mechanic "${Inputs[@]}" which correctly preserves special characters like spaces in the input shell array. Using '*' in the expression will fail unexpectedly in many situations. Though technically this is shell scripting, not image processing.

Also look at the examples on Animation Modifications
http://www.imagemagick.org/Usage/anim_mods/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Amy
Posts: 3
Joined: 2015-12-04T02:15:15-07:00
Authentication code: 1151

Re: Animation with images and their title

Post by Amy »

I should extract a substring from each image file name so the "for" loop is the best approach.
Anthony'solution works fine! !thanks, thanks to fmw42 too.

Code: Select all

for image in "${Inputs[@]}"; do

   convert  "$image" -gravity South -background Grey -splice 0x20 -fill white -pointsize 15 -annotate +0+8 "${image:5:15}" -resize 640x480  miff:-
done |
   convert miff:- -set delay 50 -loop 2 $OutGift
 


Best regards
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animation with images and their title

Post by anthony »

Glad to have helped. I see you also used the "Splice and Draw" technique to add a label under the image. ;-)

Just remember this does change the ratio of dimensions of the resulting image and thus it is unlikely image will
resize to be exactly 640x480 (especially if the image did have a 4:3 aspect ratio to start with).

That is why drawing on top of the image may be better. Depends if you need to preserve the 4:3 aspect ratio of an image (say to match the output display) or not.

Also doing this before the resize means that if you apply the label to say a larger image than others in the sequence, the final label for that image after resizing may be smaller than the others. For example labelling a 640x480 image from a website, then a 2304x1728 image from my first digital camera, or a 3264x2448 from a modern mobile phone.

You probably should resize the image first (leaving space for the appended/spiced label) first.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Animation with images and their title

Post by fmw42 »

If preserving aspect is important, then you might be better using my montage method or just writing into the image with -undercolor along with -annotate to allow the text to be seen easier.
Post Reply