[SOLVED] Jp2 Image support

What is required to add support for jp2 image format ( Plone 5.2, python 3 )

Likely support through Pillow (which should be the case). What did you try? Where does it fail?

I tried to install 'different libs etc' some time ago (without luck). Since I might have some spare time at the end of the week, I consider looking into this. A Quick search gives me the impression that that is not enough (so it will require code-changes in PIL(low) itself ( maybe: (PIL.Jpeg2KImagePlugin - Pillow (PIL Fork) 9.2.0 documentation) ?

UPDATE: I notice that Plone 5.2 uses pillow = 6.2.2. Not sure if it is OK to use never version

plone.namedfile has some ugly magic to detect the image type

I have some branches there to support WEBP images, you can use them to get an idea:

1 Like

So, the changes need to be done in phone.namedfile AND plone.scale (and nothing in Pillow ) ?

If Pillow supports JP2 images, you don't need to do anything there.

You need to modify plone.scale if you want your image scales to be in JP2 format, which I guess you want.

Awesome! Do you plan a Pull Request?

1 Like

What format they are in is not of too much importance.
The problem is that when I adding jp2 images, no scales are made ( so no image is shown)

Latest version of Pillow (9.2.0) and Plone 5.2 ( 5.2.9) and latest version of plone.scale / named file works (Python3.8).

It looks like a check for image type is done using PIL, if no image type is found (plone.namedfile/utils, line 194):

NOTE: Pillow 9.2.0 did not work with 'default 5.2.6' in my setup (on another computer, so not same python).

    # Use PIL / Pillow to determ Image Information
        img = PIL.Image.open(BytesIO(data))
        width, height = img.size
        content_type = PIL.Image.MIME[img.format]
1 Like

I was thinking on it yes.

The point is whether we get any improvement on performance or how to make this optional, or perhaps how to select the format of the scaled images, which would be better.

Maybe a control panel setting which is read at:

Please note: I got errors trying to use Pillow 9.2.0 on earlier versions (than 5.2.6), so any settings should check for Pillow version or something else.