LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-09-2009, 12:57 PM   #1
KDHofAvalon
Member
 
Registered: Apr 2007
Location: Kansas
Distribution: Slackware
Posts: 47

Rep: Reputation: 27
Program to determine if a file is a valid image (jpg, png, gif, etc.)


As the title says, I'm looking for a program that will go through all images in a directory tree and determine if they're valid, if they've been corrupted, and (wishful thinking) if they have the wrong extension. Does anything like that exist?

Last edited by KDHofAvalon; 06-09-2009 at 01:01 PM.
 
Old 06-09-2009, 01:07 PM   #2
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS6
Posts: 267

Rep: Reputation: 57
The "file" program inspects the file contents and determines the format using a variety of tests. I've found it quite accurate in its determinations. See "man file"

Last edited by david1941; 06-09-2009 at 01:08 PM. Reason: spelling
 
Old 06-09-2009, 01:17 PM   #3
harsshal
Member
 
Registered: Jul 2006
Location: New York, NY
Distribution: redhat,ubuntu,RHEL,fedora,centOS
Posts: 105

Rep: Reputation: 15
You can Google for "file type detection". Plenty of them out there. And its not that hard to create one by yourself. Look at http://en.wikipedia.org/wiki/Magic_number_(programming)
 
Old 06-09-2009, 01:46 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,040

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
The identify tool from imagemagick can tell you if the file is an image or not:

Code:
$ identify jesusBrbLol.jpg && echo "Tis an image file" || echo "This is not"
jesusBrbLol.jpg JPEG 676x828 676x828+0+0 8-bit DirectClass 216kb 
Tis an image file
$ identify keysymdef.h && echo "Tis an image file" || echo "This is not"
identify: unrecognized image format `keysymdef.h' @ magick.c/ReadMAGICKImage/5571.
This is not
Checking the integrity of a file is another matter, all these tools check, as far as I know, is the header of the file.
 
Old 06-09-2009, 01:49 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by i92guboj View Post
Checking the integrity of a file is another matter, all these tools check, as far as I know, is the header of the file.
And there's the real issue.....

It would be trivial to modify the header to say that the file is a particular image type. That is no guarantee that the actual data is valid.

Tell us more about the context of the question....
 
Old 06-09-2009, 03:20 PM   #6
KDHofAvalon
Member
 
Registered: Apr 2007
Location: Kansas
Distribution: Slackware
Posts: 47

Original Poster
Rep: Reputation: 27
Thanks for the replies.

As for why, I just recovered photos for a friend who accidentally formatted his hard drive and he want's me to delete photos that couldn't be fully recovered. There are over 10,000 so I'd really rather not go through them by hand.
 
Old 06-09-2009, 03:48 PM   #7
farslayer
Guru
 
Registered: Oct 2005
Location: Willoughby, Ohio
Distribution: linuxdebian
Posts: 7,228
Blog Entries: 5

Rep: Reputation: 189Reputation: 189
Filter 10,000 images for him.. he must be paying you very well, or a really really good friend.

not sure if you used photorec to recover the images, but their "What next After Recovery" page might be of assistance.
http://www.cgsecurity.org/wiki/After_Using_PhotoRec
 
Old 06-09-2009, 04:54 PM   #8
KDHofAvalon
Member
 
Registered: Apr 2007
Location: Kansas
Distribution: Slackware
Posts: 47

Original Poster
Rep: Reputation: 27
Thanks farslayer, that link had what I needed. Well sort of. It gave me an idea that works anyway.

Last edited by KDHofAvalon; 06-09-2009 at 04:58 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Help with sockets to download image files (JPG, GIF) in C/C++ pedropolian Programming 3 08-11-2012 11:21 AM
gnuplot 4.2 no png, jpg or gif terminals datasink Programming 4 04-26-2007 10:13 AM
What can plotting Lat, Long on a map. (in gif, png or jpg) MikeyCarter Linux - Software 2 03-09-2007 02:07 PM
convert image.png image.jpg changing colours MikeyCarter Linux - Software 1 11-17-2006 10:16 AM
CMD line tool for PDF -> HTML or JPG/PNG/GIF ilhbutshm Linux - Software 5 10-23-2004 04:18 AM


All times are GMT -5. The time now is 04:36 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration