Page 1 of 1

Get and save image dimension in memory?

Posted: 2017-05-08T15:23:39-07:00
by Don
Hello,

I was wondering if it's possible to get an image dimension and then save it into memory for later use, like the following:

Code: Select all

convert \( -size 400 -background transparent caption:”this is some text“ -write mpr:captionText +delete \) \( mpr:captionText -format "%[fx:h]" INFO: -write mpr:imgWidth +delete \)
When you don't supply the height for -size when using the caption command and just the width, the height is automatically determined for your image/text which is great and really glad it's capable of doing this, but what if I want to find out what the height from the caption command will be without having to write the image to disk but to memory instead so that I can use the height for something else?

Thanks in advance.

Re: Get and save image dimension in memory?

Posted: 2017-05-08T15:43:26-07:00
by snibgo
Your bash command has bad syntax. It must end with an output filename (which could be "info:"). Within the command, you can "+write info:" at any time.

To capture the single-line output from a bash command, use backtick, like this:

Code: Select all

$ size=`convert rose: -format %[fx:h] info:`
$ echo $size
46

Re: Get and save image dimension in memory?

Posted: 2017-05-08T15:49:44-07:00
by fmw42
This should work and is similar to snibgo's suggestion.

Code: Select all

height=`convert -pointsize 36 -size 400x caption:"This is some long text that should wrap to the next line" -format "%h" info:`
echo "$height"
126

Or perhaps you want to save it inline. If so, then

Code: Select all

convert -pointsize 36 -size 400x caption:"This is some long text that should wrap to the next line" -set option:hsize "%h" -format "%[hsize]" info: 
126

Perhaps a better explanation of what you are trying to do later with the height would help us understand what you want.