Some images rotate, why?

Phoca Gallery - image gallery extension
websperations
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 21 Oct 2014, 01:13

Some images rotate, why?

Post by websperations »

My original image is portrait and all of the thumbnails except 2 are being rotated to landscape.

Why is this. I have read well over 10 forum topics on can't seem to get answer or solution as to what's going on. We are cropping images to keep the thumbs looking clean.

How can I make it so that the cropped image stay the same orientation as the original image.

Image
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47887
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Some images rotate, why?

Post by Jan »

Hi, when e.g. the cropping is set to 500x500 and you have the portrait image it will be cut to 500x500 (means no more portrait), so it depends on how you set the large of the thumbnail in parameters.

Jan
If you find Phoca extensions useful, please support the project
websperations
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 21 Oct 2014, 01:13

Re: Some images rotate, why?

Post by websperations »

I am aware that when I set it to crop to 500px x 500px that it will crop my image to this size.

That is not he problem here. The problem is that your software is rotating the image and then cropping it.

You can clearly see from my image attachment that my original image has the sunset at the bottom, on the re-sized images, the sunset is on the left.

How do I stop Phoca from rotating my images?
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47887
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Some images rotate, why?

Post by Jan »

Hi,

1) Phoca does not create thumbnails - they are created by GD library which is a part of PHP on your server
2) There is a rotate function but it works only when "Rotate" button is called. Normally there is no function to rotate images when making thumbnails as there is no sense or reason to do :idea:

So try to check if anyone on the server didn't rotate the images manually or if they were not uploaded as rotated (as it is really unlikely that sofware which works over 8 years on thousands of servers will begin to rotate images when thumbnails are craeting :idea: :idea: )

Really no idea what could cuased it :idea:

Jan
If you find Phoca extensions useful, please support the project
htspro
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 21 Jul 2015, 20:05

Re: Some images rotate, why?

Post by htspro »

So try to check if anyone on the server didn't rotate the images manually or if they were not uploaded as rotated (as it is really unlikely that sofware which works over 8 years on thousands of servers will begin to rotate images when thumbnails are craeting :idea: :idea: )
While I agree that it is not likely that this is a new problem with your software, I am having the same issue. I uploaded images, that I validated were not rotated prior to upload. When the thumbnails generate, some of them are rotated, some one rotation, some completely upside-down. I fix them through the control panel, but whenever I hit "regenerate thumbnails" the images rotate again. This is very frustrating and my customer is expressing that towards me as his website is showing images inappropriately.

I have validated that no one else rotated the images, as I am the only one with access to the server. And, it happens immediately after I generate the thumbnails.

What can be done to troubleshoot this issue before I have to switch to another gallery?

You can see the rotation on the mosaics here: http://www.nationshomeremodelers.net/galleries
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47887
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Some images rotate, why?

Post by Jan »

Hi, are you sure the original image are not rotated, sometimes - in some OS it can happen, that you rotate the image, it is displayed as rotated, but the original image stays unchanged.

Which version of Phoca Gallery you are using? Did someone do some hack to it? Where did you download it? The thumbnails generation is working unchanged over 8 years and I didn't hear any similar problem in history, even looking at the code and see no rotate function (except the rotate when rotate is clicked) in thumbnail generation feature. And don't understand why there will be one - why to do useless function, it is waste of time :-(

I am checking your site and see that some thumbnails are created correctly and some not. But they always has only one script, example:

you have one original image and you want to create three thumbnails - in code, you don't make three different functions for each thumbnails (small, large, medium), you do only one function and the only one what is changing is the size - so this does not make any sense. If one thumbnails is created right, then all other must be created to, because they use the same function and there is no rotate function for creating thumbnails - the rotate feature is stored in other part of the system. So unfortunately, I cannot imagine what happened there. Only what I know, it does not make sense as if one thumbnail is created right with the function, another must be created the same way - this is system. It is like as if the dog gave birth to five puppies and one cat (I hope you understand what I mean, it is ilogical the same way like the server will produce all thumbnails OK and one roated :idea: )

Only to be sure, were the additional thumbnails generated the same time like standard thumbnails?

I am testing it now, seeing the code and really don't know, there is no feature to rotate the images so really don't know which way this can happen :-( :idea:

Jan
If you find Phoca extensions useful, please support the project
htspro
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 21 Jul 2015, 20:05

Re: Some images rotate, why?

Post by htspro »

Hi Jan.

Thank you for taking the time to look. I am certain that the original images are not rotated. You application was not modified by me and there is no one else that works on this site.

I understand programming logic and I agree that it does not make sense that some are rotated and some are not. I only noticed this happen after I decided to implement the mosaic option on the category view.

Here is another site: http://www.hitechsolutions.pro/sites/de ... ery-test-1

The "test-1" and "test-2" galleries are new (different product) and they both contain the same original files as used on phoca. So, you can see "unrotated" images here.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47887
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Some images rotate, why?

Post by Jan »

Hi, yes, I saw it in the code, only additional images are rotated. So the only idea is the were created additionally and the original was rotated. I know, you wrote the original was not rotated. I have tested all different combinations and the only one is:

- I have uploaded the original file - thumbnails were created normally
- then I have rotated the original file (not in Phoca Gallery, on my PC, because Phoca Gallery does not manage original files) - uploaded again
- and then I have made additional thumbnails - there were rotated because original was rotated.

In other tests I didn't get such behavior, everything was working OK as it should (when thumbnails are made, there is no rotate function)

So, Yes, I believe, nobody will delete the original image then change it to one rotated. Why?

I have searched in internet and didn't find any similar case regarding GD library (GD library is a part of PHP on server which creates the thumbnails)

So for now I really cannot say what was wrong there. The only what I can say is, Phoca Gallery does not have any rotate function for creating thumbnails (as this will be additional function without any sense - why to do it when it is not used in creation of thumbnails) :idea:

I have checked the rotate function in Phoca Gallery and it is just called only when the rotate button is clicked (if not then all thumbnails in all Phoca Galleries over the world would be rotated when creating thumbnails)

So for now, after many tests, I really finished with my thoughts about how this could happen :idea: :-(

Jan
If you find Phoca extensions useful, please support the project
andrew1879
Phoca Newbie
Phoca Newbie
Posts: 1
Joined: 30 Mar 2016, 02:40

Re: Some images rotate, why?

Post by andrew1879 »

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;
					}
				}	
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47887
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Some images rotate, why?

Post by Jan »

Hi, thank you for the guide, I will take a look at it.

Rotate function you can find here:
administrator\components\com_phocagallery\libraries\phocagallery\image\imagerotate.php

Jan
If you find Phoca extensions useful, please support the project
Post Reply