Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image endpoint (resize, crop) #257

Closed
joepio opened this issue Dec 23, 2021 · 0 comments · Fixed by #930
Closed

Image endpoint (resize, crop) #257

joepio opened this issue Dec 23, 2021 · 0 comments · Fixed by #930
Assignees

Comments

@joepio
Copy link
Member

joepio commented Dec 23, 2021

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants