How machine detects corrupted image automatically??

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
pkashrai

How machine detects corrupted image automatically??

Post by pkashrai »

When I wanted to identify corrupted image, using command line:

Code: Select all

identify -verbose corrupt.jpg
the program ends with the last messages
identify: Premature end of JPEG file 'corrupt.jpg'.
identify: Corrupt JPEG data: premature end of data segment 'corrupt.jpg'.

As I think, this gives the image is corrupted to the viewer.But now I wanted the machine to detect the corrupted image automatically as soon as the image is downloaded(e-mail attachments). What should I do? Is there any commands so that the machine detects the corrupted image? Please help!!


With Regards
Prakash Rai
shakyamanoj

Re: How machine detects corrupted image automatically??

Post by shakyamanoj »

I also have the same problem.
I issued the command as follows:

Code: Select all

identify -verbose corrupt.jpg >log.txt 2>&1
and I got the log.txt file. But I don't see any EXIT_STATUS there. I am sure that corrupt.jpg file is a corrupted file. How do I know now that the image is corrupted?


/*********************************************************/
This is the log.txt file.
------------------------

corrupt.jpg JPEG 406x491 DirectClass 67kb
identify: Corrupt JPEG data: premature end of data segment `corrupt.jpg'.
Image: corrupt.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Geometry: 406x491
Class: DirectClass
Type: TrueColor
Endianess: Undefined
Colorspace: RGB
Channel depth:
Red: 8-bits
Green: 8-bits
Blue: 8-bits
Channel statistics:
Red:
Min: 0 (0)
Max: 255 (1)
Mean: 172.474 (0.676368)
Standard deviation: 46.0133 (0.180444)
Green:
Min: 0 (0)
Max: 240 (0.941176)
Mean: 126.445 (0.495864)
Standard deviation: 38.8062 (0.152181)
Blue:
Min: 0 (0)
Max: 252 (0.988235)
Mean: 117.174 (0.459504)
Standard deviation: 38.1617 (0.149654)
Colors: 40905
Rendering-intent: Undefined
Resolution: 100x100
Units: PixelsPerInch
Filesize: 67kb
Interlace: None
Background Color: white
Border Color: #DFDFDF
Matte Color: grey74
Dispose: Undefined
Iterations: 0
Compression: JPEG
Quality: 90
Orientation: Undefined
JPEG-Colorspace: 2
JPEG-Sampling-factors: 2x2,1x1,1x1
Signature: d2836de2bccacd9b46d2a3954d4405ef974ae03a8612cac29103dfe8fb6d8f72
Tainted: False
Version: ImageMagick 6.2.3 09/13/05 Q16 http://www.imagemagick.org

/*********************************************************/


Thanks.


Regards,
Manoj Shakya
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How machine detects corrupted image automatically??

Post by anthony »

An exit status is a number the program returns whci hit is finished. Normally it is '0' for okay, or some other value for different error conditions. Shells use it for 'if' statements.

You can see it by looking at the status result of the previosu command in the calling shell.

Code: Select all

  identify file >/dev/null
  echo $?
Or you can us an IF statement in the shell (bash or bourne shell here)

Code: Select all

   if  identify file >/dev/null; then
     echo "the image is good"
   else
      echo "the image is corrupt or known format"
   fi
non of this is ImageMagcik however, but calling shell or language dependant
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
shakyamanoj

Re: How machine detects corrupted image automatically??

Post by shakyamanoj »

Thanks for your response...But still could not able to get the status 1. Can you please try this with the following image? The link for the image is.
http://www.imageboo.com/images/551933corrupt.jpg

Regards,
Manoj Shakya.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How machine detects corrupted image automatically??

Post by anthony »

Using BASH...

Code: Select all

identify http://www.imageboo.com/images/551933corrupt.jpg
echo $?
The result was 0, whcih is obviously WRONG....

However, Some output appeared on the STDERR so that could be used as a temporary indicator until this status return is fixed.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How machine detects corrupted image automatically??

Post by magick »

Add -regard-warnings to the command line.
shakyamanoj

Re: How machine detects corrupted image automatically??

Post by shakyamanoj »

Thanks a lot. It worked.

regards,
Manoj Shakya.
Post Reply