PHP code example of shishima / laravel-thumbnail

1. Go to this page and download the library: Download shishima/laravel-thumbnail library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shishima / laravel-thumbnail example snippets


'ignore_extensions' => ['png', 'jpg']

use Shishima\Thumbnail\Facade\Thumbnail;

Thumbnail::setFile($file)->create();

use Shishima\Thumbnail\Facade\Thumbnail;

$file = public_path('files/example.docx');
Thumbnail::setFile($file)->create();

use Shishima\Thumbnail\Facade\Thumbnail;

Thumbnail::setFile($request->file('file'))->create();

Thumbnail::create($file);

[
    'name' => 'thumbnail_name',
    'origin_name' => 'thumbnail_origin_name'
    'path' => 'path to file'
]

Thumbnail::setHeight(100)->create($file);

Thumbnail::setWidth(100)->create($file);

Thumbnail::setSize(width: 200, height: 200)->create($file);

Thumbnail::setFormat('png')->create($file);

Thumbnail::setLayer(20)->create($file);

$options = [
        'width' => 200,
        'height' => 200,
        'format' => 'png',
        'layer' => 20
    ];
Thumbnail::setOptions($options)->create($file);

Thumbnail::doNotRemoveTempFileAfterConvert()->create($file);

Thumbnail::shouldRemoveTempFileAfterConvert()->create($file);

use Shishima\Thumbnail\HasThumbnail;

class Document extends Models
{
    use HasThumbnail;
    //
}

protected static string $thumbnailEventTriggerColumn = 'file_path';

protected static function getDiskOfFileUploaded(): string
{
    return 'local_public';
}

protected static $thumbnailEvents = ['saved'];

protected static $doNotCreateThumbnail = true;

protected static array $thumbnailOptions = [
    'height' => 200,
    'width' => 200,
    'format' => 'png',
    'layer' => 12
];

protected static function thumbnailSaveData($thumbnail, $file, $model): array
{
    return [
        'name' => 'custom_name',
    ];
}

protected static function thumbnailSaveData($thumbnail, $file, $model): array
{
    $mime = $file->getMimeType();
    return [
        'name' => 'custom_name',
        'mime' => $mime
    ];
}

protected static function thumbnailCustomSave($thumbnail, $file, $model)
    {
        $model->thumbnail = $thumbnail['path'];
        $model->saveQuietly();
        
        // Or
        // CustomModelThumbnail::insert($data);
    }

protected static bool $thumbnailUpdateWillOverwrite = true;