PHPackages                             drh2so4/thumbnail - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. drh2so4/thumbnail

ActiveLibrary[Image &amp; Media](/categories/media)

drh2so4/thumbnail
=================

Package for making thumbnails instantly.

v1.0.9(4y ago)5635.3k—8.7%4[1 issues](https://github.com/pratiksh404/laravel-thumbnails/issues)3MITPHP

Since Jun 12Pushed 4y ago2 watchersCompare

[ Source](https://github.com/pratiksh404/laravel-thumbnails)[ Packagist](https://packagist.org/packages/drh2so4/thumbnail)[ RSS](/packages/drh2so4-thumbnail/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (3)Versions (17)Used By (3)

[![Laravel Thumbnails](https://github.com/pratiksh404/laravel-thumbnails/raw/master/img/laravel-thumbnail.png)](https://github.com/pratiksh404/laravel-thumbnails/blob/master/img/laravel-thumbnail.png)

[![Stars](https://camo.githubusercontent.com/442d38bb9888d87761c7270fb695f4c989c39227757cc06bd4fa84e22eebeb8f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f70726174696b73683430342f6c61726176656c2d7468756d626e61696c73)](https://github.com/pratiksh404/laravel-thumbnails/stargazers) [![Downloads](https://camo.githubusercontent.com/5c1fe1763fddaa3ed57c8e4b88e408c9fae4b1634f2475df64c7b920af150402/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64726832736f342f7468756d626e61696c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/drh2so4/thumbnail) [![StyleCI](https://camo.githubusercontent.com/7f710ec2e1cefae7377c882038a370c08d074d76126ad8ca64086d098c3b66f0/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3237303138313837392f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/270181879?branch=master) [![Build Status](https://camo.githubusercontent.com/e5affeb0283e77c9ff755c8d8e18882add9317d3813ca623bfb2bdd87f5425eb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70726174696b73683430342f6c61726176656c2d7468756d626e61696c732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/pratiksh404/laravel-thumbnails/build-status/master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/9acdcdf930bd70b659afdb65178d48c01da68e5c76b33d37935f0c0e975625c1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70726174696b73683430342f6c61726176656c2d7468756d626e61696c732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/pratiksh404/laravel-thumbnails/?branch=master) [![CodeFactor](https://camo.githubusercontent.com/b6ffb5e30d01632da64aae793c1dc38a6f2c4225b08652da116fbed092773216/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f70726174696b73683430342f6c61726176656c2d7468756d626e61696c732f6261646765)](https://www.codefactor.io/repository/github/pratiksh404/laravel-thumbnails) [![License](https://camo.githubusercontent.com/3b2e423634c4c443dc30ca18ba292da34eade90a8277bd0400bddfc65806796e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70726174696b73683430342f6c61726176656c2d7468756d626e61696c73)](//packagist.org/packages/drh2so4/thumbnail) [![Laravel News](https://camo.githubusercontent.com/071ffb6c1fec6ccd43e2850c9ba92b790542db9a12fbd06a11e569aa88ca9eff/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46656174757265642d4c61726176656c2532304e6577732d626c7565)](https://github.com/pratiksh404) [![MadeWithLaravel.com shield](https://camo.githubusercontent.com/2981cba980428053facfb7b01f9e6316c042758e9e3615e4a3dc9a6d04c43b91/68747470733a2f2f6d616465776974686c61726176656c2e636f6d2f73746f726167652f7265706f2d736869656c64732f323730392d736869656c642e737667)](https://madewithlaravel.com/p/laravel-thumbnail/shield-link)

Laravel Thumbnail Generator
---------------------------

[](#laravel-thumbnail-generator)

Package for uploading the image and saving that image along with it's thumbnail.

What does it do ?
-----------------

[](#what-does-it-do-)

- Uploads Image
- Make its thumbnail i.e low quality, resized version of its parent image

Why use thumbnails ?
--------------------

[](#why-use-thumbnails-)

The small file size of thumbnails makes it possible for website designers to offer visitors a lot of content immediately without increasing the loading time of the page. Also why use full glory of that image if you just have to crunched it up to tiny space... Use thumbnail.

### Installation

[](#installation)

Run Composer Require Command

```
$ composer require drh2so4/thumbnail
```

Use thumbnail trait to your model

```
 [
        [
            "thumbnail-name" => "medium",
            "thumbnail-width" => 800,
            "thumbnail-height" => 600,
            "thumbnail-quality" => 60
        ],
        [
            "thumbnail-name" => "small",
            "thumbnail-width" => 400,
            "thumbnail-height" => 300,
            "thumbnail-quality" => 30
        ]
    ] */
```

Note: This will override default option

### Specfic Custom Thumbnails

[](#specfic-custom-thumbnails)

Suppose you have applied Universal Custom Thumbnails but need to have changes for specific image field then you can pass array of custom requirements :

```
        $thumbnails = [
            'storage' => 'customs/embed',
            'width' => '600',
            'height' => '400',
            'quality' => '70',
            'thumbnails' => [
                [
                    'thumbnail-name' => 'customSmall',
                    'thumbnail-width' => '300',
                    'thumbnail-height' => '200',
                    'thumbnail-quality' => '50'
                ]
            ]
        ];
        $image->makeThumbnail('image', $thumbnails);
```

### How about multiple image uploads

[](#how-about-multiple-image-uploads)

If you are performing multiple image upload at once pass image key to thumbnail array. here $img is one of the image in chunk of images passed

```
// Controller Store Method
public function store(Request $request)
{
    $image = Image::create(['images'=>$request->images]);
    foreach($request->images as $img)
    {
        $this->multipleImageUpload($image,$img);
    }
}
// Multiple Image Upload
    private function multipleImageUpload($image, $img)
    {
        $multiple = [
            'storage' => 'custom_test/folder/another_folder/image',
            'width' => '600',
            'height' => '400',
            'quality' => '70',
            'image' => $img,
            'thumbnails' => [
                [
                    'thumbnail-name' => 'small',
                    'thumbnail-width' => '300',
                    'thumbnail-height' => '200',
                    'thumbnail-quality' => '50'
                ]
            ]
        ];
        $image->makeThumbnail('image', $multiple);
    }
```

How to use thumbnail ?
----------------------

[](#how-to-use-thumbnail-)

Just call as following

```
// Here the first parameter 'image' is the name of sttribute that is saved in db for image

    @foreach ($images as $image)
         // For small thumbnail
     // For medium thumbnail
    @endforeach
```

if you are using custom thumbnail configured from config file just call as follows

```
// Here the first parameter 'image' is the name of sttribute that is saved in db for image
// Second parameter is the name of thumbnail that you gave in 'thumbnail-name' in the config file on custom thumbnail field called 'thumbnails'
    @foreach ($images as $image)
         // For small thumbnail
     // For medium thumbnail
    @endforeach
```

Notice that parameter of function thumbnail is string same as value given for "thumbnail-name" in config file.

Thumbnail's image property is predefined but if you wish to change that publish it's config file thumbnail.php

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

### Image Property

[](#image-property)

You can obtaing the detail image property by using method imageDetail($image,$size)

```
// imageDetail method takes two parameter
// Model image attribute name (Mandatory)
// If you want thumbnail property pass its size (optional)

$image->imageDetail('image'); // Parent Image Detail Property
$image->imageDetail('image','small') // Small thumbnail related to parent image
```

### What Image Property/Detail Gives

[](#what-image-propertydetail-gives)

Default Thumbnail Image Properties
----------------------------------

[](#default-thumbnail-image-properties)

PropertyReturn TypeDescriptionExampleimagestringImage path stored in DB$image-&gt;imageDetail('image')-&gt;imagenamestringImage Stored Name (without extension)$image-&gt;imageDetail('image')-&gt;namefullnamestringImage Stored Name (with extension)$image-&gt;imageDetail('image')-&gt;fullnameextensionstringImage Extension Name$image-&gt;imageDetail('image')-&gt;extensionpathstringImage Storage Path$image-&gt;imageDetail('image')-&gt;pathdirectorystringImage Stored Directory$image-&gt;imageDetail('image')-&gt;directorylocationstringImage Full Location Path$image-&gt;imageDetail('image')-&gt;locationpropertyarrayImage Property array$image-&gt;imageDetail('image')-&gt;propertyImage Property array ($image-&gt;imageDetail('image')-&gt;property)

PropertyReturn TypeDescriptionExamplereal\_namestringImage Real Name (without timestamp and size label)$image-&gt;imageDetail('image')-&gt;property-&gt;namesizeintegerImage Storage Size$image-&gt;imageDetail('image')-&gt;property-&gt;fullnamedirectorystringImage Stored Directory$image-&gt;imageDetail('image')-&gt;property-&gt;directorylocationstringImage Full Location Path$image-&gt;imageDetail('image')-&gt;property-&gt;locationhas\_thumbnailbooleanImage's Thumbnail Check$image-&gt;imageDetail('image')-&gt;property-&gt;has\_thumbnailthumbnail\_countintegerImage Thumbnail Count$image-&gt;imageDetail('image')-&gt;property-&gt;thumbnail\_countthumbnailsarrayReturn all thumbnail Detail$image-&gt;imageDetail('image')-&gt;property-&gt;thumbnailsImage Thumbnail Property

PropertyReturn TypeDescriptionimagestringThumbnail Namereal\_namestringThumbnail Real Name (without timestamp and size label)sizeintegerThumbnail Storage Sizecreated\_dateCarbonThumbnail Created DatepathstringThumbnail Storage PathdirectorystringThumbnail Stored DirectorylocationstringThumbnail Full Location Path### Check if image has thumbnail

[](#check-if-image-has-thumbnail)

```
$image->hasThumbnail('image'); // Check for any availabe thumbnail
$image->hasThumbnail('image','small'); // Second paremater is thumbnail size check
```

### Obtain Image Thumbnail Count

[](#obtain-image-thumbnail-count)

```
$image->thumbnailCount('image');
```

### Hard Delete Image with Thumbnails

[](#hard-delete-image-with-thumbnails)

```
$image->hardDelete('image'); // First parameter is db attribute name for image
```

### Hard Delete Image with Thumbnails adn its parent

[](#hard-delete-image-with-thumbnails-adn-its-parent)

```
$image->hardDeleteWithParent('image'); // First parameter is db attribute name for image
```

### Upload Only Umage

[](#upload-only-umage)

```
$solo_image = [
                'storage' => 'solo',
                'width' => '600',
                'height' => '300',
                'quality' => '70',
            ];
            $image->uploadImage('image', $solo_image); // Second Parameter is not necessary if default settings is to be applied
            // OR
            $image->uploadImage('image'); // Image Upload with default setting
```

Our config file looks like follows :-

```
