LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   get width and height of an image file (https://www.linuxquestions.org/questions/programming-9/get-width-and-height-of-an-image-file-4175716048/)

Skaperen 08-24-2022 10:57 PM

get width and height of an image file
 
i am looking for a tool to get the width and height of an image file that is formatted in any of the major image formats like: bmp, gif, jpg, png, and more, even if the extension of the file name is wrong (for example a png file named as a gif file). it will need to figure out the format based on file contents.

it's output needs to be basically simple enough for a small shell script to parse it. output that is just the 2 numbers would be good.

EdGr 08-24-2022 11:09 PM

ImageMagick's "identify" command does exactly that.

If you need a library, gdk-pixbuf loads many image formats.
Ed

pan64 08-25-2022 03:21 AM

we have very good search engines to find answers to questions like this.
for example: https://unix.stackexchange.com/quest...ze-of-an-image

John VV 08-25-2022 06:29 AM

i like using Cimg.h over imagemagick
https://cimg.eu/
or
https://github.com/GreycLab/CImg

michaelk 08-25-2022 07:00 AM

There is also exiftool.

Typically the utilities use the file's magic number to determine image type and not the filename.

boughtonp 08-25-2022 07:06 AM


 
If you bothered to search, you should state what search terms you used, and what's wrong with the results you received.

This does several things:
1) it would demonstrate that you're not just being lazy.
2) it helps the next person using those same search terms to find an answer.
3) it allows responders to provide useful advice instead of repeating what you've already dismissed.


dugan 08-25-2022 08:42 AM

You use “identify” from ImageMagick.

teckk 08-25-2022 08:49 AM

Plain old file will do that.

Skaperen 08-25-2022 06:08 PM

Quote:

Originally Posted by boughtonp (Post 6376006)
If you bothered to search, you should state what search terms you used, and what's wrong with the results you received.

This does several things:
1) it would demonstrate that you're not just being lazy.
2) it helps the next person using those same search terms to find an answer.
3) it allows responders to provide useful advice instead of repeating what you've already dismissed.


i did not bother to search because i am unaware of a search engine capable of understanding a search expression like "...that produces easy to parse output".

Skaperen 08-25-2022 06:12 PM

Quote:

Originally Posted by michaelk (Post 6376005)
There is also exiftool.

it looks like exiftool (had to install it on my Xubuntu 20.4 x86) has the best output for many items of meta data.

pan64 08-26-2022 01:21 AM

Quote:

Originally Posted by Skaperen (Post 6376124)
i did not bother to search because i am unaware of a search engine capable of understanding a search expression like "...that produces easy to parse output".

And there is no one who knows what you mean by that.

boughtonp 08-26-2022 07:46 AM

Quote:

Originally Posted by Skaperen (Post 6376124)
i did not bother to search because i am unaware of a search engine capable of understanding a search expression like "...that produces easy to parse output".

That's a lame excuse. Prefix your search with "bash script" and the results will be something that is easy to parse.


Better yet, search for what you're trying to do with that information, and there's a fair chance someone has already done it and may have released the results.


Skaperen 08-28-2022 07:50 PM

Quote:

Originally Posted by pan64 (Post 6376185)
And there is no one who knows what you mean by that.

probably not. but maybe with an exchange of questions and answers, we can work that out. i wonder how well search engines will do that in 50 years. i wonder if the search engines, then, will know what i mean by that or will they also need to ask me.

Turbocapitalist 08-28-2022 07:58 PM

Quote:

Originally Posted by Skaperen (Post 6376126)
it looks like exiftool (had to install it on my Xubuntu 20.4 x86) has the best output for many items of meta data.

Several scripting and other languages have APIs for working with EXIF data, for more flexibility. For example, there are Image::EXIFTool in Perl and the exif module for Python3.

Skaperen 08-28-2022 08:03 PM

Quote:

Originally Posted by boughtonp (Post 6376237)
That's a lame excuse. Prefix your search with "bash script" and the results will be something that is easy to parse.

i get results like this:

Bash Scripting - Bash Echo Command - GeeksforGeeks

Quote:

Originally Posted by boughtonp (Post 6376237)
Better yet, search for what you're trying to do with that information, and there's a fair chance someone has already done it and may have released the results.


it's a local task, so no one would has done it. the information is simple, but a search didn't do as well as this thread. michaelk's answer worked best.


All times are GMT -5. The time now is 11:05 PM.