Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve ImageMagick's "Fontconfig warning: ignoring UTF-8: not a valid region tag" error?

I want add some text on an image file with ImageMagick,

This is what I entered:

convert -font Verdana label:"Text 123" pic.jpg pic_new.jpg

But it returns an error as follows:

Fontconfig warning: ignoring UTF-8: not a valid region tag

The generated picture doesn't have any test added on.

I googled it but most of the posts are not helping much.

Thanks for any kind of tips!

like image 678
AGamePlayer Avatar asked Jul 12 '14 10:07

AGamePlayer


1 Answers

This warning shows up because your local environment states a locale (UTF-8 in this case) which is not valid.

It all boils down to the environment variable named LC_CTYPE which defines the locale to be used. In your case this will default to UTF-8 which simply isn't a locale that is available on your system and thus you see ImageMagick display the warning.

You can run

echo "$LC_CTYPE"

to see what the current setting is.


I know of two ways to remedy this problem:

A) Fix your shell configuration

Depending on which system you're on, there are ways to apply different defaults to your shell. In my case the problem was local only, and i run OS X, so the solution was very simple. In the configuration of the terminal application under the Advanced tab, there is a section called International.

Terminal.app encoding configuration

The Set locale environment variables on startup box was checked by default. After unchecking it and restarting the terminal session, LC_CTYPE was no longer set. Therefore there were no more warnings from ImageMagick.

B) Supply the locale

Personally, i don't think this is a good approach. It's more like a workaround that can be messy, and is best avoided. It is also not the correct way to deal with the issue, but it still leads to no further warnings from ImageMagick.

By finding ImageMagick's locale.xml you can identify a list of locale configuration files. Finding the one that matches your working environment (given that you do NOT wish to work with different locales per default) you can copy that file and leave a reference in locale.xml which is identified by locale="UTF-8".


If your problem occurs on some remote server, you can still apply approach (A) but you need to find out how to set the environment variable LC_CTYPE (or unset it) once the session starts.

Hope this helps.

like image 97
SquareCat Avatar answered Sep 21 '22 22:09

SquareCat