I’ve got a Ghost blog that uses the built-in Unsplash image selector. The problem is that it is terribly inefficient since it always loads pics at least 1080px wide (even for small thumbnails). I’d like to fix that in one of two ways:
Update the img_url handlebar helper to add dedicated support for Unsplash images (replace/add query string for responsive size (w=1080, h=480, etc.)
Add a custom handlebar helper to correctly size and attribute unsplash images. This is preferred but I don’t know if there is a standard way to add new handlebar helpers (that includes JS, not just template partials).
Please let me know if there have been decisions and/or discussions already made around this. I am more than happy to implement this myself, I just want to make sure it “fits in” correctly.
That’s a great idea, Jim! We already have image_sizes in package.json. It would be great if {{img_url feature_image size="s"}} generated an Unsplash image URL with w=480 parameter for example.
Exactly! It would be easy to use if it’s built into the img_url helper, but I also understand that architecturally it might be better to split it out. I’m happy to start a pull request for it, I just want some guidance from a Ghost dev before starting down a path.
I just came here to make the exact same suggestion, so I’m glad I remembered to search first.
I love the convenience of the Unsplash integration, but because img_url helper treats all external image URLs equally:
// CASE: if you pass an external image, there is nothing we want to do to it!
const isInternalImage = detectInternalImage(requestedImageUrl);
if (!isInternalImage) {
return requestedImageUrl;
}
… it results in the responsive image markup requesting 2000px-wide images from Unsplash for all of the supposedly responsive sizes in the srcset, like this example:
I’ve now resorted to searching for images on Unsplash’s site, downloading them and uploading to my blog, as they’re then treated properly for responsive sizing… and if you use more than a couple of Unsplash feature images on the home page, it’s a massive saving in page weight.
Given that the Unsplash URLs support sizing via the w=2000 parameter, I’m hoping it should be feasible to add another case to the {img_url} helper logic, to support multiple sizes for Unsplash URLs in a similar way to how internal images are handled?
Yep, that’s exactly what I’d like to do, but time is extremely limited for me at the moment. I might have time this weekend to create a branch and start implementing/testing it, but I can’t promise anything.
That would be great if you manage to find the time @jimbuck!
In the meantime, the manual upload workaround works fine. This is very much a ‘best of both worlds’ enhancement, but the convenience of the slick Unsplash integration (and the image weight saving of responsive images) makes it worth pursuing, I think.