Imagemagick shows compound letter as splitted - unicode

When I try to draw text using imagemagick compound letters show as splitted. For example the word ഉത്തരം shows as ഉത് തരം without space in it.
PS: I can't write here without space as it will show as normal compound letter.
My Sublime text editor also have this problem. But in Visual studio code, it works correctly. The commands I tried below:
magick -size 1040x1310 gradient:tomato-steelblue -font Meera -pointsize 50 -fill white -gravity center -bordercolor White -border 20x20 -draw "text 0,0 'ഉത്തരം'" image.png
magick -size 1040x1310 gradient:tomato-steelblue -font Meera -pointsize 50 -fill white -gravity center -bordercolor White -border 20x20 caption:'ഉത്തരം' image.png
magick -size 1040x1310 gradient:tomato-steelblue -font Meera -pointsize 50 -fill white -gravity center -bordercolor White -border 20x20 label:'ഉത്തരം' image.png
Version: ImageMagick 7.0.10-28 Q16 x86_64
Platform: Ubuntu
Previously I was using IM version 6 of 2017 build, now I upgraded to latest manually. Still convert --version shows 6 but magick --version and magick convert --version shows latest. I also tried above commands with magick convert.

Using ImageMagick 6.9.11.28 Q16 Mac OSX Sierra, the following label: command works just fine for me.
Perhaps your problem is the meera font you are using. I got mine from https://www.malayalamfont.com/download.php?id=867. Also check your version of freetype to be sure it is current. My version was 2.10.1
convert -size 100x -background white -font /Library/fonts/meera.ttf -fill black label:"ഉത്തരം" result.png
Also -annotate and -draw work:
convert -size 100x31 xc:white -gravity center -pointsize 28 -font /Library/fonts/meera.ttf -fill black -annotate +0+0 "ഉത്തരം" result.png
convert -size 100x31 xc:white -gravity center -pointsize 28 -font /Library/fonts/meera.ttf -fill black -draw "text 0,0 'ഉത്തരം'" result.png

I looked up how to type Option+0D09 Option+0D24 Option+0D4D Option+0D24 Option+0D30 Option+0D02 in my text editor. But what I get in the editor is not ഉത്തരം. It seems that pasting into this box changes what one sees.
What I see in my text editor is the same as what I get when I render it in ImageMagick. Are you sure your 3rd character set of code, Option+0D4D, is correct? I can verify that the utf codes are what I see in my text editor by looking them up using UnicodeChecker (for Mac). I note that these are UTF-16 characters.
convert -size 100x -background white -font /Library/fonts/Meera-Regular.ttf -fill black label:"ഉത്തരം" x1.png
Or saving what I type in my text editor to a file then doing:
convert -size 100x -background white -font /Library/fonts/Meera-Regular.ttf -fill black label:#hindi.txt x2.png
ADDITION:
Here are the glyphs for the UTF character codes you specified. These are exactly what I get from ImageMagick as above.
0D09:
0D24:
0D4D:

Related

Most efficient way making an image with imagemagick

Absolut beginner here.
I got the task to write a workflow to run on a server for a web-platform that uses RoR. Server is linux based.
I want to create an image. Basically, it's a background picture, already on the server, with two green squares, one in the down left and one in the right down corner. Inside the green squares is white text from two input fields on the website (left input text and right input text).
The user uploads a logo of their sports team to be resized and fitted into the upper-right corner.
I would basically do it like:
convert -background none -fill white -font Helvetica -pointsize 100 -size 450x -gravity center caption:“text right input“ right.png
convert -background none -fill white -font Helvetica -pointsize 100 -size 450x -gravity center caption:“text left input“ left.png
composite -gravity Center left.png base.png left_done.png
composite -gravity Center right.png base.png right_done.png
composite -gravity southeast right_done.png background.png bg_right.png
composite -gravity southwest left_done.png bg_right.png bg_left_right.png
convert Logo-upload.jpg -resize 400x230 logo_resized.png
composite -gravity NorthEast logo_resized.png bg_left_right.png done.png
This is step by step command line, how I would do it.
But there must be a more efficient way, isn't it?
I would love to here your comments. Just started out with very basic tasks programming very elementary things. Would love to learn more.
//Edit: The workflow may seem weird, but it was the easiest for me to get it pixel perfect on the background.png (1000x500px)
You can do that in one command line in ImageMagick, if you use parentheses processing. Here is an example using ImageMagick 6 in Unix syntax. See https://legacy.imagemagick.org/Usage/basics/#parenthesis
Input:
Logo:
convert IMG0005.jpg \
\( -size 450x -background green1 -fill white -font Helvetica -pointsize 100 -gravity center caption:"text right input" \) \
-gravity southeast -compose over -composite \
\( -size 450x -background green1 -fill white -font Helvetica -pointsize 100 -gravity center caption:"text left input" \) \
-gravity southwest -compose over -composite \
\( olympic-logo.gif -resize 400x230 \) \
-gravity northeast -compose over -composite \
IMG0005_composite.jpg
Result:
If on Windows, remove the back-slashes from the parentheses and change the end of line back-slash to ^.
If on ImageMagick 7, change "convert" to "magick"

