The Rendering Intent variable exists in ImageMagick to provide support for ICC Color Profiles. There are five results that one can expect to get from the getRenderingIntent function, which are the predefined constants for Rendering Intent within ImageMagick. These values look like "imagick::RENDERINGINTENT_UNDEFINED", with "_VALUE" values of: undefined, saturation, perceptual, absolute, and relative. Printed out, Undefined is 0, Saturation is 1, Perceptual is 2, Absolute is 3, and Relative is 4.
The official ImageMagick documentation provides good light on what these values indicate. ( http://www.imagemagick.org/RMagick/doc/constants.html#RenderingIntent ) Undefined means "no intent," Saturation means "A rendering intent that specifies the saturation of the pixels in the image is preserved perhaps at the expense of accuracy in hue and lightness," Perceptual Intent means "A rendering intent that specifies the full gamut of the image is compressed or expanded to fill the gamut of the destination device. Gray balance is preserved but colorimetric accuracy might not be preserved," Absolute Intent means "Absolute colorimetric," and Relative Intent means "Relative colorimetric."
Every time I ran this function, it always produced the same result: #2, indicating Perceptual Intent. But this makes sense, since the ImageMagick documentation notes about the Rendering Intent, "Typically, the user or application will set the rendering intent dynamically at runtime or embedding time." The ImageMagick documentation also recommended the following link to better understand Rendering Intent in terms of Colorspace Profiles: http://www.cambridgeincolour.com/tutorials/color-space-conversion.htm .
Some sample code :
<?php
// Author: holdoffhunger@gmail.com
// Imagick Type
// ---------------------------------------------
$imagick_type = new Imagick();
// Open File
// ---------------------------------------------
$file_to_grab = "image_workshop_directory/test.jpg";
$file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
// Grab File
// ---------------------------------------------
$imagick_type->readImageFile($file_handle_for_viewing_image_file);
// Get Rendering Intent Values
// ---------------------------------------------
$imagick_rendering_intent = $imagick_type->getImageRenderingIntent();
switch($imagick_rendering_intent)
{
case '0':
$image_rendering_intent_evaluated = "Undefined";
break;
case '1':
$image_rendering_intent_evaluated = "Saturation";
break;
case '2':
$image_rendering_intent_evaluated = "Perceptual";
break;
case '3':
$image_rendering_intent_evaluated = "Absolute";
break;
case '4':
$image_rendering_intent_evaluated = "Relative";
break;
}
// Print Rendering Intent Values
// ---------------------------------------------
print("# $imagick_rendering_intent - $image_rendering_intent_evaluated");
?>
Official Function Page: http://www.php.net/manual/en/imagick.getimagerenderingintent.php
// Note: All code appearing on the PHP Revolution blog by the blog owner is released under the Hacktivismo Enhanced-Source Software License Agreement (HESSLA), unless otherwise noted. http://www.hacktivismo.com/about/hessla.php
Open Software Coders of the World, You Have Nothing to Lose but Your Proprietary Chains! (...delivering advice for users of PHP/Linux/Apache)
Monday, July 2, 2012
Sunday, July 1, 2012
Image Orientation in the ImageMagick Package of PHP
Using the getImageOrientation function, you'll get the Orientation value for an image as defined within the EXIF file format. That means you will get back an integer representation one of the Orientation constants for ImageMagick, which looks like " imagick::ORIENTATION_UNDEFINED", with "_VALUE" values of: undefined (0), topleft (1), topright (2), bottomright (3), bottomleft (4), lefttop (5), righttop (6), rightbottom (7), and leftbottom (8). When printed out directly, these predefined constants produce the number in parenthesis. The undefined being set to 0 makes sense, since -- according to Wikipedia -- EXIF allows for eight possible values for an image (and not every image has a set of EXIF properties).
The EXIF Orientation is also called "the Rotation," again, according to Wikipedia: http://en.wikipedia.org/wiki/Exchangeable_image_file_format . What's the point of that? According to the official ImageMagick documentation, it's to rotate a photograph so that it is properly oriented after the shot. This really seems to be a camera thing, since the ImageMagick documentation mentions: "If you pointed your camera almost straight up or down, the EXIF orientation setting may not resolve correctly. The same goes for angled or slanted shots. The orientation (and cameras) just have no senses for these situations." ( http://www.imagemagick.org/Usage/photos/ )
If you're having trouble getting this function to show the value for Image Orientation, then use the function and parameters of getImageProperties('*', FALSE); . This produces an array of all properties associated with an image, and one of them will have the key value of exif:Orientation. If it doesn't, then that means you will be getting back a zero from this function, indicating an "Undefined" orientation.
Some sample code :
<?php
// Author: holdoffhunger@gmail.com
// Imagick Type
// ---------------------------------------------
$imagick_type = new Imagick();
// Open File
// ---------------------------------------------
$file_to_grab = "image_workshop_directory/test.jpg";
$file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
// Grab File
// ---------------------------------------------
$imagick_type->readImageFile($file_handle_for_viewing_image_file);
// Get Orientation Values
// ---------------------------------------------
$imagick_orientation = $imagick_type->getImageOrientation();
switch($imagick_orientation)
{
case '0':
$imagick_orientation_evaluated = "Undefined";
break;
case '1':
$imagick_orientation_evaluated = "Top-Left";
break;
case '2':
$imagick_orientation_evaluated = "Top-Right";
break;
case '3':
$imagick_orientation_evaluated = "Bottom-Right";
break;
case '4':
$imagick_orientation_evaluated = "Bottom-Left";
break;
case '5':
$imagick_orientation_evaluated = "Left-Top";
break;
case '6':
$imagick_orientation_evaluated = "Right-Top";
break;
case '7':
$imagick_orientation_evaluated = "Right-Bottom";
break;
case '8':
$imagick_orientation_evaluated = "Left-Bottom";
break;
}
// Print Orientation Values
// ---------------------------------------------
print("# $imagick_orientation - $imagick_orientation_evaluated");
?>
Official Function Page: http://www.php.net/manual/en/imagick.getimageorientation.php
// Note: All code appearing on the PHP Revolution blog by the blog owner is released under the Hacktivismo Enhanced-Source Software License Agreement (HESSLA), unless otherwise noted. http://www.hacktivismo.com/about/hessla.php
The EXIF Orientation is also called "the Rotation," again, according to Wikipedia: http://en.wikipedia.org/wiki/Exchangeable_image_file_format . What's the point of that? According to the official ImageMagick documentation, it's to rotate a photograph so that it is properly oriented after the shot. This really seems to be a camera thing, since the ImageMagick documentation mentions: "If you pointed your camera almost straight up or down, the EXIF orientation setting may not resolve correctly. The same goes for angled or slanted shots. The orientation (and cameras) just have no senses for these situations." ( http://www.imagemagick.org/Usage/photos/ )
If you're having trouble getting this function to show the value for Image Orientation, then use the function and parameters of getImageProperties('*', FALSE); . This produces an array of all properties associated with an image, and one of them will have the key value of exif:Orientation. If it doesn't, then that means you will be getting back a zero from this function, indicating an "Undefined" orientation.
Some sample code :
<?php
// Author: holdoffhunger@gmail.com
// Imagick Type
// ---------------------------------------------
$imagick_type = new Imagick();
// Open File
// ---------------------------------------------
$file_to_grab = "image_workshop_directory/test.jpg";
$file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
// Grab File
// ---------------------------------------------
$imagick_type->readImageFile($file_handle_for_viewing_image_file);
// Get Orientation Values
// ---------------------------------------------
$imagick_orientation = $imagick_type->getImageOrientation();
switch($imagick_orientation)
{
case '0':
$imagick_orientation_evaluated = "Undefined";
break;
case '1':
$imagick_orientation_evaluated = "Top-Left";
break;
case '2':
$imagick_orientation_evaluated = "Top-Right";
break;
case '3':
$imagick_orientation_evaluated = "Bottom-Right";
break;
case '4':
$imagick_orientation_evaluated = "Bottom-Left";
break;
case '5':
$imagick_orientation_evaluated = "Left-Top";
break;
case '6':
$imagick_orientation_evaluated = "Right-Top";
break;
case '7':
$imagick_orientation_evaluated = "Right-Bottom";
break;
case '8':
$imagick_orientation_evaluated = "Left-Bottom";
break;
}
// Print Orientation Values
// ---------------------------------------------
print("# $imagick_orientation - $imagick_orientation_evaluated");
?>
Official Function Page: http://www.php.net/manual/en/imagick.getimageorientation.php
// Note: All code appearing on the PHP Revolution blog by the blog owner is released under the Hacktivismo Enhanced-Source Software License Agreement (HESSLA), unless otherwise noted. http://www.hacktivismo.com/about/hessla.php
Subscribe to:
Posts (Atom)