rotate images / attachments

Do not post support requests, bug reports or feature requests. Discuss phpBB here. Non-phpBB related discussion goes in General Discussion!
Get Involved
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: rotate images / attachments

Post by canonknipser »

Let me clarify some points in this discussion:
During upload, phpBB doesn't change any orientation flag on uploaded images, regardless whether plupload is used or the "classic" upload function.
Image manipulation in phpBB happens only on two points:
  1. from 3.0 (and maybe also in the 2.x mod ) attachment thumbnails are generated using the php-standard gd functions or, if properly configured, the imagemagick functions. The original image is never touched by gd or imagemagick.
  2. from 3.1, attachments are upload by default via plupload. plupload resizes images if they have larger dimensions than specified in acp for images. But also here, there is no manipulation of any orientation flag.
The rotating of (Iphone-)images is a browser thing. phpBB sends a naked bytestream to the browser by using the download/file.php script; the browser interprets the orientation flag. If you have a slow internet connection and huge image, you can recognize a sudden "flip" when the browser has finished loading the image.
Thumbnails are imbedded in a html-script via <img>-tag and interpreted different from the browser engine.

Adding a -auto-orient to the imagemagick call only affects the thumbnails.
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
sakm
Registered User
Posts: 713
Joined: Sun Jan 21, 2007 8:14 pm
Location: Hull, uk
Name: Stu
Contact:

Re: rotate images / attachments

Post by sakm »

I have had this problem and it was discussed in this thread

viewtopic.php?f=64&p=14772241

after making the edits suggested in this thread I have not had an issue with wrongly orientated images
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5850
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: rotate images / attachments

Post by thecoalman »

DWFII wrote: Sun Aug 13, 2017 11:32 pm The images appear rotated both at as thumbnails and as full size photos
This issue can crop up for many different reasons, the reason for thumbnails and the ones in lightbox not being rotated correctly are two separate issues.

Second, I understand that Lightbox controls the size of the thumbnails but I am not certain it controls the full size images.
Lightbox does not have anything to do with the thumbnails. The thumbnails are server side issue, when you upload the file to the server the image is resized by the server to produce the thumbnail. phpBB code does not take into account orientation, that information is stripped thus a sideways image.

The full size images...from IPhone...appear no larger (visually) than other images


The full size images in you example are like 4000 pixels wide, you would need a 4K monitor to see all that deatail. When the monitor is smaller the browser on your computer or phone resizes it on the fly and throws away a lot of that information. As I suggested if you go into the attachment settings and set both maximum dimensions to about 2000 you can cut down on the size of the image and the files.

When you set it to 2000 and the user uploads a file it's resized by their computer or phone. The file upload will go much faster, you'll use less disk space and when someone views the full size image it will download a lot faster.

And finally, I don't know what ImageMagick is (I searched for it in the extensions database but no joy.
Imagemagick is a program installed on many servers to manipulate images, it doesn't have anything to do with phpBB. If you go into your attachment settings there is a link you click that will search for it on the server, if it's present it will automatically fill in the correct path and click submit. This by itself will produce no changes.

If you have Imgemagick on your server you need to edit a phpBB file, if you are using Windows you can download Notepad++ here. This is specifically for editing code.

https://notepad-plus-plus.org/download/v7.4.2.html

If you are using Mac soemoenbelse can suggest a good text editor.

On you computer you need open the file from the phpBB package includes/functions_posting and replace line 564 with this.

Code: Select all

@passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -auto-orient -quality 85 -geometry ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" "' . str_replace('\\', '/', $destination) . '"');
Upload the file to your sever overwriting the original. Again this is band aid and I know it's working on my server. Keep in mind when you update phpBB if you overwrite this file with new ones it will revert to the same issue. This will only fix the issue with the thumbnails, it will not help with the lightbox issue.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5850
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: rotate images / attachments

Post by thecoalman »

Here is slightly better solution..

Code: Select all

@passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -auto-orient -quality 85 -resize XXX' . ' "' . str_replace('\\', '/', $source) . '" "' . str_replace('\\', '/', $destination) . '"');
You need to replace XXX with the desired width of the thumbnail.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
DWFII
Registered User
Posts: 386
Joined: Fri Oct 20, 2006 2:17 am
Name: D.W.
Contact:

Re: rotate images / attachments

Post by DWFII »

sakm wrote: Mon Aug 14, 2017 9:45 am I have had this problem and it was discussed in this thread

viewtopic.php?f=64&p=14772241

after making the edits suggested in this thread I have not had an issue with wrongly orientated images
Thank you.

So what did you do about the previously uploaded attachments? did you just leave them rotated?
DWFII
In the High Desert of Central Oregon
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: rotate images / attachments

Post by canonknipser »

No need for that:
thecoalman wrote: Mon Aug 14, 2017 11:45 am ...
You need to replace XXX with the desired width of the thumbnail.
that is be already done in the original command (it's a single config-parm from acp):
There is only one parameter for width and height, it is miswritten in the description and should be read as "maximum thumbnail dimension" or "maximum thumbnail edge length" instead of "width", see https://tracker.phpbb.com/browse/PHPBB3-14758
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5850
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: rotate images / attachments

Post by thecoalman »

canonknipser wrote: Mon Aug 14, 2017 12:52 pm No need for that:
thecoalman wrote: Mon Aug 14, 2017 11:45 am ...
You need to replace XXX with the desired width of the thumbnail.
that is be already done in the original command (it's a single config-parm from acp):
There is only one parameter for width and height, it is miswritten in the description and should be read as "maximum thumbnail dimension" or "maximum thumbnail edge length" instead of "width", see https://tracker.phpbb.com/browse/PHPBB3-14758
My mistake and i believe I hardcoded this into the old 3.0 code too, I want the width of thumbs to be XXXpx regardless of whether they are portraits or landscapes. That is what the second edit I posted will achieve.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5850
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: rotate images / attachments

Post by thecoalman »

DWFII wrote: Mon Aug 14, 2017 12:35 pm Thank you.

So what did you do about the previously uploaded attachments? did you just leave them rotated?

The edits to the phpBB code I posted would only apply to new thumbnails. If you apply the edit what you can do is download the full size images, delete them for that post and then reupload them.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: rotate images / attachments

Post by canonknipser »

thecoalman wrote: Mon Aug 14, 2017 1:34 pm If you apply the edit what you can do is download the full size images, delete them for that post and then reupload them.
no need for that just do generate new thumbnails, just use the script I linked above. It uses the standard pphBB-functions for generating the thumbnails from the full size images.

If you download the images, you can rotate them via image manipulation program like photoshop, paint, gimp or similar. Then you don't even need to change the core code ...
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5850
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: rotate images / attachments

Post by thecoalman »

canonknipser wrote: Mon Aug 14, 2017 1:57 pm no need for that just do generate new thumbnails, just use the script I linked above. It uses the standard pphBB-functions for generating the thumbnails from the full size images.
Your script will not fix this without the edit to the code I posted, it's just going to generate new sideways thumbs. Corret?

With the edits to the code that would work for the OP because the full size images are fine but it won't work for me. Another modification I did years ago was server side resizing of the full size image so the images I do have that are sideways have to be downloaded and manipulated with image editor. It's the only way to fix them.
If you download the images, you can rotate them via image manipulation program like photoshop, paint, gimp or similar.
The OP's full size images are fine, mucking around and finding the physical file for the thumb is a lot of work. Just seems to me it would be a bit easier to simply reuplaod the images especially if there isn't many of them.
Then you don't even need to change the core code ...
If you don't make those changes the original problem still exists for future uploads.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: rotate images / attachments

Post by canonknipser »

thecoalman wrote: Mon Aug 14, 2017 3:12 pm Your script will not fix this without the edit to the code I posted, it's just going to generate new sideways thumbs. Corret?
Correct. It will use the code edit you made to call of the imagemagick function, because it uses the core functions of phpBB, even if they are modified - if you check the code, you see it simply calls create_thumbnail from the phpBB functions (part of that function you modified by adding the auto-orient) ;)

And
thecoalman wrote: Mon Aug 14, 2017 3:12 pm The OP's full size images are fine
no, they are not. As I mentioned earlier, die original images only seem to be fine because the browser orients them to display correctly:
canonknipser wrote: Mon Aug 14, 2017 9:21 am The rotating of (Iphone-)images is a browser thing. phpBB sends a naked bytestream to the browser by using the download/file.php script; the browser interprets the orientation flag. If you have a slow internet connection and huge image, you can recognize a sudden "flip" when the browser has finished loading the image.
I had several discussion in the past about wrong orientation, eg.
https://www.phpbb.com/customise/db/exte ... pic/174006

Best to send all complains to Mr. Apple for non respecting commonly used standards. Developer try to heal those crap...
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
sakm
Registered User
Posts: 713
Joined: Sun Jan 21, 2007 8:14 pm
Location: Hull, uk
Name: Stu
Contact:

Re: rotate images / attachments

Post by sakm »

DWFII wrote: Mon Aug 14, 2017 12:35 pm
sakm wrote: Mon Aug 14, 2017 9:45 am I have had this problem and it was discussed in this thread

viewtopic.php?f=64&p=14772241

after making the edits suggested in this thread I have not had an issue with wrongly orientated images
Thank you.

So what did you do about the previously uploaded attachments? did you just leave them rotated?
Yeah I just left them but if they really annoyed me I downloaded them and re uploaded them to make them show correctly
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5850
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: rotate images / attachments

Post by thecoalman »

canonknipser wrote: Mon Aug 14, 2017 3:46 pm
no, they are not. As I mentioned earlier, die original images only seem to be fine because the browser orients them to display correctly:[/quote]

I know that but other than the issue with lightbox it's not issue. That is something that needs to be addressed by the browser or lightbox. Altering the image data for thprurposes of setting the correct orioetion of the file itself is bit beyond the scope of phBB IMO.
Best to send all complains to Mr. Apple for non respecting commonly used standards. Developer try to heal those crap...
This isn't just Iphones, even high cameras can be set to utilize it. It's a spec within EXIF. I don't know if there is any reasonable argument as to why it's being used opposed to processing the file correctly, the only possible one I can think of is that it may save some processing time and battery life on the phone.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
DWFII
Registered User
Posts: 386
Joined: Fri Oct 20, 2006 2:17 am
Name: D.W.
Contact:

Re: rotate images / attachments

Post by DWFII »

sakm wrote: Mon Aug 14, 2017 5:56 pm Yeah I just left them but if they really annoyed me I downloaded them and re uploaded them to make them show correctly
Well, I'm in the process of doing that now. Thankfully I only have ten or so on my forum that are like this.

I'd like to have a solution to the original problem--that of attached photos being displayed (in thumbnails and as full size images0)--that I could easily implement and that I understood.

There seems to be some conflict and contradictory opinions though and I'm not savvy enough to sort them out. So I guess I'll hold fire for a bit.

But on the bright side downloading (save image as) the full size photo and rotating it in a PhotoPaint and then deleting the original files and reloading the altered images seems to have cure the orientation problem in both the thumbs and the full size photos...Lightbox notwithstanding.
DWFII
In the High Desert of Central Oregon
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5850
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: rotate images / attachments

Post by thecoalman »

DWFII wrote: Mon Aug 14, 2017 8:41 pm

I'd like to have a solution to the original problem--that of attached photos being displayed (in thumbnails and as full size images0)--that I could easily implement and that I understood.
The only way you are going to fix the thumbnail issue at the moment is by making the changes to the code I posted and using Imagemagick for image processing. There may be other solutions but it's the only posted in this topic.

The full size images are whole other issue and I'll leave that for someone else to address.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
Post Reply

Return to “phpBB Discussion”