Image magic text writing on image dynamically - imagemagick

I am building a image editor with php, jquery, image magic, I am trying to write text on image dynamic position but not getting the exact command of image magic.
I tried imagemagic commands of writing text but these commands are for fixed position. e.g i need to write text on image "hey love" on position (x: 831, y: 38) x is width and y is height now what i need is exact command able to write text on dynamic positions.
convert temp.jpg -gravity North -pointsize 30 -annotate +0+100 'Love you mom' temp1.jpg
this command uses gravity i have dynamic positions

You can do it like this:
convert -size 400x250 xc:cyan -pointsize 18 -fill magenta -draw "text 250,65 'Love you Mum'" result.png

Related

Rmagick custom text width/padding using annotate method

As per the documentation on Rmagick we can set the width of the rectangle within which our text is placed.
http://www.simplesystems.org/RMagick/doc/draw.html#annotate
Below is the code that we are using but we are unable to set the padding or a custom width for the text in the annotate block.
For a use case we wanted to have a custom padding for the text that we give in the annotate block.
img=Image.new(1500,600)
b=Magick::Draw.new
b.annotate(img,120,10,120,120,"5"){ |txt|
txt.pointsize = 58
txt.undercolor= "blue"
}
b.get_type_metrics(img, "5")
img.write("undercolor3.gif")
Have tried a ton number of things but couldn't make it work.Any ideas?
Draw a block of the desired undercolor on the image, then annotate the image such that the text is over the block.
To determine the desired size of the block, use get_type_metrics or get_multiline_type_metrics to get the dimensions of your text, then add in how much padding you want.
Annotate in ImageMagick does not have any option to pad the undercolor. But you can trick it. The simplest ways is to put spaces on the left and right side of your text using "\ ". But that will only pad on the left and right. In label: you can add newlines, but that does not work in annotate. You could add -interline-spacing, but that will only pad on the bottom. But here is a trick. Create text in the undercolor with a slightly larger pointsize, then write over it with your desired color text. For example:
Without padding:
convert logo.jpg -gravity center -undercolor pink -pointsize 24 -fill black -annotate +0+0 "This Is Some Text" result1.jpg
With padding:
convert logo.jpg -gravity center -pointsize 34 -undercolor pink -fill pink -annotate +0+0 "X X" -pointsize 24 -fill black -annotate +0+0 "This Is Some Text" result2.jpg
Alternately, you could just draw a pink rectangle in the center of the image of the desired size.

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

ImageMagick glyph width error

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?

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