Generate Thumbnails

The easiest way to generate ‘on the fly’ thumbnails is to use System\Models\File model in relation like :

public $attachMany = [
    'myimages' => ['System\Models\File']
];

Show a thumbnail

To access those images in your layout or partial, you can use the following code. We are using the .thumb(x,y, mode) function to generate the thumbnail.

{% for image in myobject.myimages %}
    <img src="{{ image.thumb(200, 200, 'auto') }}" title="{{ image.title }}" alt="{{ image.description }}">
{% endfor %}

You can set the mode to auto, exact, portrait, landscape or crop. Default: auto

Delete all thumbnails files

You can use the following command to delete all the thumbnails cache file

php artisan october:util purge thumbs

Posted in OctoberCMS on Sep 08, 2016