Limit Textbox size

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
KandisZZ
Posts: 21
Joined: 2011-02-13T05:47:57-07:00
Authentication code: 8675308

Limit Textbox size

Post by KandisZZ »

Hello Again.
I cant get an answer for my problem.
I want to limit the Textbox size.
IM respects the left and right of my given -size WxH argument.
But if the Text is too big, the Text floats down.
I want it cutted off.

Hope u understand what i mean.

thx for help!

paul.

*edit: I tried to crop. Wont work. I think there must be an easy way for this.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Limit Textbox size

Post by fmw42 »

post your command so others can see what you are doing and perhaps give suggestions.

also what version of IM and platform are you on?
KandisZZ
Posts: 21
Joined: 2011-02-13T05:47:57-07:00
Authentication code: 8675308

Re: Limit Textbox size

Post by KandisZZ »

Hi.
IM 6.5.7.

Code: Select all

-background none  -font Fonts/myFont.ttf -size 100 x 100  -fill '#123456' -gravity North  -pointsize 22  caption:'Hello All'  -set page +10+10 -crop 100 x 100 +0+0 
Greets paul.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Limit Textbox size

Post by fmw42 »

-background none -font Fonts/myFont.ttf -size 100 x 100 -fill '#123456' -gravity North -pointsize 22 caption:'Hello All' -set page +10+10 -crop 100 x 100 +0+0
Perhaps I do not understand your problem, but this seems to work fine for me in IM 6.6.7.7 Q16 Mac OSX Tiger.


convert -size 100x100 -background none -font /library/fonts/arial.ttf -fill '#123456' \
-gravity North -pointsize 72 caption:'Hello All' \
tmp.png


Note that you must remove spaces for size between -size 100 x 100 and also -crop 100 x 100 +0+0

thus -size 100x100 and -crop 100x100+0+0

If you still have a problem, please post a link to your resulting image, full command line, and explain what is not working the way you would like.
KandisZZ
Posts: 21
Joined: 2011-02-13T05:47:57-07:00
Authentication code: 8675308

Re: Limit Textbox size

Post by KandisZZ »

Hey!
Wow the same code without the spaces work now.
Thx a lot.
Is this an intended behavior?

greetings paul.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Limit Textbox size

Post by fmw42 »

Yes, you must remove those spaces as IM interprets any words or characters separated by spaces as either separate images or parameters. Thus geometry must not have spaces in it.

see http://www.imagemagick.org/script/comma ... essing.php

where it says:

"The geometry argument might take any of the forms listed in the table below. These will described in more detail in the subsections following the table. The usual form is size[offset], meaning size is required and offset is optional. Occasionally, [size]offset is possible. In no cases are spaces permitted within the geometry argument."
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Limit Textbox size

Post by anthony »

Actually that is not a IM problem, but a shell (BASH) problem.

Shell will separate all words separated by any white-space as separate arguments.

As such when you have -crop 100 x 100 +0+0
the shell parses that into 5 arguments, where IM is expecting only 2 arguments... -crop and its single required geometry-style argument.

IM probably was producing errors like: unable to open image "x"
that should be the give away IM is not getting what it expects as it is seeing 'x' as a filename and not as part of the -crop argument.

The other effect (other than read errors) is that -crop 100 (what IM is seeing) is equivalent to -crop 100x0 or cut the image into multiple (tiled) 100 pixel columns!!!! Which is probably NOT what you want!

Removing the spaces causes the shell to treat the 100x100 as a single argument (two total).
The other solution is use quotes so as to tell the shell to include the spaces in the argument
EG: -crop '100 x 100 +0+0'

IM does understand spaces and will handle an argument containing spaces (ignoring them as appropriate). A long time ago this wasn't the case, which is why that line in the reference manual
still exists.



ASIDE... IM Internals...

Geometry arguments are a special argument that has a commonly used (and complex) parser. It basically allows a user to specify a single argument containing up to 5 floating point values (though most operators only use integers). These are typically of the form: WxH+X+Y but can also be in the forms of +X+Y or A/B/C or A,B,C,D,E, due to operator requirements. On top of that it reports if special 'flag' characters are present (any of %@^!<> ), but it only the characters presence, not where they were found. IM for example does not remember is that % was attached to a specific number, just that it was present.

If more than 5 numbers are needed, a different argument-style The floating point list, is used, though at the moment these are generally parsed by individual arguments. For example -sparse-color can substitute colors for some floating point values, though they also become floating point values when passed into the core library. Other operators may understand percents, or not. That makes non-geometry arguments a highly variable, depending on the operator parsing it.

In future there is a push to allow the use of percent escapes in ALL arguments, including geometry arguments, but 'percent' handling (is it a percent escape, or a percent flag?) is a bit of a problem.
See IM Examples, Future Development,
Setting arguments from in memory images and/or other settings
http://www.imagemagick.org/Usage/bugs/future/#settings
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply