Text outline issue with new IM version

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
rado
Posts: 2
Joined: 2016-05-05T12:26:12-07:00
Authentication code: 1151
Location: Slovakia

Text outline issue with new IM version

Post by rado »

I apologize if this has been discussed before, but I couldn't find any pointers here in the forum. I'm using IM on Raspbian (on Pi) but see the same behavior on Xubuntu PC as well. I've been using this code for a text watermark (white text with black outline for good readability in changing light conditions) for webcam images for quite some time with IM 6.7.7-10:

Code: Select all

text="Some Sample Text"
convert $1 -gravity southeast -pointsize 40 \
            -stroke black -strokewidth 4 -annotate +10+5 "${text}" \
            -stroke white -strokewidth 1 -fill white -annotate +10+5 "${text}" \
            "out.jpg"
After a recent crash and a fresh reinstall, the version of IM that apt-get gives me is 6.8.9-9 and same code suddenly behaves differently - it seems as if it calculated the box size of the text including the outline, so as a result, the black text that acts as the outline is offset to the left (as is white when compared to the previous versions).

Image

I could work around this by adjusting the offset like this:

Code: Select all

text="Some Sample Text"
convert $1 -gravity southeast -pointsize 40 \
            -stroke black -strokewidth 4 -annotate +6+5 "${text}" \
            -stroke white -strokewidth 1 -fill white -annotate +9+5 "${text}" \
            "out.jpg"
So there's a workaround. But I'm not sure - was 6.7.7-10 buggy? Or did 6.8.9-9 introduce a bug? Or am I doing this completely wrong? Thanks for any guidance in advance!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text outline issue with new IM version

Post by fmw42 »

IM 6.7.7.10 was during a big change to IM that involves linear vs non-linear color and grayscale. I would suggest you upgrade to the most current version (6.9.3.10 or 7.0.1.0). I doubt this is the cause of your issue, but see viewtopic.php?f=4&t=21269

I ran your code on my Mac OSX IM 6.9.3.10 as:

Code: Select all

text="Some Sample Text"
convert -size 581x153 xc:gray -gravity southeast -pointsize 40 \
-stroke black -strokewidth 4 -annotate +6+5 "${text}" \
-stroke white -strokewidth 1 -fill white -annotate +9+5 "${text}" \
"out.jpg"
and do not see the offset, though my default font appears to be different than yours, since the text is smaller. It looks similar to your 6.7.7.10 result. So I assume a bug in 6.8.9-9.
User avatar
rado
Posts: 2
Joined: 2016-05-05T12:26:12-07:00
Authentication code: 1151
Location: Slovakia

Re: Text outline issue with new IM version

Post by rado »

Fred, thank you for your response! My knowledge of IM is very limited, but it doesn't seem too likely that a colorspace change would affect positioning behavior? But I may be wrong.

Also, I apologize for not being really clear in my original description. The code you ran is the workaround version with offsets adjusted to work well with 6.8.9-9 (black text using +6+5 and white text using +9+5). The first code snipped in my original post is what worked well in 6.7.7-10 and doesn't work anymore (that is, if both the black and white text is positioned at the same coordinates +10+5 using southeast gravity, it would display OK in 6.7.7-10, and misaligned in 6.8.9-9). In other words, running the first snipped in both versions would give you the results displayed in my sample image (good rendering in 6.7.7-10, bad rendering in 6.8.9-9).

Oh well I hope what I wrote still makes sense. Perhaps it's too late in the evening already. :)

I am on 6.8.9-9 now, which seems to be the latest package provided by apt-get for both Raspbian and Xubuntu. Now that I have the workaround, this is no longer a mission critical issue (it never really was for this project) so I'll just stick with 6.8.9-9. Also I'm not sure which version you tried? But whatever it was, it seems to behave the same as 6.8.9-9 in this regard - as you tested the "workaround" snippet. Thanks again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text outline issue with new IM version

Post by fmw42 »

Proper usage of stroke would have no shift of the black with respect to the white if the annotate offsets are the same. Running your first command in IM 6.9.3.10 Q16 Mac OSX gives the offset. I also get a lesser offset using -gravity center. I think there is a bug. I will post it in the bugs forum.

P.S. It only seems to work correctly with -gravity northwest (default)
Post Reply