LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2022, 10:57 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
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.
 
Old 08-24-2022, 11:09 PM   #2
EdGr
Member
 
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 998

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
ImageMagick's "identify" command does exactly that.

If you need a library, gdk-pixbuf loads many image formats.
Ed
 
1 members found this post helpful.
Old 08-25-2022, 03:21 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,927

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
we have very good search engines to find answers to questions like this.
for example: https://unix.stackexchange.com/quest...ze-of-an-image
 
1 members found this post helpful.
Old 08-25-2022, 06:29 AM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
i like using Cimg.h over imagemagick
https://cimg.eu/
or
https://github.com/GreycLab/CImg
 
1 members found this post helpful.
Old 08-25-2022, 07:00 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,743

Rep: Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923
There is also exiftool.

Typically the utilities use the file's magic number to determine image type and not the filename.
 
2 members found this post helpful.
Old 08-25-2022, 07:06 AM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

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.

 
1 members found this post helpful.
Old 08-25-2022, 08:42 AM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,238

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
You use “identify” from ImageMagick.
 
1 members found this post helpful.
Old 08-25-2022, 08:49 AM   #8
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,141
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
Plain old file will do that.
 
2 members found this post helpful.
Old 08-25-2022, 06:08 PM   #9
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by boughtonp View Post
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".
 
Old 08-25-2022, 06:12 PM   #10
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by michaelk View Post
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.
 
Old 08-26-2022, 01:21 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,927

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
Quote:
Originally Posted by Skaperen View Post
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.
 
Old 08-26-2022, 07:46 AM   #12
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
Quote:
Originally Posted by Skaperen View Post
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.

 
Old 08-28-2022, 07:50 PM   #13
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by pan64 View Post
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.
 
Old 08-28-2022, 07:58 PM   #14
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by Skaperen View Post
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.
 
Old 08-28-2022, 08:03 PM   #15
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by boughtonp View Post
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 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Get width/height of a terminal window in c++? rohedin Programming 9 10-24-2012 07:00 PM
Use awk and sed to extract height and width of file toben Programming 6 08-04-2010 06:16 AM
imagemagick problem: height-and-width not deterministic when I crop an png file. centguy Linux - Software 2 09-09-2009 05:31 AM
Reduce width and height of gdmgreeter and Xfce desktop lothario Linux - Software 5 06-02-2006 02:27 PM
Laptop Screen Height and Width blueStatic Linux - Hardware 1 09-03-2003 12:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration