Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick to verify image integrity

I'm using ImageMagick (with Wand in Python) to convert images and to get thumbnails from them. However, I noticed that I need to verify whether a file is an image or not ahead of time. Should I do this with Identify?

So I would assume checking the integrity of a file needs the whole file to be read into memory. Is is better to try and convert the file and if there was an error, then we know the file wasn't good.

like image 570
Kiarash Avatar asked Jul 19 '13 23:07

Kiarash


1 Answers

seems like you answered your own question

$ ls -l *.png
-rw-r--r-- 1 jsp jsp 526254 Jul 20 12:10 image.png
-rw-r--r-- 1 jsp jsp  10000 Jul 20 12:12 image_with_error.png
$ identify image.png &> /dev/null; echo $?
0
$ identify image_with_error.png &> /dev/null; echo $?
0
$ convert image.png /dev/null &> /dev/null ; echo $?
0
$ convert image_with_error.png /dev/null &> /dev/null ; echo $?
1
like image 56
jsp Avatar answered Sep 22 '22 18:09

jsp