Use mogrify from ImageMagick
$command="mogrify -verbose background\ DodgeThis.jpg"
$output=$command;
$output will hold the info as in the following command line
background DodgeThis.jpg 1024x768 DirectClass 70kb JPEG 0.2u 0:01
background DodgeThis.jpg=>bmagiccoiTRt 1024x768 DirectClass 70kb JPEG 1.0u 0:04
You can then parse any info you want
actual output from shell
[tazman@localhost tazman]$ mogrify -verbose background\ DodgeThis.jpg
background DodgeThis.jpg 1024x768 DirectClass 70kb JPEG 0.2u 0:01
background DodgeThis.jpg=>bmagiccoiTRt 1024x768 DirectClass 70kb JPEG 1.0u 0:04
[tazman@localhost tazman]$
BTW there is also convert. Check out their man pages. I like convert more as it has more features. You can use it to convert to grayscale and B&W.
Saludos
Gerardo