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

PyEncoder doesn't exist #4059

Closed
sheatsm opened this issue Sep 12, 2019 · 4 comments · Fixed by #6069
Closed

PyEncoder doesn't exist #4059

sheatsm opened this issue Sep 12, 2019 · 4 comments · Fixed by #6069
Projects

Comments

@sheatsm
Copy link

sheatsm commented Sep 12, 2019

What did you do?

Attempted to implement a Python based encoder for an image plugin.

What did you expect to happen?

From the documentation of 'register_encoder', I expected ImageFile.PyEncoder to exist.

def register_encoder(name, encoder):
    """
    Registers an image encoder.  This function should not be
    used in application code.

    :param name: The name of the encoder
    :param encoder: A callable(mode, args) that returns an
                    ImageFile.PyEncoder object

    .. versionadded:: 4.1.0
    """
    ENCODERS[name] = encoder

What actually happened?

It does not exist in any namespace that I can find. Is this an oversight or is there a new way to implement Python based encoders suitable for addition to register_encoder?

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.7.3
  • Pillow: 6.0.0
class MyEncoder(ImageFile.PyEncoder):
    pass
@radarhere radarhere changed the title Documentation references PyEncoder which doesn't seem to exist. Documentation references PyEncoder which doesn't seem to exist Sep 12, 2019
@radarhere
Copy link
Member

This was added in #1938. Looking at the thread, it seems that this was simply not implemented yet.

@radarhere radarhere changed the title Documentation references PyEncoder which doesn't seem to exist PyEncoder doesn't seem to exist Sep 12, 2019
@aclark4life aclark4life added this to New Issues in Pillow Sep 12, 2019
@radarhere radarhere changed the title PyEncoder doesn't seem to exist PyEncoder doesn't exist Oct 21, 2019
@drewcassidy
Copy link

drewcassidy commented Jan 28, 2021

I'm interested in this as well, since I'd like to write a DXT compression plugin but don't know where to begin with writing the encoder

@Piolie
Copy link
Contributor

Piolie commented Jan 29, 2021

@drewcassidy I managed to get an encoder working by manually implementing the encoder class. The required public methods are __init__, (@property) pushes_fd, setimage, setfd, encode_to_pyfd and cleanup. Though a bit of a kludge, it was easier than I expected.

You can check my work and hopefully adapt it to your image format. Good luck.

@radarhere
Copy link
Member

I've created PR #6069 to add PyEncoder.

@radarhere radarhere moved this from New Issues to In progress in Pillow Feb 24, 2022
Pillow automation moved this from In progress to Closed Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

4 participants