Roundup Tracker - Issues

Message7439

Author rouilj
Recipients rouilj
Date 2022-01-10.03:27:38
Message-id <1641785259.09.0.817984266675.issue2551187@roundup.psfhosted.org>
In-reply-to
https://wiki.roundup-tracker.org/MixinClassFileClass defined a
gzip mixin that compresses data files transparently.

Could we add a similar mixin that takes an image file and
converts it to avif format for storage at the same quality? This
should reduce file storage needs by 66% in many cases.

Issues:

 1. some cases avif can increase file size. In this case, the
    mixin should store the original file. The mime type for the
    file should be the stored format: e.g. image/avif if smaller
    or the original image/... mime type.

 2. client:_serve_file doesn't look at the accept header, it
    probably should.  If no acceptable format is found, possible
    raise exception and return 406.  parse_accept_header() (from
    roundup.rest import parse_accept_header) can do this to
    self.request.headers['Accept']. Consider moving
    parse_accept_header out of rest.py and into a general
    roundup/http_headers.py. Also maybe
    roundup/cgi/accept_language.py can join it.

 3. Browsers that don't support avif. Using the <picture> tag
    with multiple source tags for each supported format: avif,
    png, jpg should work. Set the srcset="..."  to
    .../file33/afile.jpg?@format=image/jpeg should return a jpg
    version of file33. It looks like the accept header includes
    all supported image types: e.g. chrome will download the avif
    type but includes image/avif, image/webp, image/apng,
    image/svg+xml, image/*, and */*;q=0.8. So maybe we don't
    bother with @format and just search for a valid hit in the
    Accept header. We prefer sending the stored mime type when it
    is supported.

 4. rendering time. The conversion to jpg can be done on the
    fly. But this can take time. Consider caching file33 as a jpg
    to file33.jpg at db/files/file/0/file33.jpg.  These files can
    be cleaned using a scheduled script to remove files either
    unread (atime) or older (mtime) than 30 days for example.  As
    more browsers support avif the back conversion will be less
    of an issue.

 5. Can this be done totally as a mixin? I think the mixin gets the
    client object as self. So the logic about what to convert to
    should be possible without changes to _serve_file. However
    _serve_file may need to be modified to call write_file with the
    modified file##.jpg name.

 6. Is there some time we should not convert the file? E.G. if some
    analysis of the file would be damaged by converting it. Think
    png that trigger a remote code execution. Converting it may trigger
    the issue or only the original file format will support forensic analysis.
 
For python library support, pillow with
https://pypi.org/project/pillow-avif-plugin/ should support avif as
source and destination formats.
History
Date User Action Args
2022-01-10 03:27:39rouiljsetrecipients: + rouilj
2022-01-10 03:27:39rouiljsetmessageid: <1641785259.09.0.817984266675.issue2551187@roundup.psfhosted.org>
2022-01-10 03:27:39rouiljlinkissue2551187 messages
2022-01-10 03:27:38rouiljcreate