Code Monkey home page Code Monkey logo

laravel-thumbnail's Introduction

Laravel Thumbnail

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

laravel-thumbnail's People

Contributors

rolandstarke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-thumbnail's Issues

Update to php 8

Please can you update your composer.json to allow php 8:

"require": {
        "php": "^7.1.3|^8.0",
        "intervention/image": "^2.0"
    },

Port for path

I use a port for my website, so how can I configure that in thumbnail?

Folder no exist

{{ Thumbnail::src(public_path($photo->path))->smartcrop(200, 200)->url() }} - return path. But folder "thumbnails" not created

Relative URL

How can I configure the package to generate relative urls?

Source is not allowed. Given path

Source is not allowed. Given path error given when trying to generate thumbnail.

src="{{\Thumbnail::src(storage_path('public/'.$pnews->primary_img)) }}"

FR: Support FILESYSTEM_CLOUD as an alternate to $disk

I am using FILESYSTEM_CLOUD in .env to decouple the cloud disk driver from my application.

For example, instead of Storage::disk('spaces') I can do this: Storage::cloud() which allows me to easily swap out the disk by changing one line in the .env file.

Currently to achieve this with laravel-thumbnail I am doing this:

    'allowedSources' => [
        'cloud' => ['disk' => env('FILESYSTEM_CLOUD', 'local'), 'path' => '/'],
    ],

    'presets' => [
        'cloud' => [
            'destination' => ['disk' => env('FILESYSTEM_CLOUD', 'local'), 'path' => '/thumbnails/default/'],
            'smartcrop' => '256x256',
        ],
    ],

And using it like this:

$data = Thumbnail::preset('cloud')->src($path, config('filesystems.cloud'))->string(true);

Would be awesome if I could do something like this instead:

    'allowedSources' => [
        'cloud' => ['cloud' => true, 'path' => '/'],
    ],

    'presets' => [
        'cloud' => [
            'destination' => ['cloud' => true, 'path' => '/thumbnails/default/'],
            'smartcrop' => '256x256',
        ],
    ],
$data = Thumbnail::preset('cloud')->cloud()->src($path)->string(true);

Delete single thumbnail

How should i delete single thumbnail ? if the src picture updates the old thumbnail is cached.

Images not viewable for chmod permissions

Since I upgraded to Laravel 9 and PHP 8.1.5, I've noticed that it correctly creates thumbnails but they are not showing.

In checking the routes I noticed that:

/httpdocs/storage/crops/news/1z/yz
yz = 0700

towrmhfoogoog48ow4osc.jpg
0644
if I put permissions 0755 on folders and files the images will be viewable...

CDN Storage Thumbnail Creation Error

I found this packages by accident, and I already like it so much but I have a question. I have the original images in a DigitalOcean Spaces CDN called in Laravel's filesystem “do_spaces”.

So the image for example is:

\Thumbnail::src('projectx/article/00b9c8c0e4123c441353050cceafb173.jpg', 'do_spaces' );

How can I make him save me image in:

projectx/crops/.*

in config:

        'ld' => ['disk' => 'do_spaces', 'path' => 'projectx/'], //allow images to be loaded from `Storage::disk('local')`
        'pd' => ['disk' => 'do_spaces', 'path' => 'projectx/'],
            'destination' => ['disk' => 'do_spaces', 'path' => 'projectx/crops/'],

Blade:
{{ Thumbnail::src('projectx/article/00b9c8c0e4123c441353050cceafb173.jpg', 'do_spaces')->url() }}

but when the url is generated in the blade:

https://***.ams3.digitaloceanspaces.com/projectx/crops/db9/ag5cy0kooo40w4g4go0so8.jpg%3Fp%3Darticle%252F00b9c8c0e4123c441353050cceafb173.jpg%26s%3Dld

and the image does not exist, where am I wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.