Get Image width and height without loading pixels on Windows 10

Was hoping someone could help me getting the width and height of an image from disk without loading the pixels of the image on Windows 10.
On OSX, this works for me:

string outs = ofSystem( "sips -g all "+tfile+" | grep 'pixelWidth' " );
    std::size_t pos = outs.find(":");
    if( pos != string::npos ) {
        if( pos+1 < outs.length()-1 ) {
            outs = outs.substr(pos+1, string::npos);
    return ofToInt(outs);

I would prefer not to use any third party libs that need to be installed if possible.
Any help is much appreciated.

Hi. Try this:

ofxIO has a function to read header info (e.g. width / height / bits per pixel). It uses FreeImage which is part of OF.

If you don’t want to use the whole library, you could just use the code

Thank you @Dorald + @bakercp !
I was looking into FreeImage but couldn’t figure out how to only load the pixels. The ImageUtils::loadHeader function is perfect. :slight_smile:

1 Like