pointsize reporting with best fit use of label:

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
fmw42
Posts: 23900
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

pointsize reporting with best fit use of label:

Post by fmw42 » 2010-06-17T11:27:20-07:00

I was wondering if it would be possible to report the pointsize created when using label: with a specified size only. For example:


convert -size 160x -background lightblue -fill white -verbose label:"TESTING" null:

reports

label:TESTING=>TESTING LABEL 160x41 160x41+0+0 16-bit DirectClass 0.190u 0:00.220

Would it be possible to include the resulting pointsize of the text that was drawn?


This would be very beneficial when trying to get the image size and pointsize for subsequent use with -annotate.

snibgo
Posts: 10723
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pointsize reporting with best fit use of label:

Post by snibgo » 2010-06-17T15:26:08-07:00

Good idea. Meanwhile, "-debug all" seems to list all the pointsizes tried.
snibgo's IM pages: im.snibgo.com

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

Re: pointsize reporting with best fit use of label:

Post by fmw42 » 2010-06-17T16:08:30-07:00

snibgo wrote:Good idea. Meanwhile, "-debug all" seems to list all the pointsizes tried.

Good catch Alan! Now I just need to filter all the attempts to get the final pointsize and dimensions. That might do in the meantime.

Fred

PS. Unfortunately, I am having trouble using SED or GREP to extract the pointsize only from the debug text. Not sure if it is me or the way the text is output. It seems to go to the terminal and cannot be piped to SED or GREP.

PS2. using -debug annotate (even with label:) seems to give similar pointsize information, but not everything else. However, I still cannot filter that to get just the last pointsize.
Last edited by fmw42 on 2010-06-17T16:48:54-07:00, edited 1 time in total.

snibgo
Posts: 10723
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pointsize reporting with best fit use of label:

Post by snibgo » 2010-06-17T16:44:36-07:00

On Windows, it goes to stderr, so

convert -size 160x -background lightblue -fill white -verbose -debug all label:"TESTING" null: 2>x.txt

and then grep and tail for the final pointsize. (But I haven't really played with this.)
snibgo's IM pages: im.snibgo.com

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

Re: pointsize reporting with best fit use of label:

Post by fmw42 » 2010-06-17T16:57:42-07:00

I had tried 2>&1 with no success. But your method does work.

convert -size 160x -background lightblue -fill white -debug annotate label:"TESTING" null: 2> text_label.txt
cat text_label.txt | sed -n 's/^.*[ ]*pointsize[ ]*\([0-9]*\)$/\1/p' | tail -n 1


However, it would be nice to avoid writing to a file.

Thanks Alan.

Fred
Last edited by fmw42 on 2010-06-17T17:20:32-07:00, edited 2 times in total.

User avatar
magick
Site Admin
Posts: 10842
Joined: 2003-05-31T11:32:55-07:00

Re: pointsize reporting with best fit use of label:

Post by magick » 2010-06-17T17:03:42-07:00

In the next release of ImageMagick, look for label:pointsize as a property.

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

Re: pointsize reporting with best fit use of label:

Post by fmw42 » 2010-06-17T17:10:58-07:00

magick wrote:In the next release of ImageMagick, look for label:pointsize as a property.

Thanks. I am not sure how that will work. Do you mean that it will be reported with -verbose as in my command earlier? If so, that will be terrific, because I want to be able to extract the width, height and pointsize when using label: from once instance and then I can filter the text returned to get each of these properties. That will help a lot when using label to get the width, height and pointsize to feed then to -annotate to do the more fancier text creation.

Let me know when in a Beta and I will test this.

Fred

User avatar
magick
Site Admin
Posts: 10842
Joined: 2003-05-31T11:32:55-07:00

Re: pointsize reporting with best fit use of label:

Post by magick » 2010-06-17T18:20:14-07:00

The patch will be available in one hour @ magick.imagemagick.org:pub/ImageMagick/beta.

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

Re: pointsize reporting with best fit use of label:

Post by fmw42 » 2010-06-17T21:20:55-07:00

magick wrote:The patch will be available in one hour @ magick.imagemagick.org:pub/ImageMagick/beta.
Perhaps I am premature in testing or do not understand how to extract the pointsize.

I just downloaded and installed 6.6.2-7 Beta and tried


convert -size 160x -background lightblue -fill white -verbose label:"TESTING" null:

label:TESTING=>TESTING LABEL 160x41 160x41+0+0 16-bit DirectClass 0.190u 0:00.200
label:TESTING=> LABEL 160x41 160x41+0+0 16-bit DirectClass 0.010u 0:00.000


But don't see the pointsize here. Am I doing something wrong or am I premature in testing? It is not urgent, if it is not ready yet

User avatar
anthony
Posts: 8871
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: pointsize reporting with best fit use of label:

Post by anthony » 2010-06-17T22:00:50-07:00

fmw42 wrote:
magick wrote:In the next release of ImageMagick, look for label:pointsize as a property.
Thanks. I am not sure how that will work.
It means it will be set as an image properity (-set) or artifact (-define). probably the former. that in turn is accessible from verbose info: (identify) output, or -format percent escapes. Of course not all file formats will save the information, though it will be present in-memory or in MIFF.

For example

Code: Select all

   convert label:t -verbose info:
outputs...
...
Properties:
date:create: 2010-06-18T14:53:16+10:00
date:modify: 2010-06-18T14:53:16+10:00
label: t
signature: dfccf3ecae95aa07a323b231fd3ff9eae965249f4b9e66da83d274d6746e6e58
Artifacts:
verbose: true
...
whcih shows that 'label' contains the string that was used to generate the label! (something you recently came accross and commented on). When Cristy (magick) addes his code. then there will also be a label:pointsize 12 in the above. Which means you can access it using. a -format %[label:pointsize], just as you can with any other 'Property'.

until then try...

Code: Select all

   convert label:t -format '%[date:create]'  info:
or

Code: Select all

   convert label:t -print '%[date:create]\n'  null:
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

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

Re: pointsize reporting with best fit use of label:

Post by fmw42 » 2010-06-18T09:31:31-07:00

Thanks I see it now by doing:


convert \( -size 160x -background lightblue -fill white label:"TESTING" \) \
-verbose info:

Properties:
date:create: 2010-06-18T09:30:21-07:00
date:modify: 2010-06-18T09:30:21-07:00
label: TESTING
label:pointsize: 35
signature: 3c5ccc42fa207dac992b84878074c919a9d3c9eaebc39d3d101001407fbef0be


And this gets the width, height and pointsize


convert \( -size 160x -background lightblue -fill white label:"TESTING" \) \
-format "%wx%hx%[label:pointsize]" info:

160x41x35


Anthony, thanks for the explanation.

Thanks Magick for the implementation.

This will work great.

User avatar
anthony
Posts: 8871
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: pointsize reporting with best fit use of label:

Post by anthony » 2010-06-18T19:29:49-07:00

I am hoping to have these properties report other information too. For example it could report the number of primitive iterations morphology last performed. Or in a connected object labelling operation I could have IM report the number of connected objects that it found and coloured.

Note -set also sets these labels. For example -set filename:tile_offset '%O' +repage would remove the virtual pixel offset, but still keep a copy of it for later use.
You can use +set to remove property.

-set option:... however will defines a 'artefact' (such as verbose does in the above example) -define also only sets artefacts. Artefacts are meant only to be used by image processing operators such as coders and expert options. For exampe -set option:compose:args ... actually sets a -define compose:args=...

I only learned this facite of Im operations myself recently, so only have rough notes about it in "Basics, Settings" at this time.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply