ImageMagick glyph width error - imagemagick

I try to overlay two versions of the same text using different fonts (to create text effects like outlines and multi-color letters).
The fonts are defined with identical glyph widths, if I use Photoshop (or any text processing software) to generate the two texts and overlay them, they fit perfectly.
But ImageMagick doesn't seem to care about glyph widths but uses its own positioning system. So the two layers don't fit even if it's only a one-letter-text to be displayed.
What font definitions are used by ImageMagick?
Here my command for displaying a "4":
convert -size 500x500 xc:transparent -antialias -stroke none -pointsize 140 -gravity southwest -fill "#00ff00" -font FontBack.ttf -annotate 0x0+0+0 "4" -fill "#ff0000" -font FontOverlay.ttf -annotate 0x0+0+0 "4" -trim -virtual-pixel Background temp.png
To position the layers with the annotate options won't be a solution, as texts are generated dynamically in an imageprocessor.
Any ideas?

Related

align text to left with imagemagick

I am using ImageMagick to add text to an image. I used to -gravity Center flag to put the text in the center of the image. But I think this is resulting in the text being center aligned too. I want the text at the center of the image but left aligned. Here is an example of what I'm trying to have:
This is the output I'm getting:
Current output
This is what I want:
This is my requirement
How do I accomplish this? This is my first time using ImageMagick. Please guide me.
Here is one way to do that in Imagemagick 6. I specify the background color, the font color (fill), the font and the pint-size and gravity west (left side). I use label: to create the two lines of text with a new line between them. This creates a text image of the size needed to hold the text. Then I pad the image all around that to the final size with the text image in its center using the same background color.
convert -background black -fill white -font ubuntu -pointsize 28 -gravity west label:"This is line 1 of text\nThis is line 2 of text" -gravity center -extent 400x300 result.png
See
https://imagemagick.org/Usage/text/
https://imagemagick.org/Usage/crop/#extent
ADDITION
If you want to put the text over an existing image, then you do something similar, but in place of the extent, we composite the text image over the background image.
The following is Unix syntax. For Window, remove the backslashes \ before the parentheses.
Input:
convert lena.png \( -background black -fill white -font ubuntu -pointsize 21 -gravity west label:"This is line 1 of text\nThis is line 2 of text" \) -gravity center -compose over -composite result.png
Result:
Or if you do not want the black background, use "none" for the color.
convert lena.png \( -background none -fill white -font ubuntu -pointsize 21 -gravity west label:"This is line 1 of text\nThis is line 2 of text" \) -gravity center -compose over -composite result2.png

Smooth text edge with ImageMagick

I'm using ImageMagick ver 6.9.3-7 to write text over pictures. I've noticed that the same text with the same font looks much better in html canvas and I'm trying to make it looks the same.
This is how it looks in the html5 canvas:
and this is how it's looks with IM:
(enlarge the images to view the different)
This is how I'm creating the image with node.js:
gmFrame
.font("./assets/impact.ttf", fontSize)
.stroke("#000")
.strokeWidth(8)
.draw(`gravity center text ${position.x},${position.y} '${text}'`)
.stroke("transparent")
.fill("#fff")
.draw(`gravity center text ${position.x},${position.y} '${text}'`);
Is there something to do about it?
After investigating the only way to do it is with blur.
This is an example for how to add text with blur without writing another file
convert -quality 100 "DJ Pauly D.jpg" -resize 500x500 \( +clone -alpha transparent -pointsize 52 -font impact -stroke "#000" -strokewidth 8 -draw "gravity center text 0,0 'WRITE SOMETHING'" -stroke "transparent" -fill "#fff" -draw "gravity center text 0,0 'WRITE SOMETHING'" -blur 0x5 \) -composite r2.png

Generating small text with Imagemagick is blurry

I'm trying to generate an image using Imagemagick to match a preview in the browser, but the text comes out blurry. Does anybody have any suggestions? Attached is an image with the Imagemagick one on top, and browser one on bottom, along with the IM code.
convert -density 288 -resize 25% -background white -fill black -strokewidth 0 -stroke white -font Rubik-Regular.ttf -pointsize 10 -gravity center label:'This is a TEST!' label_arial.gif
You might find it easier to start with caption which automatically sizes the text the best way to fill a given area. So, as your lettering is around 140x36 pixels, you would do:
convert -size 140x36 -gravity center caption:'This is a TEST!' label.gif

Apply watermark with text / image using GraphicsMagick

I need to be able to apply watermark on an image, using either text or another image.
Getting it to work with an image was quite straight forward, using the following command:
gm composite -dissolve 15 -tile logo.png image.jpg wmark_tiled.jpg
Now, I also want to be able to use text for watermarking (in other cases). The only thing that I found close to it, is a command from ImageMagick tutorial which is the following :
convert -size 140x80 xc:none -fill grey -gravity NorthWest -draw "text 10,10 'copyrigh text'" -gravity SouthEast -draw "text 5,15 'copyright text'" miff:- | gm composite -tile - image.jpg copyrightImage.jpg
Although its not working in GM, and I would rather avoid using pipe as it causes some headaches managing it from Java.
What I thought I could do, is generate an image from a given text, and then use that image as logo.png is used on my first command. Although I cannot find how to generate an image out of text, all I find is putting text on top of an image.
Ideally I will generate a transparent image with the text, and from what I see modifying font/color etc should be quite flexible.
Any suggestions on how to achieve this, or any better solutions are welcome.
(I added imagemagick tag as the interfaces are often same/similar)
I'm not sure I fully understand your query, so apologies if I've misunderstood, but are you trying to create a transparent image, with some text in the corner? If so, would this not work?
convert -background transparent -fill grey -font Calibri -size 140x80 -pointsize 14 -gravity southeast label:'copyright text' output.png
Obviously adjusting the font, pointsize, output image name etc. That would create the following:
http://oi42.tinypic.com/14j1bvp.jpg
P.S. that was written for ImageMagick. I don't know how GM differs or whether it would still work.
To be able to get the watermark text into the same image I had to use the -annotate parameter.
So Moogle's code snippet would look like this in my case:
convert original_image.jpg -background transparent -fill grey -font Calibri -size 140x80 -pointsize 14 -gravity southeast -annotate +0+0 'copyright text' output.jpg

Add gradient overlay under a photo label using imagemagick

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

Resources