Save the size of the image as variables

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
LeyreM

Save the size of the image as variables

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Save the size of the image as variables

Post 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/
LeyreM

Re: Save the size of the image as variables

Post by LeyreM »

It worked, thank you very much!!!!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Save the size of the image as variables

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Save the size of the image as variables

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Save the size of the image as variables

Post by anthony »

Applogies.

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

Or more specifically What is the final objective!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
LeyreM

Re: Save the size of the image as variables

Post 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!!
Post Reply