News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Automatic Attachment Rotation (and Resize)

Started by dougiefresh, March 04, 2016, 07:34:59 PM

Previous topic - Next topic

szinski

#560
Yes, the new new code works, thanks.

szinski

Also, animated GIFs are not working when I enable the plugin (only displays a static image). When I disable the plugin, animated GIFs upload and display properly.

GL700Wing

Quote from: szinski on July 09, 2024, 09:06:31 PMAlso, animated GIFs are not working when I enable the plugin (only displays a static image). When I disable the plugin, animated GIFs upload and display properly.
@szinski Okay - try this file ...
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

szinski

Quote from: GL700Wing on July 10, 2024, 12:08:56 AM
Quote from: szinski on July 09, 2024, 09:06:31 PMAlso, animated GIFs are not working when I enable the plugin (only displays a static image). When I disable the plugin, animated GIFs upload and display properly.
@szinski Okay - try this file ...
Installed the new code and it's still not showing animated GIFs. I disabled the plugin, uploaded an animated GIF, and it displays properly. Then, I re-enable the plugin and the animation no longer works.

Settings (that should matter) are:
Re-encode potentially dangerous image attachments: OFF
Reformat non-JPEG images to JPEG: OFF

szinski

Seeing the following error:

Cannot modify header information - headers already sent by (output started at /home/test/public_html/forum/Sources/Subs-AutoRotation.php:2345)

szinski

It seems to be resizing the GIFs.

GIF uploaded with plugin disabled is 243.86 KB and animates as expected.
GIF uploaded with plugin enabled is 10.73 KB and no animation.

Arantor

Is the "Use Imagick" option ticked? (And does your server have ImageMagick?)

Resizing using the GD (default) method cannot handle animated GIFs, it ends up resizing the first frame only.
Holder of controversial views, all of which my own.


szinski

Quote from: Arantor on July 10, 2024, 12:45:53 PMIs the "Use Imagick" option ticked? (And does your server have ImageMagick?)

Resizing using the GD (default) method cannot handle animated GIFs, it ends up resizing the first frame only.
Yes, Imagick is installed and working. (yes, the box is checked, which I believe isn't selectable unless it's installed)

GL700Wing

Quote from: szinski on July 10, 2024, 11:39:01 AMInstalled the new code and it's still not showing animated GIFs. I disabled the plugin, uploaded an animated GIF, and it displays properly. Then, I re-enable the plugin and the animation no longer works.

Settings (that should matter) are:
Re-encode potentially dangerous image attachments: OFF
Reformat non-JPEG images to JPEG: OFF

Just discovered that I'd forgotten to also exclude GIF images if the 'Automatically process existing images using the settings above when messages are displayed' setting is enabled - the previous version was working as I expected apart from that.  New Subs-AutoRotation.php file attached.

Quote from: szinski on July 10, 2024, 11:41:39 AMSeeing the following error:

Cannot modify header information - headers already sent by (output started at /home/test/public_html/forum/Sources/Subs-AutoRotation.php:2345)
Can't find any leading/trailing whitespace around the opening/closing PHP tags in the last Subs-AutoRotation.php file I uploaded (the most common cause of this type of error) - can't explain that error at all.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

szinski

#569
Quote from: GL700Wing on July 10, 2024, 07:01:00 PMCan't find any leading/trailing whitespace around the opening/closing PHP tags in the last Subs-AutoRotation.php file I uploaded (the most common cause of this type of error) - can't explain that error at all.
I installed the latest Subs-AutoRotation.php and now everything seems to be working.

That crazy error was caused by a trailing newline character after the PHP closing ?> tag from where I pasted the code using VIM. I removed the trailing newline and the error is gone.

I appreciate all of your help with this!

GL700Wing

Quote from: szinski on July 11, 2024, 09:27:14 AM
Quote from: GL700Wing on July 10, 2024, 07:01:00 PMCan't find any leading/trailing whitespace around the opening/closing PHP tags in the last Subs-AutoRotation.php file I uploaded (the most common cause of this type of error) - can't explain that error at all.
I installed the latest Subs-AutoRotation.php and now everything seems to be working.

