Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get dimensions of JPEG in C++

Tags:

c++

jpeg

openvms

I need to get the image dimensions of a JPEG in C++. I'm looking for either a fairly simple way to do it or a smallish library that provides that functionality. I'm working in C++ on OpenVMS, so any external libraries may have to be adapted to compile on our systems - so please don't post me links to big, closed source libraries!

Has anyone come across anything that might do the trick, or understand the JPEG file format (I think I probably mean the JFIF file format here) to tell me how I might go about rolling my own solution?

like image 498
Dominic Rodger Avatar asked Nov 25 '08 12:11

Dominic Rodger


People also ask

What is getimagesize?

The getimagesize() function will determine the size of any supported given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondent HTTP content type.

How to get image size using php?

The getimagesize() function in PHP is an inbuilt function which is used to get the size of an image. This function accepts the filename as a parameter and determines the image size and returns the dimensions with the file type and height/width of image.


2 Answers

You have this C function which may extract the relevant data for you.

This is a C routine but should compile fine with C++.
Pass it a normal FILE pointer (from fopen) to the beginning of a jpeg file and two int pointers to be set with the image height and width.

Or you may find in the Boost library a jpeg class which has the right function (From Adobe Generic Image Library).

jpeg_read_dimensions

boost::gil::jpeg_read_dimensions (const char *filename)

Returns the width and height of the JPEG file at the specified location. Throws std::ios_base::failure if the location does not correspond to a valid JPEG file.

like image 161
VonC Avatar answered Nov 15 '22 04:11

VonC


libjpeg is reasonably small, open source and available on OpenVMS. It's probably quicker to install it than to handle JPEG yourself.

like image 31
Julien Oster Avatar answered Nov 15 '22 05:11

Julien Oster