Add watermark after tile in ImageMagick

I got this working code for tiling an image in ImageMagick:
convert D:\tile.jpg -resize 300x300 -write mpr:tiler +delete ^
-size 900x900 tile:mpr:tiler -sharpen 0x2 D:\tiles.jpg
But now i found out that i need to add watermark in the same process. I got this working code for that:
tiles.jpg Wartermark.png -gravity southeast -geometry +0+0 -composite D:\tile-watermark.jpg
But how do i process those two in one line?

Imagemagick create thumbnail

I have an image that is 200x200 I want to trim the white space, and make it into an icon that is 32x32.
convert img.png -trim -resize 32x32 imgi.png
This line of code does not work, it will not make the canvas a uniform 32x32. I have tried taking it and adding -canvas 32x32 or -extend 32x32 but then the script does not work at all.
I am doing this from PHP with exec so I do not get an error back.
You can pad to tweak dimensions of the image after cropping. As of ImageMagick version 6.3.2 you can use -extent option to modify end result.
convert img.png -trim -resize 32x32 -gravity center -extent 32x32 imgi.png
For earlier versions it is necessary to play with -border, -crop and +repage.
convert img.png -trim -resize 32x32 -bordercolor white -border 16 -gravity center -crop 32x32+0+0 +repage img.png;

Replace transparency in PNG image with white background