That crazy error was caused by a trailing newline character after the PHP closing ?> tag from where I pasted the code using VIM. I removed the trailing newline and the error is gone.

Great - thanks for letting me know. 

Also, and when possible, you should just overwrite the old file with the new one that is supplied by uploading it rather than using an editor to copy/paste to replace the old file contents.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

szinski

I agree, totally my fault.

I use a Mac and it's easier to open the file in Visual Studio Code, then copy all to the clipboard, then SSH to my server, create a new file using VIM (set paste mode) and paste in the new code. Then I backup the old file, then move the new one into place. That way I can easily revert back to the old code if I see any issues. I usually remove the trailing whitespace, but I neglected to do so this time. Again, my bad. But, everything looks good now. Animated GIFs are working and my users are happy. I appreciate your help with this.

GL700Wing

#572
Quote from: szinski on July 11, 2024, 09:47:12 AMI use a Mac and it's easier to open the file in Visual Studio Code, then copy all to the clipboard, then SSH to my server ...
I use the Waterfox Classic browser with the FireFTP add-on (which supports SFTP and can use SSH keys) for file transfers to/from the web hosting servers I use.  I know the Waterfox Classic browser is no longer being updated but I don't use it for anything else except the FireFTP add-on.

QuoteI appreciate your help with this.
You're welcome.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

gevv

Hello,

Not showing animated gif.

Re-encode potentially dangerous image attachments: Off
Reformat non-JPEG images to JPEG: Off

Automatic Attachment Rotation v6.25
SMF v2.1.4
ElkArte is a modern, powerful community building forum software. https://www.elkarte.net/

GL700Wing

Quote from: gevv on June 24, 2025, 02:59:18 AMNot showing animated gif.

Re-encode potentially dangerous image attachments: Off
Reformat non-JPEG images to JPEG: Off

Automatic Attachment Rotation v6.25
SMF v2.1.4
Did you try using the Subs-AutoRotation.php script attached to this message?
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

gevv

@GL700Wing  Thanks.

I tried it and the problem was solved.
ElkArte is a modern, powerful community building forum software. https://www.elkarte.net/

gevv

I noticed another problem. After uploading, the background of .png images with transparent backgrounds becomes white or black. The transparency disappears.

Resized transparent .png image has black background.

Without resizing transparent .png image has white background.
ElkArte is a modern, powerful community building forum software. https://www.elkarte.net/

GL700Wing

#577
Quote from: gevv on June 24, 2025, 04:58:37 PMI noticed another problem. After uploading, the background of .png images with transparent backgrounds becomes white or black. The transparency disappears.

Resized transparent .png image has black background.

Without resizing transparent .png image has white background.
@gevv Just to help me with troubleshooting: are you using iMagick or GD to process the images?


Update: Fixed ./Sources/Subs-AutoRotation.php for PNG images with transparent backgrounds processed by GD.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

GL700Wing

Version 6.26 - June 25, 2025
o Added support for SMF 2.1.5.
o Fixed issue reported by gevv that caused PNG images to lose background transparency.
o Fixed issue reported by gevv that caused GIF images to lose animation because non-JPEG images were being compressed.
o Fixed issue reported by szinski that caused allowed memory size to be exhausted when entering 'File Maintenance' on forums with a very large number of image attachments (eg, 300,000).
o Fixed issue reported by szinski where GIF images were losing animation.
o Fixed bug that caused PNGs to lose transparency when resized.
o Another bug fix for some images being incorrectly resized when a message was displayed (see explanation in v6.24).
o Minor tweak for reducing file size of images when iMagick is used.
o Updated code so that only image attachments with the following image MIME types are processed by this mod: bmp, gif, jpeg, png, tiff, and webp.
o SMF 2.1: Bug fix for not all mod features being disabled when mod is disabled.
o SMF 2.1: As per this request added feature to extract iTxt and tExt metadata from PNG images (the extracted text is converetd to ASCII and can optionally be used as the 'title' attribute for images that are displayed as thumbnails below a message and/or inserted inline within a message).



Notes:
This version of the mod only supports SMF 2.0.18-2.0.19 and SMF 2.1.4-2.1.5 (versions for earlier SMF releases are still available to download/install).
There is an upgrade option for v6.25.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Advertisement: