Pass suffix as option to $file->resize()

Hi ya’ll,

I’m in the process of migrating an existing passion project from a Handlebars/JSON-based static site generator to Kirby 3. It’s a lot of fun, not least thanks to the great documentation. :+1:t2:

I’m making good use of the resize() file helper to provide a srcset of responsive image renditions. Here’s the thing though: I opted for filename suffixes like image-small.jpg, image-medium.jpg or image-large.jpg for my renditions on the existing site and I have a few images that are ranked #1 or at least top 10 for choice search terms in Google Image Search. I’d be very sad to lose those rankings.

Is there a way to pass in a suffix to resize()? I’d be looking for something like $image->resize(1200, null, 80, 'large') to get image-large.jpg instead of image-1200x800-q80.jpg.

I’ve been looking at the docs entry for creating my own thumb generator, but that didn’t immediately enlighten me.

Thanks for helping!

Yes, I would’ve thought the thumbs generator would be the starting point, by modifying the $dst destination parameter (but haven’t tested this yet myself).

The resize() method doesn’t allow additional arguments.

Thank you! I’ll have another look then, although $dst - The root to the desired destination didn’t sound too promising.

Unfortunately, I’ve just realized thanks to Image URLs - How to remove string? that I have more changes to my image URLs than just the filename-suffix.

I’ll need to ponder on this.

Maybe redirecting old file URLs to their new home would be the better option in this case?

Maybe, but as far as I understood the feature, the “new home”-URLs with their iteration-specific hashed folder names don’t seem to be a very stable basis for 301 redirects.

As long as the original image itself doesn’t change, the URL to the image should remain intact.

With the new media API you always get the same URL no matter how the pages are sorted. URLs to files only change when the file itself is being modified.

Otherwise it wouldn’t make much sense for SEO.

This is how the hash is generated:

 public function mediaHash(): string
        return crc32($this->filename()) . '-' . $this->modified();

So as long as the filename and the modification date do not change, the hash will always be the same.