Thumbnail Creation and Filename Outputs

Hello,
I was wondering if someone could help me out?

I’ve created a template that loads image thumbnail URLs using the default out. eg. thumb($file, array(‘width’ => 90, ‘height’ => 100, ‘crop’ => true))->url()

This works perfectly for me.

The problem I am having is that when I re-order the pages the thumbnails appear to regenerate. This causes the page to take longer to load. Can anyone confirm if this is the correct behaviour?

Secondly, is it possible to remove the md5 from the thumbnail file outputs?

Thanks for your help in advance!

As regards your 2nd question, yes, you can using the filename option:

<?php
thumb($image, array('filename' => '{safeName}.{extension}', 'width' => 300))->url() ?>

[Edit:] I’m not sure this is a good idea, because then you won`t be able to generate differently sized thumbs.

Thanks texnixe, that worked great.

I hear your point regarding different sizes so I slightly modified your suggestion by adding -{width} to the safename. In full I have the following.

<?php thumb($file, array('filename' => '{safeName}-{width}.{extension}', 'width' => 220, 'height' => 240, 'crop' => true))->url(); ?>

As for my other question, I can’t replicate the problem at the moment so I’ll have to come back to it!

Thanks again for your help! You saved me plenty of time!

Just keep in mind that the hash is created like this:

'hash'         => md5($this->source->root() . $this->settingsIdentifier())

And the settingsIdentifier in turn contains the options:

public function settingsIdentifier() {

    // build the settings string
    return implode('-', array(
      ($this->options['width'])   ? $this->options['width']   : 0,
      ($this->options['height'])  ? $this->options['height']  : 0,
      ($this->options['upscale']) ? $this->options['upscale'] : 0,
      ($this->options['crop'])    ? $this->options['crop']    : 0,
       $this->options['blur'],
       $this->options['grayscale'],
       $this->options['quality']
    ));

  }
1 Like

With regards to speed improvements, I like to use $thumb->dataUri() whenever possible to save an HTTP request. Turn on caching as well, and you’ll notice a huge speed boost.

1 Like

Great! Thanks for the tip I’ll try it out.

Maybe you solved it already but you can read about how you can resize images on your own here:

http://forum.getkirby.com/t/resize-images-to-thumbnails/1237