Hi all,
I just finished migrating from Gallery 2 to Phoca Gallery. I also encountered this problem of thumbnails of some portrait images being rotated 90 degrees.
I have an answer: it's due to Phoca Gallery not respecting the EXIF Orientation data, which is set by many cameras when the photo is taken, when Phoca resizes an image to create a thumbnail. The GD library used by Phoca does not look at the EXIF data and it also strips the EXIF data so that it cannot be used to display the image oriented correctly in the viewing application.
When looking for a solution I saw that it has been raised by other users previously:
phoca. cz/ forum/ viewtopic.php?f=1&t=25259
phoca. cz/ forum/ viewtopic.php?f=1&t=6367
phoca. cz/ forum/ viewtopic.php?f=1&t=24707
phoca. cz/ forum/ viewtopic.php?f=1&t=4752
phoca. cz/ forum/ viewtopic.php?f=1&t=29236
phoca. uservoice. com /forums /12720-phoca-gallery /suggestions /290153-rotate-automatically-based-on-exif-orientation
For me, it's important than normal users should be able to upload any photo without having to edit it first.
I have developed a solution that I hope can be incorporated into future releases of Phoca Gallery. It is based on information found at:
stackoverflow .com/ questions /7489742 /php-read-exif-data-and-adjust-orientation
and user comment at php. net /manual/ en/ function.exif-read-data.php by chadsmith729 at gmail dot com
It works for me but I'm not much of a programmer so please review for any problems.
As an aside, I don't see any "Rotate image" function in the Phoca Gallery backend, although it is present in the code. Has it been removed?
In the following file:
administrator/components/com_phocagallery/libraries/phocagallery/image/imagemagic.php
Change:
Code: Select all
list($w, $h, $type) = GetImageSize($fileIn);
to:
Code: Select all
// Read EXIF data from image file to get the Orientation flag
$exif = exif_read_data($fileIn);
// GetImageSize returns an array of width, height, IMAGETYPE, "height=x width=x" (string)
// The EXIF Orientation flag is examined to determine if width and height need to be swapped, i.e. if the image will be rotated in a subsequent step
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8: // will need to be rotated 90 degrees left, so swap order of width and height
list($h, $w, $type) = GetImageSize($fileIn);
break;
case 3: // will need to be rotated 180 degrees so don't swap order of width and height
list($w, $h, $type) = GetImageSize($fileIn);
break;
case 6: // will need to be rotated 90 degrees right, so swap order of width and height
list($h, $w, $type) = GetImageSize($fileIn);
break;
}
} else {
// No EXIF orientation data, so don't swap order of width and height
list($w, $h, $type) = GetImageSize($fileIn);
}
And above the existing line:
Code: Select all
ImageCopyResampled($image2, $image1, $dst[0],$dst[1], $src[0],$src[1], $dst[2],$dst[3], $src[2],$src[3]);
insert the following:
Code: Select all
// Examine the EXIF Orientation flag (read earlier) to determine if the image needs to be rotated prior to the ImageCopyResampled call
// Use the imagerotate() function to perform the rotation, if required
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image1 = imagerotate($image1,90,0);
break;
case 3:
$image1 = imagerotate($image1,180,0);
break;
case 6:
$image1 = imagerotate($image1,-90,0);
break;
}
}