function image_gd_imagecache_autorotate in ImageCache Actions 8
Same name and namespace in other branches
- 7 autorotate/imagecache_autorotate.module \image_gd_imagecache_autorotate()
GD toolkit specific implementation of this image effect.
Parameters
stdClass $image:
Return value
bool true on success, false otherwise.
File
- autorotate/
imagecache_autorotate.module, line 127 - Autorotate image based on EXIF Orientation tag.
Code
function image_gd_imagecache_autorotate(stdClass $image) {
if (!function_exists('exif_read_data')) {
watchdog('imagecache_actions', 'Image %file could not be auto-rotated: !message', array(
'%file' => $image->source,
'!message' => t('The exif_read_data() function is not available in this PHP installation. You probably have to enable the exif extension.'),
));
return FALSE;
}
$exif = exif_read_data(drupal_realpath($image->source));
if (isset($exif['Orientation'])) {
// http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html:
// 1 = Horizontal (normal)
// 2 = Mirror horizontal
// 3 = Rotate 180
// 4 = Mirror vertical
// 5 = Mirror horizontal and rotate 270 CW
// 6 = Rotate 90 CW
// 7 = Mirror horizontal and rotate 90 CW
// 8 = Rotate 270 CW
// @todo: Add horizontal and vertical flips etc.
// imagecopy seems to be able to mirror, see conmments on
// http://php.net/manual/en/function.imagecopy.php
// @todo: Create sample set for tests.
switch ($exif['Orientation']) {
case 3:
$degrees = 180;
break;
case 6:
$degrees = 90;
break;
case 8:
$degrees = 270;
break;
default:
$degrees = 0;
}
if ($degrees != 0) {
return image_rotate($image, $degrees);
}
}
return TRUE;
}