I have a PNG image with an alpha channel (i.e. transparency), and I need to create versions with the image layer composed onto a white background. I want to use a scriptable command using a CLI tool such as Image Magick to directly convert PNG to PNG losslessly.
An example of a non-working Image Magick command which results in an error is:
convert input.png -background white -flatten output.png
-background white -alpha remove -alpha off
Example:
convert image.png -background white -alpha remove -alpha off white.png
Feel free to replace white with any other color you want. Imagemagick documentation says this about the -alpha remove operation:
This operation is simple and fast, and does the job without needing
any extra memory use, or other side effects that may be associated
with alternative transparency removal techniques. It is thus the
preferred way of removing image transparency.
This works for me:
convert -flatten img1.png img1-white.png
Documentation references:
-flatten command-line option
-layers command-line option (-flatten is equivalent to -layers flatten)
Flattening image and applying background image is straight forward in ImageMagick
However, order of the commands is very important
To apply any background on a transparent image and flatten it, first apply the background than flatten it. The reverse doesn't work.
$ convert sourceimage.png -background BackgroundColor -flatten destinationimage.png
The only one that worked for me was a mix of all the answers:
convert in.png -background white -alpha remove -flatten -alpha off out.png
here's how to replace the same image in all folders in a directory with white instead of transparent:
mogrify -background white -flatten */*.png
Using -flatten made me completely mad because -flatten in combination with mogrify crop and resizing simply doesn't work. The official and for me only correct way is to "remove" the alpha channel.
-alpha remove -alpha off (not needed with JPG)
See documention: http://www.imagemagick.org/Usage/masking/#remove
The Alpha Remove section of the ImageMagick Usage Guide suggests using the -alpha remove option, e.g.:
convert in.png -background white -alpha remove out.png
...using the -background color of your choosing.
The guide states:
This operation is simple and fast, and does the job without needing any extra memory use, or other side effects that may be associated with alternative transparency removal techniques. It is thus the prefered way of removing image transparency.
It additionally adds the note:
Note that while transparency is 'removed' the alpha channel will remain turned on, but will now be fully-opaque. If you no longer need the alpha channel you can then use Alpha Off to disable it.
Thus, if you do not need the alpha channel you can make your output image size smaller by adding the -alpha off option, e.g:
convert in.png -background white -alpha remove -alpha off out.png
There are more details on other, often-used techniques for removing transparency described in the Removing Transparency from Images section.
Included in that section is mention of an important caveat to the usage of -flatten as a technique for removing transparency:
However this will not work with "mogrify" or with a sequence of multiple images, basically because the "-flatten" operator is really designed to merge multiple images into a single image.
So, if you are converting several images at once, e.g. generating thumbnails from a PDF file, -flatten will not do what you want (it will flatten all images for all pages into one image). On the other hand, using the -alpha remove technique will still produce multiple images, each one having transparency removed.
It appears that your command is correct so the problem might be due to missing support for PNG (). You can check with convert -list configure or just try the following:
sudo yum install libpng libpng-devel
This is not exactly the answer to your question, but I found your question while trying to figure out how to remove the alpha channel, so I decided to add this answer here:
If you want to remove alpha channel using imagemagick, you can use this command:
mogrify -alpha off ./*.png
Welp it looks like my decision to install "graphics magick" over "image magick" has some rough edges - when I reinstall genuine crufty old "image magick", then the above command works perfectly well.
edit, a long time later — One of these days I'll check to see if "graphics magick" has fixed this issue.
I needed either: both -alpha background and -flatten, or -fill.
I made a new PNG with a transparent background and a red dot in the middle.
convert image.png -background green -alpha off green.png failed: it produced an image with black background
convert image.png -background green -alpha background -flatten green.png produced an image with the correct green background.
Of course, with another file that I renamed image.png, it failed to do anything. For that file, I found that the color of the transparent pixels was "#d5d5d5" so I filled that color with green:
convert image.png -fill green -opaque "#d5d5d5" green.png replaced the transparent pixels with the correct green.
I saw this question and answers which really help me but then I was needed to do it for a lot of files, So in case you have multiple images (PNG images) in one folder and you want to do it for all:
find ./ -name "*.png" -exec convert {} -flatten {} \;
this creates an image just placing the 1st with transparency on top of the 2nd
composite -gravity center ImgWithTransp.png BackgroundSameSizeOfImg.png ResultImg.png
originally found the tip on this post
To actually remove the alpha channel from the file, use the alpha off option:
convert in.png -background white -alpha off out.png
Tried all, none worked. This one did:
convert input.png -channel rgba -alpha set \
-fill none -opaque white \
-fill white -opaque black \
-fill white -opaque none \
-alpha off output.png
It's -alpha off, NOT -alpha remove! iOS app store upload fails when there is an alpha channel in any icon!!
Here's how to do it:
mogrify -alpha off *.png
This does the job for me:
magick convert OLD.png -background white -alpha remove NEW.png
Here is a starter image with a transparent background in case it helps with testing:
Also, for one-offs on PC, you can always open the PNG file in Windows Paint and click Save. This will automatically turn the transparency to opaque white.

Problem with generating images from unicode strings using imagemagick

i'm generating text images with following command sequence
convert -background "rgb(233, 231, 218)" -fill black \
-font media/fonts/FuturaStd-Medium.otf \
-pointsize 13 label:"ğüşıöçĞÜŞİÖÇ" -size 88x18 \
media/images/category_images/food-drink/category-top-row/tr_food-drink.png
which generates the following image.
alt text http://img54.imageshack.us/img54/5461/trfooddrinkai3.png
ğşĞİŞ are problematic, where others display correctly. my locale is en_US.UTF-8.
i'm also not having any problems trying the following example pinched from http://www.imagemagick.org/Usage/text/#unicode
convert -background lightblue -fill blue -pointsize 32 \
label:' é è à ù ç Ö ÿ ‘ ’ “ ” ° ² ³ € x ÷ ' label_i8n.gif
unicode characters displayed correctly in the label_i8n.gif.
how can i make imagemagick correctly convert these characters to image?
edit: following image is created with gimp using the same font. alt text http://img93.imageshack.us/img93/1986/gimpfuturastdnc4.png
Probably the font doesn't have those glyphs, and that's why they are displayed as "?". Check it with the Character Map application.