Drawing text after cropping and resizing is insane

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
whattheheck
Posts: 2
Joined: 2016-11-05T06:32:52-07:00
Authentication code: 1151

Drawing text after cropping and resizing is insane

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Drawing text after cropping and resizing is insane

Post 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".
snibgo's IM pages: im.snibgo.com
whattheheck
Posts: 2
Joined: 2016-11-05T06:32:52-07:00
Authentication code: 1151

Re: Drawing text after cropping and resizing is insane

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Drawing text after cropping and resizing is insane

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply