Page 1 of 1

Save the size of the image as variables

Posted: 2010-08-23T14:56:24-07:00
by LeyreM
Hi, I've been looking for some way to save the number or rows and columns (high and width) of the image as variables to use them in some "for" loops, but the closer I've get has been just saving all the information of the image in a file .txt.
Any help, please?

Re: Save the size of the image as variables

Posted: 2010-08-23T15:01:52-07:00
by fmw42
In command line unix

size=`convert image -format "%wx%h" info:`
convert -size $size xc:red redimage.png

see http://www.imagemagick.org/script/escape.php


or

width=`convert image -format "%w" info:`
height=`convert image -format "%h" info:`
convert -size ${width}x${height} xc:red redimage.png


If on Windows, then see http://www.imagemagick.org/Usage/windows/

Re: Save the size of the image as variables

Posted: 2010-08-24T03:11:52-07:00
by LeyreM
It worked, thank you very much!!!!

Re: Save the size of the image as variables

Posted: 2010-08-26T19:29:08-07:00
by anthony
If you just want the image to be red why not just make it red.

Code: Select all

  convert image -strip -alpha off -fill red -colorize 100 redimage.png
The -strip is optional, but you get the idea.

See IM Examples, Canvas Generation, Blanking existing images.
http://www.imagemagick.org/Usage/canvas/#blank

Re: Save the size of the image as variables

Posted: 2010-08-26T19:34:05-07:00
by fmw42
anthony wrote:If you just want the image to be red why not just make it red.

Code: Select all

  convert image -strip -alpha off -fill red -colorize 100 redimage.png
The -strip is optional, but you get the idea.

See IM Examples, Canvas Generation, Blanking existing images.
http://www.imagemagick.org/Usage/canvas/#blank

He did not ask for a red image. I just used that as a simple example of using the size after it was computed.

Re: Save the size of the image as variables

Posted: 2010-08-26T19:43:10-07:00
by anthony
Applogies.

prehaps we should ask... What does he want the size for?

Or more specifically What is the final objective!

Re: Save the size of the image as variables

Posted: 2010-08-30T01:17:42-07:00
by LeyreM
Hi, I wanted to save the size of the image as variables to use them to scan the image, to count how many pixels had a specific color. However I found an easier solution in this forum, so in the end I didn't use that way...
Thanks anyway!!