To identify format and characteristics of image file you need to use command called identify.
It will also report if an image is incomplete or corrupt. The information displayed includes the scene number, the file name, the width and height of the image, whether the image is colormapped or not, the number of colors in the image, the number of bytes in the image, the format of the image (JPEG, PNM, etc.), and finally the number of seconds it took to read and process the image
If you are looking to provide scripting solution to automate task then this command is the best one.
$ identify -verbose snap-S25-20060218-235000-1.ppm | less
Image: snap-S25-20060218-235000-1.ppm Format: PNM (Portable anymap) Geometry: 768x576 Class: DirectClass Colorspace: RGB Type: TrueColor Depth: 8 bits Endianess: Undefined Channel depth: Red: 8-bits Green: 8-bits Blue: 8-bits Channel statistics: Red: Min: 0 Max: 255 Mean: 87.5478 Standard deviation: 89.9707 Green: Min: 0 Max: 255 Mean: 73.0576 Standard deviation: 84.7219 Blue: Min: 0 Max: 255 Mean: 53.6681 Standard deviation: 73.7701 Colors: 163423 Rendering-intent: Undefined Resolution: 72x72 Units: Undefined Filesize: 1.3mb Interlace: None Background Color: grey100 Border Color: #DFDFDF Matte Color: grey74 Dispose: Undefined Iterations: 0 Compression: Undefined Orientation: Undefined signature: ad1ac5b547203e393117aab Tainted: False User Time: 0.020u Elapsed Time: 0:01