Imagick provides various ways to identify image properties. These properties include for example some basic attributes like width, height, format and some more advanced attributes like exif tags, profiles and colorspaces.
This example will demonstrate a few basic ways to read these attributes from an image. The image used in this example is from www.exif.org and can be found here http://exif.org/samples/fujifilm-dx10.jpg.
The support for getImageProperties and getImageProfiles was added in ImageMagick version 6.3.5-9 and Imagick version 2.0.0RC4.
-
<?php
-
-
$im = new Imagick( "fujifilm-dx10.jpg" );
-
$identify = $im->identifyImage();
-
-
/* Ouput some basic attributes */
-
echo '<b>Basic image properties:</b> <br />';
-
echo 'Image geometry: ' , $identify['geometry']['width'] , 'x' , $identify['geometry']['height'] , '<br />';
-
-
echo '<br /><br />';
-
-
echo '<b>All image properties:</b> <br />';
-
-
/* Loop trough image properties */
-
foreach ( $im->getImageProperties() as $k => $v )
-
{
-
}
-
-
echo '<br /><br />';
-
-
echo '<b>All image profiles:</b> <br />';
-
/* Same goes for properties */
-
foreach ( $im->getImageProfiles() as $k => $v )
-
{
-
}
-
-
?>
The output looks something like this:
Basic image properties:
Image geometry: 1024x768
Image format: JPEG (Joint Photographic Experts Group JFIF format)
Image type: TrueColor
Image compression: JPEG
Image size: 129.955kb
All image properties:
exif:ApertureValue => 41/10
exif:BrightnessValue => -27/10
exif:ColorSpace => 1
exif:ComponentsConfiguration => ...
exif:CompressedBitsPerPixel => 14/10
exif:Compression => 6
exif:Copyright => J P Bowen
exif:DateTime => 2001:04:12 20:33:14
exif:DateTimeDigitized => 2001:04:12 20:33:14
exif:DateTimeOriginal => 2001:04:12 20:33:14
exif:ExifImageLength => 768
exif:ExifImageWidth => 1024
exif:ExifOffset => 258
exif:ExifVersion => 0210
exif:ExposureBiasValue => 0/10
exif:ExposureProgram => 2
exif:FileSource => .
exif:Flash => 1
exif:FlashPixVersion => 0100
exif:FNumber => 42/10
exif:FocalLength => 58/10
exif:FocalPlaneResolutionUnit => 3
exif:FocalPlaneXResolution => 2151/1
exif:FocalPlaneYResolution => 2151/1
exif:InteroperabilityIndex => R98
exif:InteroperabilityOffset => 708
exif:InteroperabilityVersion => 0100
exif:ISOSpeedRatings => 150
exif:JPEGInterchangeFormat => 856
exif:JPEGInterchangeFormatLength => 10274
exif:Make => FUJIFILM
exif:MaxApertureValue => 41/10
exif:MeteringMode => 5
exif:Model => DX-10
exif:Orientation => 1
exif:ResolutionUnit => 2
exif:SceneType => .
exif:SensingMethod => 2
exif:ShutterSpeedValue => 66/10
exif:Software => Digital Camera DX-10 Ver1.00
exif:XResolution => 72/1
exif:YCbCrPositioning => 2
exif:YResolution => 72/1
jpeg:colorspace => 2
jpeg:sampling-factor => 2x1,1x1,1x1
Signature => 434d8554488bf9af5fc551adeba43e6d1d04ac36559a02357cf5df93db4b35c5
All image profiles:
Profile name: exif (size: 11136)
#1 by Anirudh on October 28, 2007 - 8:30 pm
Quote
Imagemagick sounds useful. i can think of checking the avatar sizes would be nice if you’re adding social features.
#2 by Mitron on February 23, 2008 - 10:48 am
Quote
Is it possible yet to add to the image properties with the setImageProperty() function, then do a writeImage() or is it a bit more complicated than that?
I’d like to be able to set the Copyright, Artist, Image Description and User Comment to images before I save them online.
#3 by Mitron on February 24, 2008 - 9:11 am
Quote
Well so far I’ve been able to take a JPEG, set a few image properties and successfully write a PNG file that retains some of the image properties I set, but each time I try to save it as a JPEG, the original image properties seem to overwrite the image properties I set.
I even tried writting to a PNG, then converting it with the new image properties to a JPEG and again the image properties I set are rewritten to the original settings of the first JPEG.
I must be missing a step or something.
#4 by Peter Robinett on April 28, 2008 - 6:04 pm
Quote
Mikko, thanks for the very useful documentation to imagick! Is there a simple function to get an image’s mime-type? identifyImage() gives ‘JPEG (Joint Photographic Experts Group JFIF format)’ and getImageFormat() gives me ‘JPEG’; I want ‘image/jpeg’.
#5 by Nick E on May 12, 2008 - 7:38 pm
Quote
Peter: Try getFormat();
#6 by dvd to avi on August 12, 2010 - 4:24 pm
Quote
thanks for analyzing PNG property PHP code . I was searching for this and found on your blog!! Exactly what I needed to know! Thank you!!!!!!