Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3] Local adapter thumbnails (PR 36552 clone) #38805

Merged
merged 27 commits into from
Jan 20, 2023

Conversation

obuisard
Copy link
Contributor

@obuisard obuisard commented Sep 22, 2022

Summary of Changes

This Pull Request is for issue #36533 [Solves no 2 of the 3 reported problems, the thumbs] and is a rewrite for #36552 created by @dgrammatiko.

Please refer to the original PR if you want to follow the discussions about the implementation.

The general idea is that image thumbnails are created in the Media Manager and those thumbnails are cached, increasing performance especially when a large amount of images is processed.

The thumbnail creation is 'off' by default.

Testing Instructions

Go to the FileSystem - Local plugin and set 'Create thumbnails' to 'Yes' on the 'images' folder.

Actual result BEFORE applying this Pull Request

The media manager loads full size images.

Expected result AFTER applying this Pull Request

The media manager loads a thumbnail image (max width or height of 200px).

Link to documentations

Please select:

Updated thumbnails creation function
Added thumbs to the adapter
Added thumbs field (defaults to true)
Commented out lines in testUpdateFileWithoutAdapter
Added thumbs and thumbSize properties
Updated construct, createFile, updateFile, delete, getPathInformation, rglob, checkContent
Added getLocalThumbPaths, getThumb, createThumb functions
Replaced all use of mkdir() to Folder::create()
@obuisard
Copy link
Contributor Author

tests/Codeception/api/com_media/MediaCest.php needs to be updated and fails at this point.

@dgrammatiko
Copy link
Contributor

Hey, @obuisard I can't reply on #38722 as Nik has blocked me so I'll write my comment here:

  • when I asked you to resurrect this PR I meant to fork it and patch the things that other were asking me to change in the original PR and also fix the failing tests
  • About the other PR: the approach on that PR is wrong in the sense that you need a data structure that holds all related info per supported media file (mime type, has preview, allows edit, etc). If the project ends up with different inputs for each of all these required data you end up with countless inputs which makes the app really hard to configure and finally use it to its full extend. Mind that since Media manager supports audio and video and other types at some point you might want to provide edit for those (I had a trim plugin for audio and video). Also one more thing: uploads should only allowed if there is a known and matching mime type, the idea that in 2022 people rely on extensions for uploads is a huge security problem. A simple composer require is all it takes: https://packagist.org/packages/league/mime-type-detection to start making things right...

@obuisard
Copy link
Contributor Author

Thank you Dimitris @dgrammatiko. I did address the first review, fixed formatting and tested the code successfully.

As far as the tests are concerned, a solution would be to remove testUpdateFileWithoutAdapter all together, but I would appreciate someone's expertise on this.

@dgrammatiko
Copy link
Contributor

a solution would be to remove testUpdateFileWithoutAdapter all together,

@laoneo could you advise here?

@laoneo
Copy link
Member

laoneo commented Oct 17, 2022

Removing the test is a bad idea. Better to set the default to 0, so no thumbs will be generated and the admin has to activate it. If it is on by default, then after the update all thumbnails are generated without notice, which can lead to resource issues on large sites.

By default, thumbnails are not created
Default the creation of thumbnails to 'no'
@obuisard
Copy link
Contributor Author

I have modified the code to make the thumbnail creation 0 by default. It does solve issues with tests. Thank you @laoneo for the suggestion.

Removed the creation of the folder since it is addressed in libraries/src/Image/Image.php as suggested by @Quy in the previous PR
@jwaisner
Copy link
Member

jwaisner commented Nov 8, 2022

I have tested this item ✅ successfully on 53bc63a

Everything looks good after applying the PR.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38805.

@N6REJ
Copy link
Contributor

N6REJ commented Nov 8, 2022

I have tested this item ✅ successfully on 53bc63a


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38805.

thumb_path should not have been renamed
Added the deprecation on createThumbs
changed deprecated version number
@obuisard
Copy link
Contributor Author

Troy @N6REJ and Jacob @jwaisner, would you mind re-testing this so we can merge it? Thank you so much!

@jwaisner
Copy link
Member

I have tested this item ✅ successfully on d82abd9

Everything retested well. No issues.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38805.

@N6REJ
Copy link
Contributor

N6REJ commented Jan 19, 2023

I have tested this item 🔴 unsuccessfully on d82abd9

in my test the images were already thumbnailed without the PR. This was " The currently installed Joomla! version is "‎4.3.0-dev"‎4.3.0-dev"
with the latest composer & npm.
plugin setting did not exist w/o the pr as expected.
Media manager image Without PR..
image
image with pr
image

original image
DSC_5613-closeup-


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38805.

@obuisard
Copy link
Contributor Author

in my test the images were already thumbnailed without the PR.

That's strange. The thumbnails created with the PR should be 200x200.

@dgrammatiko
Copy link
Contributor

@obuisard what @N6REJ is showcasing is the SIZE of the container DIV, not the size of the image. To get the size of the image open the browser tools, select the image in the elements tab and in the console type $0.naturalWidth (or naturalHeight for the height). False alarm...

@obuisard
Copy link
Contributor Author

@obuisard what @N6REJ is showcasing is the SIZE of the container DIV, not the size of the image. To get the size of the image open the browser tools, select the image in the elements tab and in the console type $0.naturalWidth (or naturalHeight for the height). False alarm...

Oh good catch Dimitris @dgrammatiko! @N6REJ can you double-check? Thank you!

@Quy
Copy link
Contributor

Quy commented Jan 19, 2023

Blurry quality:
38805-blurry-quality

Before PR:
38805-gif-before

After PR:
38805-gif-after

@obuisard
Copy link
Contributor Author

Thank you, Troy @N6REJ for reporting those issues.
The image quality and handling of transparency for GIFs is unrelated to this PR, but improvements need to be made to the image library itself. Something for another PR...

@N6REJ
Copy link
Contributor

N6REJ commented Jan 20, 2023

I have tested this item ✅ successfully on d82abd9

retested as instructed.
image


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38805.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jan 20, 2023
@obuisard obuisard added this to the Joomla! 4.3.0 milestone Jan 20, 2023
@obuisard obuisard merged commit eadc217 into joomla:4.3-dev Jan 20, 2023
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jan 20, 2023
@obuisard
Copy link
Contributor Author

A big thank you to Dimitris @dgrammatiko and the testers !

@carlitorweb
Copy link
Member

Documentation added ✔️

@dgrammatiko
Copy link
Contributor

@obuisard I haven't checked but is the thumbnails functionality bypasses the svg files? If not it needs to do so, the thumbs helper expects only files that the Image class can handle. I'll try to check the next days if I get some free time

@obuisard
Copy link
Contributor Author

obuisard commented Jan 20, 2023

@obuisard I haven't checked but is the thumbnails functionality bypasses the svg files? If not it needs to do so, the thumbs helper expects only files that the Image class can handle. I'll try to check the next days if I get some free time

@dgrammatiko I have checked SVG and image thumbnail creation and both work well together. The image.php file specifies which image file formats can be treated by the GD library .

@N6REJ
Copy link
Contributor

N6REJ commented Jan 20, 2023

it's sad that we are using GD instead of imagemagick.

@obuisard
Copy link
Contributor Author

it's sad that we are using GD instead of imagemagick.

I know, but GD is more widely installed than imagick. It would be great to offer the use of either one of those graphic libraries in Joomla.

@dgrammatiko
Copy link
Contributor

You'll be surprised but GD (PHP 8.1+) is (median) faster than imagick. How do I know? I keep testing these for responsive-images

@N6REJ
Copy link
Contributor

N6REJ commented Jan 21, 2023

@dgrammatiko faster but I thought imagick quality was far higher?

@obuisard obuisard deleted the pr-36552-clone branch September 15, 2023 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants