Skip to content

Image endpoint (resize, crop) #257

Closed
@joepio

Description

@joepio

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions