rolandstarke/laravel-thumbnail

Laravel Thumbnail generator

v1.0.8 2023-11-04 14:16 UTC

This package is auto-updated.

Last update: 2024-12-16 00:27:39 UTC


README

Build PHP Version Latest Stable Version LICENSE

image image resized

<img src="{{ Storage::disk('public')->url('desert.jpg') }}">
<!-- <img src="/storage/desert.jpg"> -->

<img src="{{ Thumbnail::src('desert.jpg', 'public')->smartcrop(200, 200)->url() }}">
<!-- <img src="/storage/jhf47.jpg?src=desert.jpg&smartcrop=200x200"> -->

Laravel package to resize images with specially formatted URLs.

  • Generates the URL without touching the filesystem.
  • Rendered thumbnails are stored and subsequent requests are directly served from your nginx/apache.
  • The URL is signed to prevent malicious parameters.

Getting Started

Requirements

  • GD Library or Imagick
  • php >= 7.1.3
  • laravel >= 5.5

Installation

To install the most recent version with composer run the following command.

composer require rolandstarke/laravel-thumbnail

Usage

<img src="{{ Thumbnail::src($path)->crop(64, 64)->url() }}" />


<?php
    //load image from dir
    \Thumbnail::src(public_path('images/example.jpeg'));

    //load image from Storage::disk('local')
    \Thumbnail::src('userimage.jpg', 'local' /* disk */);

    //load image from website
    \Thumbnail::src('https://picsum.photos/200');
?>

Checkout the docs for more examples.

Configuration

Publish the configuration file with the following command.

php artisan vendor:publish --tag=thumbnail-config

The configuration file is located at config/thumbnail.php. Read here what you can configure.

Commands

Deletes the generated thumbnails.

php artisan thumbnail:purge

Tests

php vendor/bin/phpunit

License

MIT