How to get the dimensions of an image?!

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
jstoezel

How to get the dimensions of an image?!

Post by jstoezel »

Hello,

I would like to get the dimensions of an image (horizontal and vertical pixels). This is what I though would work:

m_Image.read(fileName);
ImageSize_x = m_Image.rows();
ImageSize_y = m_Image.columns();

However, m_Image.rows() always returns a huge number, while m_Image.columns() always returns 0.

Any idea!?

Thanks!
koopa

Re: How to get the dimensions of an image?!

Post by koopa »

Looks right to me, so a fair question. Can we get an fuller example, maybe in the form:

m_Image.read("test.png"); // Portable Network Graphic (non-interlaced)
long ImageSize_x = m_Image.rows(); // should be 300
long ImageSize_y = m_Image.columns(); // should be 200

Is this for every image, or just some?

Shouldn't columns be x (or maybe more clearly width)?

-Chris
jstoezel

Re: How to get the dimensions of an image?!

Post by jstoezel »

koopa wrote:Looks right to me, so a fair question. Can we get an fuller example, maybe in the form:

m_Image.read("test.png"); // Portable Network Graphic (non-interlaced)
long ImageSize_x = m_Image.rows(); // should be 300
long ImageSize_y = m_Image.columns(); // should be 200

Is this for every image, or just some?

Shouldn't columns be x (or maybe more clearly width)?

-Chris
Hi,

I got it to work by using the geometry function:

m_Image.read(fileName);
Geometry mygeo;
mygeo = m_Image.size();
ImageSize_y = mygeo.height();
ImageSize_x = mygeo.width();

I used the exact same image I used with the previous example.
koopa

Re: How to get the dimensions of an image?!

Post by koopa »

If it works more power to you, but I still feel uneasy about it. Unfortunately I don't have any answers to offer.

-Chris
Post Reply