Bug in MagickAnnoteImage() if locale is set to de_DE.UTF-8
Marvin Gülker <[email protected]>
| Newsgroups | gmane.comp.video.graphicsmagick.help |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I think I have found a bug in GraphicsMagick's Wand C API. The problem
is that the MagickAnnotateImage() function always positions the text it
is given at (0|0) no matter which actual values you pass for the X and Y
co-ordinates. This however only happens if the programme's locale is set
to de_DE.UTF-8; if the programme runs under en_US.UTF-8 everything works
as expected.
Below is a minimal example demonstrating the problem. You need to run it
on Linux with your environment's locale set to de_DE.UTF-8 to reproduce
the issue. It is expected that the text "My line of text" is positioned
at (200|200), but it is placed at (0|0) (observe how it nearly is off
the viewport due to that at the top-left corner). Running the programme
under an environment locale of en_US.UTF-8 works. Removing the call to
setlocale() will also make the programme work (under any environment
locale), because the programme is then assumed to be in the C/POSIX
locale, which is basically ASCII English.
I suppose GraphicsMagick does some string->number conversion by looking
for a "." character in a string. The problem with this is that in
Germany, floating-point values are not denoted with a point, but with a
comma, i.e. where in English you write "0.5" for one half, in Germany you
write "0,5", which is what the environment locale affects. This is just
a guess; the problem might be different, but I have run into that myself
earlier.
My environment is Gentoo Linux, kernel 4.9.16, environment set to
de_DE.UTF-8. GraphicsMagick version 1.3.25.
Here is the minimal example:
/* gm-bug.c -- Minimal example reproducing GraphicsMagick locale bug.
*
* Compile with:
*
* $ gcc -o gm-bug gm-bug.c `GraphicsMagickWand-config --cppflags --ldflags --libs`
*
* Then run as:
*
* ./gm-bug
*/
#include <locale.h>
#include <wand/magick_wand.h>
int main(int argc, char* argv[])
{
MagickWand* p_wand = NULL;
DrawingWand* p_font = NULL;
/* If the following line is removed, the text is placed as it is
* expected. With it, it always ends up at (0|0) (top-left corner,
* usually outside viewable area unless you request a multiline
* text). Test with system locale de_DE.UTF-8. */
setlocale(LC_ALL, "");
InitializeMagick(argv[0]);
p_wand = NewMagickWand();
MagickReadImage(p_wand, "mypic.jpg");
p_font = NewDrawingWand();
DrawSetFont(p_font, "DejaVuSans.ttf");
DrawSetFontSize(p_font, 20);
MagickAnnotateImage(p_wand, p_font, 200.0, 200.0, 0.0, "My line of text");
MagickWriteImage(p_wand, "output.jpg");
DestroyDrawingWand(p_font);
DestroyMagickWand(p_wand);
DestroyMagick();
return 0;
}
DejaVuSans.ttf is the DejaVu Sans font, included by probably all major
Linux distros. You can download it from
<https://dejavu-fonts.github.io/> if you don't have it, or change it to
another font you have available. It does not matter for the problem
which font you use.
Greetings
Marvin
--
Blog: https://www.guelkerdev.de
PGP/GPG ID: F1D8799FBCC8BC4F
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot