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

Allow overriding of functions for specific file types #88

Open
dbramwell opened this issue Dec 3, 2020 · 0 comments
Open

Allow overriding of functions for specific file types #88

dbramwell opened this issue Dec 3, 2020 · 0 comments

Comments

@dbramwell
Copy link

Recently I tried to make Wagtail use gifsicle when resizing gifs, rather than wand and imagemagik as it seemed to be quicker at it.

I thought I could do this by adding the following code with implementations of the functions that just called the gifsicle cli:

        registry.register_operation(GIFImageFile, "auto_orient", auto_orient)
        registry.register_operation(GIFImageFile, "resize", resize)
        registry.register_operation(GIFImageFile, "crop", crop)
        registry.register_operation(GIFImageFile, "save_as_gif", save_as_gif)

After some experimentation this approach worked as expected, however I then got intermittent errors with jpegs. Occasionally throwing an error here stating that cost was None.

This seems to boil down to the registry trying to figure out how it can convert a JPEGImageFile to a GIFImageFile, and adding the following has fixed it for our usecase:

        for image_class in registry.get_image_classes():
            if image_class is GIFImageFile:
                break
            registry.register_converter(image_class, GIFImageFile, None, float("inf"))

I'm unsure if you intended for register_operation to be used in this way, but it seems quite useful and am happy to work on a pull request to remove the need for the register_converter stuff and add tests.

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

No branches or pull requests

1 participant