Thumbnail

Introduction

The Post Thumbnails are images that are chosen as the representative for the post.

Registering own thumbnails allows for creating additional images sizes, beyond those shipped with WordPress.

Basics of thumbnails

All application thumbnails should be defined inside app\Support\thumbnails.php file. This file is included on application bootstrap by the App\Providers\AppServiceProvider class.

Creating thumbnail

Call create method on Thumbnail facade and pass desired image sizes in arguments.

Thumbnail::create('hero', [
    'size' => [800, 600]
]);

Arguments

Create method accepts options as the second argument.

Thumbnail::create('hero', [
    'title' => ['Hero image'],
    'crop' => false,
]);
Image Cropping

The crop argument changes how the images are resized. More about different cropping options you can read in Codex.

List of available options:
Option name Default value Description
title [] Array of titles, where the first element is a singular variant, second a plural
crop false Cropping behavior for the image.
size [800, 600] Array of image dimensions (width × height).

Getting thumbnail

You can get thumbnail instance with get method.

Thumbnail::get('hero');

Removing thumbnail

Call remove method on the desired thumbnail instance to remove previously created thumbnail size.

Thumbnail::get('hero')->remove();