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

Wait before we actually need to process the image for checking if Pillow can handle it. #72

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

patrickfournier
Copy link
Collaborator

This avoids loading the image needlessly.

…low can handle it.

This avoids loading the image needlessly.
@patrickfournier patrickfournier force-pushed the pillow-lazy-check branch 2 times, most recently from 2628392 to 41a5152 Compare December 31, 2022 20:46
Copy link
Member

@MinchinWeb MinchinWeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patrickfournier thank you, as always, for this. I think it would work (functionally) as is, but I've added some note that I think would improve it.

i = Image.open(path)
except UnidentifiedImageError:
logger.warning(
"%s Source image %s is not supported by Pillow.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When putting a filename like this in a log message, I like to wrap the name in quotes (single or double).

This is probably more for Windows, as Rich (the log processing library) doesn't consistently pick out Windows filenames.

return None
except FileNotFoundError:
logger.warning(
"%s Source image %s not found.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this filename in quotes too (single or double, but match above).


i = Image.open(image[0])
i = try_open_image(image[0])
if i is None:
Copy link
Member

@MinchinWeb MinchinWeb Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like it would be better (more Python-ic) to re-raise the exemptions in try_open_image(), and then catch them here.

Are there other cases (than raised exemptions) that i could come back as None?

LOG_PREFIX,
path,
)
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I note below, it seems to me that it would be more Python-ic to re-raise the exemption, rather than returning a placeholder value like this.

Something like:

try:
    # ...
except UnidentifiedImageError as e:
    # log message
    raise e

MinchinWeb added a commit that referenced this pull request Mar 7, 2024
…recommendations

Add Release.md
Closes #72

# Conflicts:
#	pelican/plugins/image_process/image_process.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants