Page 1 of 1

Drawing text after cropping and resizing is insane

Posted: 2016-11-05T07:27:24-07:00
by whattheheck
I don't know if this qualifies as a bug but I want to get it out regardless.

First, let's add text to a 500 by 500 pixel image:

Code: Select all

convert 500by500.png \
  -gravity center \
  -draw "text 0,0 'TEXT'" \
out.png
Image

No problems so far:

Now let's crop the image (and add a line):

Code: Select all

convert 500by500.png \
  -crop 400x400+0+0 \
  -gravity center \
  -draw "text 0,0 'TEXT'" \
  -draw "line 0,200 400,200" \
out.png
Image

Problem: drawing text doesn't respect the new image dimensions.

Note that line does respect the new dimensions, so even if text is somehow behaving as desired, it's still undesirable that line and text behave so differently given that their syntax is very alike.

Things get very complicated if you add crop offsets and resizing and then try to compensate for all of that. This can all be avoided if drawing text would behave like drawing lines, so:

Suggested fix: make drawing text behave the way drawing lines does.

Re: Drawing text after cropping and resizing is insane

Posted: 2016-11-05T09:23:39-07:00
by snibgo
Well, have you looked at the coordinates the text has been placed? It is at (250,250), which is the centre (because you have "-gravity center") of the canvas.

The canvas is still 500x500 because you have no "+repage" after "-crop". As a general rule, when you "-crop" or "-trim", always consider adding "+repage" after it. Of course, there are many times you don't want "+repage".

"-draw line" doesn't respond to gravity; its coordinates are always absolute. The documentation http://www.imagemagick.org/script/comma ... s.php#draw tells you that text responds to gravity, but the others such as line don't.

In other words: RTFM.

PS. I'm moving this out of "Bugs" to "Users".

Re: Drawing text after cropping and resizing is insane

Posted: 2016-11-06T06:50:13-07:00
by whattheheck
Hi snibgo.

This post was borne of frustration because, well.. I didn't RTFM.

Thank you for the explanation and my apologies for filling this as a bug instead of question.

Re: Drawing text after cropping and resizing is insane

Posted: 2016-11-06T07:37:25-07:00
by snibgo
No problem. IM's facilities (and "convert" language) have grown and evolved over the decades so they often don't follow neat logical patterns and we scratch our heads wondering why IM does this but not that.

In my idle moments I've considered a proper, formal language for IM. But the underlying mechanisms (eg what operations respond to what options) don't lend themselves to that.