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
Refactor: Use Pillow for image info #1138
Merged
dairiki
merged 19 commits into
lektor:master
from
dairiki:refactor.use-pillow-for-image-info
Nov 7, 2023
Merged
Refactor: Use Pillow for image info #1138
dairiki
merged 19 commits into
lektor:master
from
dairiki:refactor.use-pillow-for-image-info
Nov 7, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dairiki
force-pushed
the
refactor.use-pillow-for-image-info
branch
2 times, most recently
from
April 23, 2023 18:58
160d768
to
5522837
Compare
dairiki
force-pushed
the
refactor.use-pillow-for-image-info
branch
6 times, most recently
from
May 9, 2023 15:24
4e99b6d
to
4c64b71
Compare
dairiki
force-pushed
the
refactor.use-pillow-for-image-info
branch
from
May 11, 2023 03:47
4c64b71
to
99e01c4
Compare
dairiki
force-pushed
the
refactor.use-pillow-for-image-info
branch
2 times, most recently
from
June 6, 2023 22:38
f123e16
to
e27ff9d
Compare
dairiki
force-pushed
the
refactor.use-pillow-for-image-info
branch
2 times, most recently
from
August 1, 2023 16:12
f015ae8
to
115730d
Compare
dairiki
force-pushed
the
refactor.use-pillow-for-image-info
branch
from
November 2, 2023 22:25
115730d
to
4e0237c
Compare
Use Pillow to determine image format and dimensions rather than our own home-rolled code.
Remove deprecated property `ThumbnailMode.label` and classmethod `ThumbnailMode.from_label`.
The following plugins appears to use internal bits of `lektor.imagetools`: - https://github.com/numericube/lektor-minification/ - https://github.com/chaos-bodensee/lektor-image-resize/ - https://github.com/skorokithakis/lektor-thumbnail-generator/ From a perusal of their code, it appears that they'll all be broken by recent Lektor code changes having to do with moving from ImageMagick to Pillow. This doesn't completely address the issues for those plugins, but, for the sake of backward-compatibility, here we: - re-export `lektor.imagetools.compute_dimensions` (which was moved to `lektor.imagetools.thumbnail`). - re-implement and deprecated `lektor.imagetools.get_quality`
Instead of a Mock, use a real lektor.context.Context in the image tests.
I'm not sure why this test ever worked. Different versions of convert from color strings to HSV values differently.
- rename to `_get_svg_info` to emphasize it is internal - raise exception rather than returning "unknown" if SVG is unparseable - rewind file after _get_svg_info call
Pillow >= 9.1 moves many of the constants that were in the top-level of the PIL.Image module into IntEnums within the module. But then it re-exports the enum members to the module programmatically. Something has changed recently (I'm not sure whether on the Pillow side or the pylint side) to make pylint throw `no-member` warnings when these are accessed as module-level attributes. For the sake of moving forward, here we use the enums, polyfilling them if running with an older version of Pillow.
dairiki
force-pushed
the
refactor.use-pillow-for-image-info
branch
from
November 5, 2023 20:12
4e0237c
to
2a69b6b
Compare
dairiki
force-pushed
the
refactor.use-pillow-for-image-info
branch
from
November 6, 2023 21:53
2a69b6b
to
3898402
Compare
Nice one, thanks :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This replaces our homegrown code in get_image_info() code, and the exifread-based based code in exif_info() with Pillow-based code.
This eliminates two dependencies (on exifread and filetype) and will make it much easier to support other image formats (e.g. WEBP) going forward.
It also guarantees that get_image_info and make_image_thumbnail will agree on things like image type and what images are thumbnailable.
I've done some rudimentary profiling. Currently, the new Pillow-based version of get_image_info is a bit slower (maybe by 30-50%) than the current one. (Getting the image dimensions is very fast, the slower bit is reading the Exif tags to determine whether height and width need to be swapped.)
Issue(s) Resolved
Fixes #
Related Issues / Links
#1099
Description of Changes