Automatic Attachment Rotation (and Resize)

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

Previous topic - Next topic

GL700Wing

Prior to v4.x of this mod 'white screen of death' issues were still encountered with JPEG images that had very large dimensions and which needed to be rotated (and even installing the Image Processing Memory Limit mod and configuring it to use 512M of memory didn't resolve the issue) - the only fix for this issue is to resize JPEG images before attempting to rotate them.




Quote from: @rjen on April 08, 2018, 04:17:30 PM
Similar functionality ? It seems to be mostly the same code! Even the text strings are the same...
Some of the functionality/text strings is/are the same but there are some important differences between this mod and Resize Attached Images - particularly in relation to how 'Resize existing images' works (this is done in ./Sources/Display.php).

The Resize Attached Images mod has the following shortcomings in relation to the processing of existing images:
1.  It does not reformat non-JPEG images to JPEG unless 'Resize existing images' is also enabled;
2.  It does not apply a reduction in JPEQ quality unless the image width/height are greater than max width/height; and
3.  It converts non-JPEG images to JPEG when image attachment width/height are greater than max width/height even if 'Reformat non-JPEG images to JPEG' is disabled.

Finally, this mod fully integrates rotating and/or resizing images in topics and, if the PM Attachments mod is already installed, also in PMs.




I'd like to apologise for the inconvenience that has been caused by the number of updates this mod has been through in the last 10 days - dougiefresh and I have been working together to integrate the resizing functionality (which I have had working in a slightly different format on my forums for almost a year) with the 'Automatic Attachment Rotation' mod and obviously we've encountered a few issues along the way.

That said, I am confident the latest version will work as expected/intended.
Life doesn't have to be perfect to be wonderful ...

@rjen

I will do some testing with the latest package in my Test system.

In the meantime I have updated the Dutch Language files (with the strings I already translated for the other MOD  ;D ). Find these attached...
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

@rjen

The MOD is working fine and I have applied it for productive use where it has been for a few days, no errors reported and all seems OK.

I do have a few recommendations though:
1. The UTF8 language files for English are missing in the install package: those should really be included. (same applies to the Inline Attachments MOD)

2. I find that there is an annoying 'feature':

When I go to 'browse files' in the admin section there is the function added to Rotate / Flip the file
Next to this option are the standard checkboxes to select multiple files.

Now when I use the checkbox and Click on the Flip/Rotate Images Button, the image is actually DELETED! Regardless of wether or not the checkbox is selected: it should only cause the selected processing option to be executed...
That is pretty dangerous.

In my opinion clicking the Flip/Rotate button should NEVER cause an image to be deleted!
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

GL700Wing

#163
Uploaded v4.7 - April 12th, 2018
o Updated Dutch translation courtsey of @rjen
o As per @rjen's post included English UTF8 language file.
o As per @rjen's post fixed issue where attachment is deleted when checkbox for deleting attachment is selected and Rotate/Flip Images button is clicked.
o Some code tidy-up in ./Sources/Display.php for JPEG Quailty processing.




@rjen : Thanks for the Dutch language files and bug report.
Life doesn't have to be perfect to be wonderful ...

GL700Wing

Uploaded v5.0 - April 27th, 2018
o Added option for resizing existing images in either manual or batch mode.
o Changed code to only display rotate/flip options for image attachments when modifying a post.
o Fixed problem with readme file that was causing it not to display during package installation.
Life doesn't have to be perfect to be wonderful ...

@rjen

In the new admin option to Resize Existing Images  a list is presented of images to be processed.

Two problems with the list:

1. This list cannot be sorted (by any column)
2. The browse pages option does not function: even though the page number changes, the listed images remain unchanged...

Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

@rjen

In addition: I was looking at the new text strings to add these to the dutch language files.

Now I am confused: as part of the install package you have included an additonal text file : ResizeExistingImages.english.php and ResizeExistingImages.english-utf8.php, but the install file is also adding the same text strings to Modifications.english.php!

It seems that this is not intentional... can you please correct this?

I will provide the dutch files if the files are the correct way...
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

Rob Lightbody

Hi,

I've just installed v5.0 after giving you a few weeks to iron out your niggles, and so far so good.  I'll feed back again in a few days if I see any issue (or not).

Keep up the good work (but don't go overboard and make this mod too large and complex!!)

Cheers,

- Rob

GL700Wing

Uploaded v5.1 - April 28th, 2018
o Per @rjen - fixed issue that prevented Post and PM Inline Attachment inline attachment numbers from being incremented when modifying a post.
o Per @rjen - fixed issues with sorting and browsing list of images to be resized/reformatted.
o Per @rjen - load required language file rather than add text strings to other language files.




Thanks @rjen for the bug reports.

In relation to the adding of the text strings to the Modifications.english.php file : this was the approach taken in the mod I based the manual/batch resizing code on.  That said, I have now updated the code in this mod to load the required language file instead.

QuoteI will provide the dutch files if the files are the correct way...
Thanks - if you provide the ResizeExistingImages.dutch.php and ResizeExistingImages.dutch-utf8.php files I'll add them to the next release.
Life doesn't have to be perfect to be wonderful ...

GL700Wing

Quote from: The QE2 Story Forum on April 27, 2018, 01:03:07 PMI've just installed v5.0 after giving you a few weeks to iron out your niggles, and so far so good.  I'll feed back again in a few days if I see any issue (or not).
Thanks - I've just uploaded v5.1 so you can try that version now!  ;)

QuoteKeep up the good work (but don't go overboard and make this mod too large and complex!!)
I don't think much more functionality will be added to this mod.

That said I know that having the option to resize existing image attachments (using manual and/or batch processing modes) is really important for forums that have not previously implemented image attachment dimension/filesize restrictions for several reasons:
1. Smaller image attachment filesizes will result in posts that load more quickly;
2. Reducing the filesize of image attachments has the potential to significantly reduce the disk space used by attachments; and
3. Probably no so important but less website bandwidth will be used.
Life doesn't have to be perfect to be wonderful ...

@rjen

Thanks for sorting out the language strings. Find attached the missing dutch files...

Small problem with the links to images in the list.
For most images the link works: it brings me directly to the image in the post. For some the link brings me to the first message in the post...

I noticed that the link under the standard option (Browse files > Attachments) always work.
Theze are formatted as such:
https://test.fjr-club.nl/index.php?topic=14573.msg257357#msg257357
https://test.fjr-club.nl/index.php?topic=14573.msg213612#msg213612

The links in the new list (Browse files > Resize Existing Images) are formatted as below:
https://test.fjr-club.nl/index.php?topic=14573.0.msg257357#msg257357
https://test.fjr-club.nl/index.php?topic=14573.0.msg213612#msg213612

These links do not always work. It seems to be related the length of the topics: in a long topic it does not work correctly..

It seems to be caused by the .0 added after the topic ID..
?topic=14573.0.msg


Apart from that the packages seems to be fine.
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

GL700Wing

V5.2 - April 28th, 2018
o Per @rjen - fixed image and post links for images in Browse files > Resize Existing Images list.
o Per @rjen - added Dutch language files.




@rjen - Many thanks for your testing and feedback - I really appreciate it!
Life doesn't have to be perfect to be wonderful ...

Rob Lightbody

#172
Hi there,

I woke up to lots of errors in my forum, and have uninstalled this again (v 5.0).  Do you think, from looking below, that 5.2 will resolve this?  I have uninstalled 5.0 and installed 5.2.

This was the first error, from a guest


https://www.theqe2story.com/forum/index.php?/topic,8446.0.html
The database value you're trying to insert does not exist: width
Function: loadAttachmentContext
File: /public_html/forum/Sources/Display.php
Line: 1584

Then followed by hundreds of errors from everyone when accessing that topic.


2: rename(/home/robligh/public_html/forum/attachments/58323_58fd5a2be5327a3ac9844bdf2b5c8440a0a01323.temp,/home/robligh/public_html/forum/attachments/58323_58fd5a2be5327a3ac9844bdf2b5c8440a0a01323): No such file or directory
File: /home/robligh/public_html/forum/Sources/Display.php
Line: 1542



2: getimagesize(/home/robligh/public_html/forum/attachments/58323_58fd5a2be5327a3ac9844bdf2b5c8440a0a01323): failed to open stream: No such file or directory
File: /home/robligh/public_html/forum/Sources/Display.php
Line: 1545



https://www.theqe2story.com/forum/index.php?/topic,8446.0.html
2: filesize(): stat failed for /home/robligh/public_html/forum/attachments/58323_58fd5a2be5327a3ac9844bdf2b5c8440a0a01323
File: /home/robligh/public_html/forum/Sources/Display.php
Line: 1548


Thanks.

Rob Lightbody

Second, separate feedback.

Now on 5.2.

Someone has managed to upload a huge 10mb photo - 6000x4000 px.  I've tried to use the resize existing images feature to shrink this down, but it seems to just ignore me when I try - doesn't do anything, and no error logged either.   If its any help, this is the post with the huge image on it - https://www.theqe2story.com/forum/index.php/topic,8333.msg96611.html#msg96611


GL700Wing

Quote from: The QE2 Story Forum on April 28, 2018, 06:23:17 AM
Someone has managed to upload a huge 10mb photo - 6000x4000 px.  I've tried to use the resize existing images feature to shrink this down, but it seems to just ignore me when I try - doesn't do anything, and no error logged either.
Have you checked the error_log file on the server to see if it contains any error messages?

QuoteIf its any help, this is the post with the huge image on it - https://www.theqe2story.com/forum/index.php/topic,8333.msg96611.html#msg96611
I've downloaded that photo and tested the following scenarios on my test forum and the image is successfully resized to 1024x682 with a filesize of ~57Kb every time:

Scenario One:
1. The following Attachment Settings all saved as blank: 'Max attachment size per post', 'Max size per attachment', 'JPEG quality factor', 'Maximum width of attached images' and 'Maximum height of attached images'.
2.  The Attachment Setting 'Resize existing images' is disabled.
3. The 10Mb/6000x4000Px photo is attached to a post - the image information shows the photo is 10715.44 kB, 6000x4000.
4. The following Attachment Settings are configured using values shown at the end of this post: 'Max attachment size per post', 'Max size per attachment', 'JPEG quality factor', 'Maximum width of attached images' and 'Maximum height of attached images'
5. The image attachment is selected from the Admin -> Attachments and Avatars -> Browse Files -> Resize Existing Images list and successfully resized by clicking on 'Resize Existing Images'/'Resize and/or Reformat Existing Images'.

Scenario Two:
1. The following Attachment Settings all saved as blank: 'Max attachment size per post', 'Max size per attachment', 'JPEG quality factor', 'Maximum width of attached images' and 'Maximum height of attached images'.
2.  The Attachment Setting 'Resize existing images' is disabled.
3. The 10Mb/6000x4000Px photo is attached to a post - the image information shows the photo is 10715.44 kB, 6000x4000.
4. The following Attachment Settings are configured using values shown at the end of this post: 'Max attachment size per post', 'Max size per attachment', 'JPEG quality factor', 'Maximum width of attached images' and 'Maximum height of attached images'
5. The Attachment Setting 'Resize existing images' is enabled.
6. The image attachment is automatically resized the next time the post containing the image is displayed.

Scenario Three:
1. The following Attachment Settings are configured using values shown at the end of this post: 'Max attachment size per post', 'Max size per attachment', 'JPEG quality factor', 'Maximum width of attached images' and 'Maximum height of attached images'
2. The Attachment Setting 'Resize existing images' is enabled.
3. The 10Mb/6000x4000Px photo is attached to a post  - the image information is automatically resized when the post is saved.




The fact that the image is being shown in the list of images that can be resized indicates that you have configured at least some of the following Attachment Settings:  'Max attachment size per post', 'Max size per attachment', 'JPEG quality factor', 'Maximum width of attached images' and 'Maximum height of attached images' - you should also make sure the Attachment Setting 'Resize existing images' is enabled.

Given that the photo resizes correctly on my test forum with three different scenarios (and no error messages) the only other thing I can suggest you try is to save the photo to your own computer, edit the topic and clear the checkbox for the existing image attachment and attach the photo as a new attachment.



Suggested Attachment Settings:
Max attachment size per post: 2048
Max size per attachment: 1024
JPEG quality factor: 80
Maximum width of attached images: 1024
Maximum height of attached images:1024

Life doesn't have to be perfect to be wonderful ...

GL700Wing

Quote from: The QE2 Story Forum on April 28, 2018, 05:44:41 AM
I woke up to lots of errors in my forum, and have uninstalled this again (v 5.0).  Do you think, from looking below, that 5.2 will resolve this?  I have uninstalled 5.0 and installed 5.2.
I suspect those error messages are being generated because the Attachment Setting 'Resize existing images' is enabled and there is a missing or corrupted image attachment -  Admin => Forum => Attachments and Avatars => File Maintenance => Attachment Integrity Check should be run and issues corrected.

If the errors persist disable the Attachment Setting 'Resize existing images'.
Life doesn't have to be perfect to be wonderful ...

Rob Lightbody

Thanks for replying/trying to help.

OK so ....

I have max attachment size per post and max size per attachment deliberately set to 0 (disable) to allow my very non-technical forum users to upload big files.  I don't want it stopping them trying to upload a big photo, I just want it to shrink it down without htem knowing what its doing.  If i set these to 1024/2048 as you suggest, I can't upload that big image at all.

I did have resize existing imagest ticked.

And I've had JPEG quality set to 85, and max height/width both at 1280 for a long time.

I can't see any errors at all on the server, it just stubbornly refuses to do anything to this particular photo!

GL700Wing

Quote from: The QE2 Story Forum on April 28, 2018, 09:39:07 AM
I have max attachment size per post and max size per attachment deliberately set to 0 (disable) to allow my very non-technical forum users to upload big files.  ...  If i set these to 1024/2048 as you suggest, I can't upload that big image at all.
That's really interesting because I can definitely upload that big image with those settings (ie, Max attachment size per post: 2048 and Max size per attachment: 1024) and the reason for this is that the attachment size is checked after the image has been resized.

I'll send you a PM with details of a login you can use on my test forum (which is a recent copy of my production forum) so that you can try with that big image yourself (you can either create a new topic or reply to an existing one).




FYI: My test forum is configured with the following Attachment Settings:
Max attachment size per post: 2048
Max size per attachment: 1024
Reformat non-JPEG images to JPEG: Enabled
Resize existing images: Enabled
JPEG quality factor: 80
Maximum width of attached images: 1024
Maximum height of attached images:1024
Life doesn't have to be perfect to be wonderful ...

Rob Lightbody

Quote from: GL700Wing on April 28, 2018, 10:07:40 AM
That's really interesting because I can definitely upload that big image with those settings (ie, Max attachment size per post: 2048 and Max size per attachment: 1024) and the reason for this is that the attachment size is checked after the image has been resized.

Hi.  I did wonder about that, which is why I did the test - it sounds like my forum/server is simply not managing to resize that image (by whatever method), but does manage to upload it OK.

GL700Wing

Quote from: The QE2 Story Forum on April 28, 2018, 10:10:42 AM
Quote from: GL700Wing on April 28, 2018, 10:07:40 AM
That's really interesting because I can definitely upload that big image with those settings (ie, Max attachment size per post: 2048 and Max size per attachment: 1024) and the reason for this is that the attachment size is checked after the image has been resized.

Hi.  I did wonder about that, which is why I did the test - it sounds like my forum/server is simply not managing to resize that image (by whatever method), but does manage to upload it OK.
The forum I've been using to test/check the resizing of your large photo is running SMF 2.0.15 and has 135 mods (including this one) installed plus lots of other customisations.

I'm beginning to wonder if you have a conflicting mod installed or if an earlier version of this mod or a mod like Resize Attached Images did not uninstall fully/correctly.
Life doesn't have to be perfect to be wonderful ...

Advertisement: