atomic-server icon indicating copy to clipboard operation
atomic-server copied to clipboard

Image endpoint (resize, crop)

Open joepio opened this issue 3 years ago • 0 comments

Now that we have Files #107, users are likely to upload and use images. Very important here is the ability to resize (and often crop) images to keep websites performant.

Implementation

As an endpoint

I think a simple implementation is this is to have an endpoint that takes:

  • A File resource (must be of whitelisted MIME type)
  • Width in pixels
  • Height in pixels
  • Output filetype (png / jpg / gif / webp, whatever is supported)

Add an Endpoint in the server/plugins directory.

When the endpoint receives a request, it checks its store (either a Tree in sled or a folder on the filesystem) if the file (probably with some deterministic identifier, such as {resource}-{width}-{height}.{extension}) exists. If yes, it will be returned to the user. If not, it will be created and stored, and then returned to the user.

As a dynamic Class plugin

  • Use uploads a File to upload endpoint
  • Server recognizes this, creates an Image instead of a File
  • Requesting this file with query parameters will change the type of response. You can set dimensions in the Query params to get a resized image.

Libraries

  • The photon library looks pretty sweet.

joepio avatar Dec 23 '21 13:12 joepio