sanity-io / sanity-plugin-asset-source-unsplash

Search photos on Unsplash and use them directly inside of your Sanity Studio.
MIT License
17 stars 5 forks source link

How to change stored image size pulled from Unsplash? #93

Open alextenczar opened 1 year ago

alextenczar commented 1 year ago

Hey, I'm wondering if there's any way to default to using one of the smaller image sizes for the selected image that's stored on Sanity. Many of the images I select are way too large and it results in a large asset (4+ MB). It would be awesome to select one of the other image size urls provided by the Unsplash API:

 "urls": {
    "raw": "https://images.unsplash.com/photo-1472289065668-ce650ac443d2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEwMDg3MX0",
    "full": "https://images.unsplash.com/photo-1472289065668-ce650ac443d2?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjEwMDg3MX0",
    "regular": "https://images.unsplash.com/photo-1472289065668-ce650ac443d2?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwMDg3MX0",
    "small": "https://images.unsplash.com/photo-1472289065668-ce650ac443d2?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjEwMDg3MX0",
    "thumb": "https://images.unsplash.com/photo-1472289065668-ce650ac443d2?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjEwMDg3MX0"
  },

any guidance in this would be appreciated. Thank you!

LeoMacherla commented 1 year ago

+1 I came here looking for a way to do this too!

LeoMacherla commented 1 year ago

I've just realised that a potential solution could be to add a URL parameter on the end of the image URL to request a smaller image from Sanity. See here: https://www.sanity.io/docs/image-urls

So you could append '?h=200' to the end of the URL and Sanity would return the image with a height of 200 pixels.

This seems like a nice solution as it allows you to keep the full resolution images stored in Sanity, however, it would still use up more storage on your Sanity account