It compresses thumbnails with TinyPNG generated with Kirby CMS.
Copy the plugin files to site/plugins
.
Download cacert.pem and add it to site/plugins/tiny-thumb/
.
Add c::set('tinypngKey', 'Your_TinyPNG_API_Key');
to your config file with your tinypng API key.
Replace your thumb()
function with the tinyThumb()
function, like this:
echo tinyThumb( $page->image( '1.png' ), array( 'width' => 300 ) );
You can get data from it, with the same functions as the thumb()
like this:
$thumb = tinyThumb( $page->image( '1.png' ), array( 'width' => 300 ) );
echo $thumb->width();
You can get data from the original thumb()
like this:
$thumb = tinyThumb( $page->image( '1.png' ), array( 'width' => 300 ) )->thumb();
echo $thumb->filename();
You can get data from the original image()
like this:
$thumb = tinyThumb( $page->image( '1.png' ), array( 'width' => 300 ) )->image();
echo $image->filename();
It uses the same arguments as the built in thumb() function.
When a file is not compressed, it will try again the next time the page loads. It will fallback to show the original thumbnail if the compressed one could not be generated. That way it will always show an image to the visitor.
If a page loads and the thumbnail has already been compressed, it will not be compressed again on each page load, only the first time.
It simply check if the compressed file already exist or not.
If the thumbs.filename
or the thumbs folder path is changed in the config, this plugin will respect your setting and work with them.
Initial release
- Prefix config to change "-min" that is added to compressed files
- Add a similar plugin for images,
tinyImage()
- Bug reports with detailed information how to reproduce the issue
- Code or suggestions on code improvements
- Requested features
- Feedback