Page 1 of 1

Retrieve pointsize for autofitting text using caption

Posted: 2016-11-02T07:10:22-07:00
by Djidiouf
Hi, I'm currently using the autofit capability of Imagemagick but I struggle on how I can retrieve the pointsize used by -caption. I want to know what is the size of the text used to autofit a defined area.


I don't have any issue with label and can use the following command to retrieve the pointsize of the font used for autofitting a text in a box:

Code: Select all

convert -size 260x253 -background None -font /home/server/font/_resources/BebasNeue.otf -fill '#ffffff' label:"text text text text" -verbose info:

However, I'm trying to achieve the same thing with caption and that information doesn't appear in the logs.
Am I missing something? Do you know how can I do it?

Re: Retrieve pointsize for autofitting text using caption

Posted: 2016-11-02T07:45:28-07:00
by snibgo
I'm not sure what you are asking. If you run your command, with "caption:" instead of "label:", one line of output is:

Code: Select all

caption:pointsize: 72.75
You can get the result more directly by replacing "-verbose" with

Code: Select all

-format "%[caption:pointsize]"

Re: Retrieve pointsize for autofitting text using caption

Posted: 2016-11-03T06:53:36-07:00
by Djidiouf
I ran the command on Linux with Version: ImageMagick 6.8.9-9 Q16. I can confirm I don't have the caption:pointsize output unfortunately.

Code: Select all

convert -size 1260x253 -background None -font /home/server/_resources/BebasNeue.otf -fill '#ffffff' -stroke black -strokewidth 6 caption:"Il faut p" -verbose info:
Image: caption:Il faut p
  Format: CAPTION (Caption)
  Class: DirectClass
  Geometry: 1260x253+0+0
  Units: Undefined
  Type: GrayscaleAlpha
  Endianess: Undefined
  Colorspace: Gray
  Depth: 16-bit
  Channel depth:
    gray: 16-bit
    alpha: 16-bit
  Channel statistics:
    Pixels: 318780
    Gray:
      min: 0 (0)
      max: 65535 (1)
      mean: 4926.06 (0.0751668)
      standard deviation: 17097.1 (0.260885)
      kurtosis: 8.42761
      skewness: 3.22064
    Alpha:
      min: 0 (0)
      max: 65535 (1)
      mean: 9170.6 (0.139934)
      standard deviation: 22601 (0.344869)
      kurtosis: 2.34035
      skewness: -2.07815
  Alpha: graya(0,0)   #0000000000000000
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Tile geometry: 1260x253+0+0
  Background color: graya(0,0)
  Border color: graya(223,1)
  Matte color: graya(189,1)
  Transparent color: graya(0,0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 1260x253+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Orientation: Undefined
  Properties:
    caption: Il faut p
    date:create: 2016-11-03T14:49:13+01:00
    date:modify: 2016-11-03T14:49:13+01:00
    signature: ed523266469ef220c0bca83e76d71df0cef125f9a8af39512dbd2646c9422969
  Artifacts:
    background: None
    filename: caption:Il faut p
    fill: #ffffff
    MVG: path 'M8.125,0.375L30.4844,0.375L30.4844,-142L8.125,-142L8.125,0.375M47.125,0.34375L106.281,0.34375L106.281,-20L69.4844,-20L69.4844,-142L47.125,-142L47.125,0.34375M170.484,-121.656L207.281,-121.656L207.281,-142L148.125,-142L148.125,0.34375L170.484,0.34375L170.484,-58.6719L199.344,-58.6719L199.344,-79L170.484,-79L170.484,-121.656M267.719,-142L235,-142L212.234,0.5L232.766,0.5L236.625,-25.6719L264.062,-25.6719L267.922,0.5L290.484,0.5L267.719,-142M250.25,-116.844L261.016,-45L239.469,-45L250.25,-116.844M300.109,-142L300.109,-33.75C300.109,-11 311.5,2 333.453,2C355.391,2 366.781,-11 366.781,-33.75L366.781,-142L345.641,-142L345.641,-32.3594C345.641,-22.2031 341.172,-18.5469 334.062,-18.5469C326.938,-18.5469 322.469,-22.2031 322.469,-32.3594L322.469,-142L300.109,-142M375.625,-121.656L399,-121.656L399,0.34375L421.359,0.34375L421.359,-121.656L444.734,-121.656L444.734,-142L375.625,-142L375.625,-121.656M519.062,-142L486.125,-142L486.125,0.34375L508.484,0.34375L508.484,-53L519.062,-53C541.406,-53 552.391,-65.4219 552.391,-88.2344L552.391,-106.766C552.391,-129.578 541.406,-142 519.062,-142M519.062,-121.656C526.172,-121.656 530.031,-118.406 530.031,-108.203L530.031,-86.7969C530.031,-76.5938 526.172,-73.3438 519.062,-73.3438L508.484,-73.3438L508.484,-121.656L519.062,-121.656'
    stroke: black
    strokewidth: 6
    verbose: true
  Tainted: False
  Filesize: 0B
  Number pixels: 319K
  Pixels per second: 625KB
  User time: 0.600u
  Elapsed time: 0:01.510
  Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-05-16 http://www.imagemagick.org

Re: Retrieve pointsize for autofitting text using caption

Posted: 2016-11-03T10:12:39-07:00
by fmw42
It is specially computed from the command (on my IM 6.9.6.3 Q16 Mac OSX):

Code: Select all

convert -size 1260x253 -background None -font arial -fill '#ffffff' -stroke black -strokewidth 6 \
> caption:"testing" -format "%[caption:pointsize]" info:
219

Re: Retrieve pointsize for autofitting text using caption

Posted: 2016-11-03T17:41:02-07:00
by snibgo
Djidiouf wrote:ImageMagick 6.8.9-9 Q16
Perhaps this feature is newer than your version.

Re: Retrieve pointsize for autofitting text using caption

Posted: 2016-11-04T06:19:31-07:00
by Djidiouf
That was my thought yes.

Code: Select all

user@server:~/scripts$ convert -size 1260x253 -background None -font /home/user/_resources/BebasNeue.otf -fill '#ffffff' -stroke black -strokewidth 6 caption:"testing" -format "%[caption:pointsize]" info:
convert: unknown image property "%[caption:pointsize]" @ warning/property.c/InterpretImageProperties/3580.
I think the -verbose attribute displays every property and the -format "%[caption:pointsize]" lets you extract that information without having to play with grep etc..


I tried to look at the changelog available on the imagemagick website http://www.imagemagick.org/script/changelog.php but didn't find anything in relation with my issue.

Re: Retrieve pointsize for autofitting text using caption

Posted: 2016-11-04T09:41:13-07:00
by fmw42
Best I can tell from trying various versions, it first works at 6.9.1.0 and also shows in the verbose information.

Re: Retrieve pointsize for autofitting text using caption

Posted: 2016-11-04T16:37:33-07:00
by Djidiouf
I compiled ImageMagick from sources this night. I now have the version 7.0.3 and it works accordingly to your examples.

Thank you