Mastodon: Optimize user-uploaded images

Created on 1 Jul 2017  路  7Comments  路  Source: tootsuite/mastodon

Even with running media:clear every day as a cronjob, after 3 months of use toot.cafe is using up 27.6GB in public/system/media_attachments. It would be nice to have another rake task, let's say media:optimize, to run mozjpeg and zopfli-png over those images to shrink their size down a bit.

zopfli-png is non-destructive, but mozjpeg can reduce the quality of the original image. So ideally there'd be some reasonable default quality (mozjpeg seems to recommend 75) and then admins could also pass in a parameter to change it.


  • [x] I searched or browsed the repo鈥檚 other issues to ensure this is not a duplicate.
  • [ ] This bug happens on a tagged release and not on master (If you're a user, don't worry about this).
performance

All 7 comments

Alternatively, maybe this should be an automatic operation when an image is uploaded, since it's also a performance improvement that improves transfer times, and would benefit those using cloud storage providers as well.

Image quality issues aside, wouldn't making the files smaller only postpone the problem for a short time?

reducing file sizes is, admittedly, not the panacea regarding disk space taken by uploaded media, but it helps both the users and the admins, and it doesn't cost much.

Automatic conversion of any image to low-quality jpeg is one of the things people keep cursing birdsite for.

Mastodon already turns animated gif into mpeg (much smaller, but bad for pixel artists). Please don't start turning png into jpeg too.

Compressing png as far as possible is okay of course. And maybe jpeg can be compressed a little further (though not as much as birdsite please)

optimizing media doesn't mean turning everything into trash like twitter does yeah. If we do this we should definitely keep a good quality.

  • Video quality is not changed because converting video is resource-intensive and we want to avoid it as much as possible
  • Videos generated from GIFs are optimized pretty well without quality loss
  • JPEG and PNG already have a -quality 90 setting, any more would be quality loss

There might be some tools that do advanced stuff but as far as ffmpeg/imagemagick go we're maxed out imo.

Fair enough, maybe at some point though it'd be nice to have hooks to add extra minifiers (mozjpeg, zopfli-png) and/or dial down the quality a bit.

Was this page helpful?
0 / 5 - 0 ratings