I'd like to draw a text onto an image in a way like this:
convert -quality 100 -font Oswald-Regular -pointsize 515 -fill black -draw "text 1339.0,1099 'some text'" /tmp/ascript.png /tmp/ascript.png
and I need to know the dimensions of the text with the above parameters (size, font, text). How can I get that?
I tried something like this:
convert -size 5000x1500 xc:lightblue -font Oswald-Regular -pointsize 515 -fill none -undercolor white -annotate +20+100 'some text' -trim info:
but it's giving false result:
xc:lightblue XC 1834x250 5000x1500+19+0 16-bit sRGB 0.010u 0:00.000
.
What is the proper way (or a working way) to get the dimension of a drawn image based on this 3 parameters (font, size, text)?
I'm not strictly binded to ImageMagick, it can be any command line tool for the Linux shell, however, the text will be drawn by convert.
There are a couple simple ways to get the dimensions using ImageMagick with commands like this...
convert -size 5000x1500 xc:lightblue -font Oswald-Regular -pointsize 515 \
-fill none -undercolor white -annotate +20+100 'some text' \
-format "%[#]\n" info:
That uses the FX escape "%#" as the formatting string for the "info:" output. It will show IM's calculation of the after-trim width, height, horizontal offset, and vertical offset like "WxH+X+Y".
This similar command just gives the width and height of the trimmed text...
convert -size 5000x1500 xc:lightblue -font Oswald-Regular -pointsize 515 \
-fill none -undercolor white -annotate +20+100 'some text' \
-trim +repage -format "%[w]x%[h]\n" info:
That will trim the text, reset the paging geometry with "+repage", then output a string showing "WxH".
––– Edited to Add –––
I tried your image with_text.png with these commands. The output immediately follows each command...
convert with_text.png -format "%[#]\n" info:
1807x389+512+115
convert with_text.png -trim +repage -format "%[w]x%[h]\n" info:
1807x389
Those were tested with IMv6.8.9-9 on ubuntu bash on Windows 10. If you use that actual image and those commands, I'm not sure why you would get different results.
Related
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.
I would like to add a logo and some text to an image.
I can achieve this through the following:
// Add logo
composite -geometry +10+20 logo.png input.jpg \
output_with_logo.jpg
// Add text
convert output_with_logo.jpg -font Arial -pointsize 20 \
-draw "fill black text 20,50 'Test'" \
final.jpg
However I'm wondering if I can chain these 2 commands together so I can work from the same source file at once, instead of saving out staged versions of the image.
I've tried:
convert -font Arial -pointsize 20 \
-draw "fill black text 20,50 'Test'" \
-composite -geometry +10+20 input.jpg logo.png \
final.jpg
However this creates 2 "Test" strings on the image
Like this:
convert input.jpg logo.jpg -geometry +10+20 -composite -font Arial -pointsize 20 -draw "fill black text 20,50 'Test'" final.jpg
Rather than use the composite command which won't let you add text, use the convert command and its -composite operator which does the same thing. So, I am saying:
composite A.jpg B.jpg result.jpg = convert A.jpg B.jpg -composite result.jpg
Then, once you have done the compositing, you can add the text afterwards - exactly as you had it.
I am using imagemagick to create some simple graphics using the Dymo font. Here is an example:
convert -background White -fill DarkRed -font Dymo -pointsize 72 label:"DYMO FONT" -trim name.png
This command creates a file that looks like this:
I would like the red to fill all the way across, so that the image looks like a single label. I plan to use this on a page with a black background, which makes it look even worse.
I have played around with this for a while with no luck. Help would be appreciated.
Version: ImageMagick 6.9.2-7 Q16 x86_64 2015-12-06
O/S: Fedora 23
I don't know why it does that, but you can generate the text you want by replacing the space with a UTF non-breaking space and sending that to the stdin of convert and asking -label to read its text from the "file" called stdin:
printf "DYMO\xc2\xa0FONT" |
convert -background white -fill DarkRed -font DYMO -pointsize 72 label:#- result.png
Add -trim just before the output filename if you want the extraneous white space trimmed off from around the edges.
If you had more complicated text and didn't want to do that for all spaces, you could replace spaces using a short piece of Perl or sed to do it for you...
echo -n "Text with lots of spaces." | sed 's/ /\xC2\xA0/g' | convert -background white -fill DarkRed -font dymo -pointsize 72 label:#- -trim label.png
I'm trying to place a copyright message on a large batch of PNG images. I'd like to place the message in the bottom-right corner in black text on a semi-transparent white background. Here's my Windows command line script which loops through the images and runs a ImageMagick convert & composite pipeline:
for %%f in (*.png) do (
convert -background "#FFFFFF80" -font verdana -fill black ^
label:" (c) 2015 My Company " miff:- ^
| composite -compress zip -gravity SouthEast ^
-geometry +0+0 - "%%f" "credited\%%f.png" )
The white background with 50% (0x80) opacity is working well, but when the label text renders into the image, there's a horrible grey in the background of the characters. Here is an example by just running the initial convert into a PNG.
Is this a bug or am I missing something important in IM alpha channel management?
Running these commands on OSX with version 6.9.0-0 Q16 x86_64 2014-12-06:
convert -background '#ffffff80' -font verdana \
-size 360 -fill black label:"Hello World" hw1.png
convert -background '#00000080' -font verdana \
-size 360 -fill black label:"Hello World" hw2.png
convert -background '#ff000080' -font verdana \
-size 360 -fill black label:"Hello World" hw3.png
composite hw1.png -geometry +100+10 hw2.png comp12.png
composite hw1.png -geometry +100+10 hw3.png comp13.png
produces the following images:
I'm trying to convert a bunch of photos using imagemagick. However, I hadn't figured out how to overlay an image with gradient and write some text on it. I know the text part though:
convert IMG_8408.jpg \
-font URWChanceryMediumI \
-pointsize 250 \
-draw "gravity south
fill black text 0,40 'Some text stuff here'" \
test.jpg
Is there a way to add a white gradient to the bottom? Note, that the image size may vary.
What I have:
What I want:
I picked the colors so that it's clearly visible what I want to achieve
You can achieve desired output with 3 commands:
a. create the upper part of your image (a solid rectangle with your selected background color):
convert -size 640x200 xc:#A02B2B background.jpg
b. create another image containing the text over a gradient:
convert -size 640x110 gradient:#A02B2B-#126B27 -pointsize 25 -draw "gravity south fill black text 0,40 'Some text stuff here'" text.jpg
c. combine the images to obtain the final output:
montage background.jpg text.jpg -tile 1x2 -geometry +0+0 output.jpg
Note: I modified text creation parameters in step 2 to keep the command short, but you can add back your original settings
Use the following command:
magick -size 640x310 -define gradient:vector="0,107 0,0" gradient:"#a02b2b-#126b27" -flip -gravity south -font script-mt-bold -pointsize 48 -annotate +0+24 "Some text stuff here" output.png