Adding text before an image using imagemagick - imagemagick

how can I add some text "before" an existing image using imagemagick? That means I have an image (a signature) and I would like to add some text (the current date) before the image, on the left side (not above or bottom). How can I do that? Ive tried it with append, but that havent worked for me :-(
Here is one exemple signature
And here it is how it should looks afterwards with the current date
Ive tried it with this code so far:
convert signature.png label:21.10.2019 -gravity West +append signature-with-date.png
Now Ive tried it with other order:
convert -gravity west label:21.10.2019 signature.png +append signature-with-date.png
But there is only white space before the image added, no text is shown
Ive tried it now with:
magick \( -size 400x -background white -gravity west label:21.10.2019 \) signature.png +append signature-with-date.png
Still not working
as you can see here

This works just fine for me on Imagemagick 6.9.10.68 Q16 Mac OSX.
Unix syntax:
convert \( -size 400x -background white -gravity west label:"21.10.2019" \) signature.png +append signature-with-date.png
Windows syntax:
convert ( -size 400x -background white -gravity west label:"21.10.2019" ) signature.png +append signature-with-date.png
What is your Imagemagick version and platform?
If on Imagemagick 7, use magick in place of convert.

Related

Captioning all frames of a gif

I have a simple bash script to caption still images (jpg, png...) but it completely fails when given an animated gif. The error is convert: unable to write pixel cache '/tmp/magick-[random chars]': No space left on device # error/cache.c/WritePixelCachePixels/5854. There are many questions similar to mine, however they use specific coordinates to determine where the text should be placed (at least, I think). My script creates a dynamically sized caption area for the text to be written to. The image is appended to the bottom of the caption area (or the caption area is prepended to the top of the image, however you want to think about it.)
#!/bin/bash
input=$1
caption=$2
output=$3
wd=`convert $input -format "%w" info:`
convert \( -size ${wd}x -background white -gravity north -fill black -font FuturaBT-ExtraBlackCondensed -pointsize $(($wd/17)) \
caption:"$caption" \) \
$input \
-append $output
You can also do this in Imagemagick.
convert anim.gif -coalesce \
-gravity north -background white \
-splice 0x18 -font Arial -pointsize 12 -annotate +0+0 'THIS IS A TEST OF CAPTIONING TEXT' \
-layers Optimize anim3.gif
In Imagemagick you will need to create a text image from your caption and then use -layers composite to apply it to your animation.
Input GIF Animation:
Imagemagick 6 Unix Syntax:
convert \( anim.gif -coalesce \) null: \( -size 100x -background white -gravity north -fill black caption:"THIS IS A TEST OF CAPTIONING TEXT ON AN ANIMATION" \) -compose over -layers composite -layers optimize anim2.gif
For Windows, remove the \s
For Imagemagick 7, change convert to magick.

Imagemagick create image and place image inside with max size

I have trimmed .pngs and need them placed on a canvas (3000x3000 px) BUT with a max size.
convert -size 3000x30000 xc:transparent test.png -gravity south -composite -size 2200x2200 result.png
The code I have now works, but the sizing of the image is off. My canvas is 3000x3000px as intended, but the image placed on the canvas doesn't have the correct size. It should have a max width/height of 2200px and if possible be scaled up, if they are to small in height.
This ImageMagick command will resize the input image to 2200 pixels on the longer side while maintaining its aspect, then create a 3000x3000 transparent canvas, then swap the input image and the canvas, and finish by compositing the resized input image onto the transparent canvas...
convert input.png -resize 2200x2200 \
-size 3000x3000 xc:none +swap -gravity south -composite result.png
For Windows change that continued line backslash "\" to a caret "^". For ImageMagick v7 use "magick" instead of "convert".
Unix syntax:
convert -size 3000x30000 xc:transparent \( test.png -resize 2200x2200 \) -gravity south -composite result.png
Windows syntax:
convert -size 3000x30000 xc:transparent ( test.png -resize 2200x2200 ) -gravity south -composite result.png
Why not use -extent?
convert input.jpg -resize 2200x2200 -background none -gravity south -extent 3000x3000 result.png

Overlay PNGs with ImageMagick while keeping transparency

I have two images:
Image 1
In this image, the white region plus the white + pink region are transparent.
Image 2
GOAL
I want to merge both images (Image 1 in front, Image 2 behind) by:
Keeping the transparent region from Image 1 so that Image 2 can be
seen through the white mask.
Having the chance to locate Image 2 by vertically centering the photo in the middle of the white region.
Then, I'd like to obtain a result like this:
HOWEVER
I am using the following command in ImageMagick 6.8.9-9 Q16 x86_64 2017-07-31 in Ubuntu 16.04:
convert \( Image1.png -resize 447x640 \) \( -compose Overlay Image2.png \) -gravity north -composite Image3.png
I've tried countless times but the best result I can get (by using command above) is Image 3. Can anyone help me? Thank you.
Image 3
I think this is what you want using Imagemagick in Unix syntax:
Img:
Mask:
convert \( mask.png -alpha off \) img.jpg \( mask.png -alpha extract -negate \) -compose over -composite result.png
or more simply:
convert mask.png img.jpg -compose dstover -composite result.png

How to blend + translate simultaneously with Imagemagick (or some other scriptable software like Photoshop)?

How can I blend AND translate at the same time ?
Something like this : http://www.imagemagick.org/Usage/layers/#flatten but in such a way that the images are transparent.
I was trying :
composite -blend 90 -page +0+0 input01.jpg -page +500+0 input02.jpg -resize x400 outputSimpleMosaicBlend01.
but this did not work.
So if I have two input images:
Then how can I get an image that looks like the composite image below ?
Any suggestions how to do this programatically (not manually) with ImageMagick ? Or some other tools ?
I would like to create several thousands of composite images like that (for an animation) and I would like to automate the process.
The problem is that I can find examples that overlay images and that translate images but I cannot find examples that do these two operations simultaneously.
This is the main goal of this question, to give such code/script examples, how to do that with image manipulation tools like ImageMagick programmatically.
EDIT:
Things that I tried and did not work:
convert a.jpg -geometry +100+0 b.jpg -compose blend -composite result.jpg
gives:
I tried
convert -background none a.jpg -geometry +100+0 b.jpg -compose blend -composite result.jpg
too which gives the same result.
I got this :
with this
convert -background none input01.jpg input02.jpg -geometry +1200+0 -compose blend -define compose:args=50 -composite result.jpg
command.
It's getting close ! Thanks Mark!
A slightly different way of doing this is to set the width of the output image using -extent and then to overlay the right hand image using -gravity East to align it to the right edge - seems a fraction more intuitive to me - but go with whatever works for you!
convert a.jpg -background white -extent 2800x \
\( b.jpg -resize 150% -alpha on -channel A -evaluate set 50% +channel \) \
-gravity east -composite result.jpg
Thanks to Snigbo, the following command :
convert input02.jpg \( input01.jpg -resize 150% -alpha Opaque -channel A -evaluate Multiply 0.5 +channel -set page +1200+30 \) -background White -layers merge a.jpg
produces:

Imagemagick montage, different -extent values for 3 images

I have the following ImageMagick code that makes a poster out of 3 images, and it works well, however I would like to have a different -extent value for each of the 3 images. How would I do this? Any help would be much appreciated.
exec("montage -background black $img_1 $img_2 $img_3 -geometry 390x620+5+5 -gravity center -extent 396x626^ $img_out");
I still don't understand what you are trying to achieve, but I think the following might help you get where you are trying to go - hopefully!
I would tend to use convert rather than montage, so let's create three different size images, red, green and blue
convert -size 120x200 xc:red red.png
convert -size 200x300 xc:lime green.png
convert -size 80x120 xc:blue blue.png
they look like this
Now I try and make a poster, using a different shade of grey background for each "picture" and a different size and hope you can adapt that to your needs:
convert -gravity center \
\( -background gray70 red.png -extent 800x300 \) \
\( -background gray40 green.png -extent 300x300 \) \
\( -background gray10 blue.png -extent 100x300 \) \
+append result.png

Resources