I'm trying to convert a text label into image using imagemagick's convert util following the guide at official page
I'm using the following command.
convert -background lightblue -pointsize 72 label:" spaces " label.gif
Although my text as leading whitespace, the output image has no space in the front. Spaces are getting trimmed. Trailing spaces have no issue though. I've tried the solution given at this SO question too in vain.
While I had typed this question and was waiting to post it, I figured out a way by guessing ;-)
The solution is simply to escape the first space with blackslash.
convert -background lightblue -pointsize 72 label:"\ spaces " spaces.gif
Related
I am generating a number of imagemagick commands to write out labels, one of the labels I need to write is the following:
[0]
whenever I get to the command with this label it does not work.
This is the specific command
convert -background white -fill black -font Arial -pointsize 24 label:[0] -rotate 90 16.png
when I run this in my Mac terminal I get the message
convert: no images defined `16.png' # error/convert.c/ConvertImageCommand/3282.
I have of course tried to escape with a backslash but neither
label:[0]
or
label:\[\0\]
or
label:[\0]
or
label:\[0\]
work, and each gives the same error. Any suggestions?
Try:
convert -pointsize 36 label:'\[0\]' image.png
The single quotes prevent the shell from seeing/interpreting the square brackets as a bracket expression and the backslashes prevent ImageMagick from believing they are part of an fx-like expression.
This is an example from Imagemagick that will render the chinese characters in the file if using the ZenKaiUni font.
convert -background lightblue -fill blue -pointsize 48 -font ZenKaiUni label:#chinese_words.utf8 label_utf8.gif
I have a situation where a Chinese font is mixed with English and would like to render it with the above command. Imagemagick is rendering the English text with "?" symbols. Is it possible to provide an English font also to the same command above or any other way to render the mixed languages text ?
Thanks .
Imagemagick is not a text editor and so its text functions are basic. Later versions come with Pango and you may be able to use that.
I'm drawing the text output from display-dhammapada to an existing image. The following CLI command works:
convert test.jpg
-pointsize 30
-draw "gravity northwest
fill black
text 120,200 '$( display-dhammapada)'"
result.png
...except when I receive a quote that has a contraction. Then the text input ends prematurely with an error such as:
convert: non-conforming drawing primitive definition `s' # error/draw.c/DrawImage/3182
which was an apostrophe s case.
If I reverse the quotes from " ' ' " to ' " " ' then I end up with the literal text $( display-dhammapada) on my image.
What is the best way to sanitize my input in this case?
You could sanitise your quote through sed like this:
convert -size 1000x1000 xc:red -pointsize 30 -draw "gravity northwest fill black text 120,200 '$(./display-dhammapada|sed "s/'/\\\'/g")'" result.png
display-dhammapada
#!/bin/bash
printf "There's one there!"
FYI:
It may be an idea to write a general purpose sanitiser script that you can maintain and modify. You could consider not allowing it to pass # as the first character which would make ImageMagick read a file and could permit attacks and you may not want to allow various other things through - e.g. trailing newlines, or semi-colons.
I've got a bit of a weird question and, after parsing through ImageMagick's extensive documentation for hours, I cannot find an answer.
I have a program that creates text boxes within larger images. My current solution uses label: and caption: to create a temporary image sized appropriately, then later composites this image into the larger image. This has worked for me up until now.
convert \
-size 321x93 \
-font Carolyna-Pro-Black-Regular \
-pointsize 43 \
-fill #808080 \
-gravity center \
label:"Carolyna Pro Black\nis an obnoxious font." \
/tmp/generator20140421-7999-157xadf.png
However, recently I added some new fonts, and these fonts are a pain to work with because they have rather large ascenders and descenders (loopy, curly bits above and below the text.) In the case of these fonts, these ascenders and descenders are supposed to overflow their bounding box. I've tried a few things, but none produce the desired effect:
Making the bounding box larger: It seems like this would work, but when the -gravity is set to North, the text moves all the way to the top and clips the top anyway.
Various forms of the -draw command: These don't give me the ability to use -gravity to align my text within the bounding box, and don't seem to work with multi-line text.
Not specifying a -size argument and cropping the image later. This might be the only option, but it will take a lot of manual computation to get it to align text correctly, and adds an extra step to the process.
Essentially, my problem is that I need the text aligning capabilities that label: provides, but I don't want my text to be unnecessarily cut off.
Any ideas?
The solution turned out to be as simple as adding a newline character before and after the text, and adding the height of the text to the top and bottom of the bounding box.
I am using convert from PDF to PNG.
$ convert -density 203.294113 -resize 6000x3300\> src.pdf[0] dst.png
But when the image is created, it has a white margin added around the origin pdf page and I don't know how to eliminate it (it doesn't matter whether "density" and "resize" are used). Thanks a lot for the help.
you can use -shave to remove border with specific size or -trim to auto-trim image