jacobobryant / platypub

A publishing platform built with Biff
MIT License
65 stars 13 forks source link

Resize images on upload/on render #23

Open jacobobryant opened 2 years ago

jacobobryant commented 2 years ago

It'd be nice if we could handle image resizing in one way or another. #17 talks about resizing the image element in the DOM but doesn't cover resizing the original file. (Same for the default theme code; images are displayed at the right size, but the files will sometimes be bigger than they need to be.)

One option: have theme code use https://images.weserv.nl/, a free image resize/editing service. It's very convenient; you pass in a url to the original file along with some size params etc and they'll resize, cache, and serve the image for you on demand.

Another option: upload-image could put the original + a few standard sizes on s3, and then we update the data model in one way or another to include all the sizes. Perhaps add keys like :image/url-small, :image/url-medium etc. Then in different contexts we use different urls. Maybe when you're uploading an image from the TinyMCE, we use a medium/large size ("large" might still be smaller than the original size), and when you're uploading an image in the post sidebar (i.e. for use in social media previews) then we use a smaller size. Or have theme code figure out which size to use somehow.

I like the first option, but one downside is you can't use it for the post metadata because images.weserv.nl's robots.txt file. otoh often for preview images they're custom made in the correct size to begin with so maybe not a big deal; just use the original url for that and use images.weserv.nl for images in post content etc. 🤷‍♂️