diff --git a/README.md b/README.md index cc40ca7..0ea2d6a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ ![Laravel Thumbnails](https://github.com/pratiksh404/laravel-thumbnails/blob/master/img/laravel-thumbnail.png) -[![Issues](https://img.shields.io/github/issues/pratiksh404/laravel-thumbnails)](https://github.com/pratiksh404/laravel-thumbnails/issues) -[![Stars](https://img.shields.io/github/stars/pratiksh404/laravel-thumbnails)](https://github.com/pratiksh404/laravel-thumbnails/stargazers) +[![Issues](https://img.shields.io/github/issues/pratiksh404/laravel-thumbnails)](https://github.com/pratiksh404/laravel-thumbnails/issues) [![Stars](https://img.shields.io/github/stars/pratiksh404/laravel-thumbnails)](https://github.com/pratiksh404/laravel-thumbnails/stargazers) [![Latest Stable Version](https://poser.pugx.org/drh2so4/thumbnail/v)](//packagist.org/packages/drh2so4/thumbnail) [![Total Downloads](https://poser.pugx.org/drh2so4/thumbnail/downloads)](//packagist.org/packages/drh2so4/thumbnail) [![License](https://poser.pugx.org/drh2so4/thumbnail/license)](//packagist.org/packages/drh2so4/thumbnail) ## Laravel Thumbnail Generator @@ -79,23 +78,100 @@ What about thumbnail... well thumbnail uses it's parent image name followed by -size i.e batman-1521549-medium-jpg, batman-1521549-small.jpg +## How to make thumbnail ? + +There are the options you can have for making thumbnails :- + +- Default Option +- Universal Custom Thumbnails +- Specfic Custom Thumbnails + +### Default Option + +you can just call the following and the packages will handle the rest + +```sh + + $image->makeThumbnail('image'); //Here the first parameter is image attribute name saved in db + +``` + +Note : if the attribute dedicated for storing image is named 'image' you don't have to pass image attribute name jusr use \$image->makeThumbnail(); + +### Universal Custom Thumbnails + +here you should mention the thumbnails that you want to be applied on every case. +when you publish thumbnail.php config file you will find 'thumbnails' property where you can mention your custom thumbnails + +```sh + /* + |-------------------------------------------------------------------------- + | Custom Thumbnail Creation + |-------------------------------------------------------------------------- + | Uncomment to create... + */ + + /* "thumbnails" => [ + [ + "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 + +Suppose you have applied Universal Custom Thumbnails but need to have changes for specific image field then you can pass array of custom requirements : + +```sh + $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 to use thumbnail ? Just call as following ```sh +// 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 + // For small thumbnail + // For medium thumbnail @endforeach ``` if you are using custom thumbnail configured from config file just call as follows ```sh +// 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 + // For small thumbnail + // For medium thumbnail @endforeach ``` @@ -120,7 +196,7 @@ return [ | Thumbnail Feature |-------------------------------------------------------------------------- | - | This option defines whether to use Package's Thumbnail Featured or not + | This option defines whether to use Package's Thumbnail feature or not | Default option is true | */ @@ -176,7 +252,6 @@ return [ | Custom Thumbnail Creation |-------------------------------------------------------------------------- | Uncomment to create... - | */ /* "thumbnails" => [ @@ -191,16 +266,17 @@ return [ "thumbnail-width" => 400, "thumbnail-height" => 300, "thumbnail-quality" => 30 - ] - ] */ - + ], + "thumbnails_storage" => "uploads", + ] */ ]; + ``` Feel free to change the values -## Thumbnail +## Default Thumbnail Image Properties | Thumbnail | Width | Height | Quality | | ---------------- | ----- | ------ | ------- | @@ -208,14 +284,12 @@ Feel free to change the values | Medium Thumbnail | 800 | 600 | 60 | | Small Thumbnail | 400 | 300 | 30 | -Don't worry..working on making these thumbnail dynamic.. Stay tuned xoxo. - ![Laravel Thumbnails](https://github.com/pratiksh404/laravel-thumbnails/blob/master/img/thumbnails.png) ### Todos -- Dyanmic Thumbnail Categories -- More Functionality +- Error Handling +- Image Caching - Maintainabilty ## Package Used @@ -226,4 +300,4 @@ Don't worry..working on making these thumbnail dynamic.. Stay tuned xoxo. MIT -**DOCTYPE NEPAL ||DR.H2SO4** +**DOCTYPE NEPAL || DR.H2SO4** diff --git a/config/thumbnail.php b/config/thumbnail.php index eacf13b..f06a33e 100644 --- a/config/thumbnail.php +++ b/config/thumbnail.php @@ -78,7 +78,7 @@ "thumbnail-width" => 400, "thumbnail-height" => 300, "thumbnail-quality" => 30 - ] - ] */ - + ], + "thumbnails_storage" => "uploads", + ] */ ]; diff --git a/src/Traits/thumbnail.php b/src/Traits/thumbnail.php index 478dfb9..ed3d24d 100644 --- a/src/Traits/thumbnail.php +++ b/src/Traits/thumbnail.php @@ -34,11 +34,12 @@ public function makeThumbnail($fieldname = "image", $custom = []) if (config('thumbnail.thumbnail', true)) { $thumbnails = false; $thumbnails = $custom['thumbnails'] ?? config('thumbnail.thumbnails', false) ?? false; + $storage = $custom['storage'] ?? config('thumbnail.thumbnails_storage', false) ?? false; if ($thumbnails) { /* --------------------------------Custom Thumbnails------------------------------------------------- */ foreach ($thumbnails as $thumbnail) { $customthumbnail = $imageStoreNameOnly . '-' . $thumbnail['thumbnail-name'] . '.' . $extension; // Making Thumbnail Name - $custom_thumbnail = request()->file($fieldname)->storeAs($custom['storage'] ?? config("thumbnail.storage_path", "upload"), $customthumbnail, 'public'); // Thumbnail Storage Information + $custom_thumbnail = request()->file($fieldname)->storeAs($storage ?? config("thumbnail.storage_path", "uploads"), $customthumbnail, 'public'); // Thumbnail Storage Information $make_custom_thumbnail = Image::make(request()->file($fieldname)->getRealPath())->fit($thumbnail['thumbnail-width'], $thumbnail['thumbnail-height']); //Storing Thumbnail $make_custom_thumbnail->save(public_path('storage/' . $custom_thumbnail), $thumbnail['thumbnail-quality']); //Storing Thumbnail } @@ -51,8 +52,8 @@ public function makeThumbnail($fieldname = "image", $custom = []) //medium thumbnail name $mediumthumbnail = $imageStoreNameOnly . '-medium' . '.' . $extension; // Making Thumbnail Name - $small_thumbnail = request()->file($fieldname)->storeAs(config("thumbnail.storage_path", "upload"), $smallthumbnail, 'public'); // Thumbnail Storage Information - $medium_thumbnail = request()->file($fieldname)->storeAs(config("thumbnail.storage_path", "upload"), $mediumthumbnail, 'public'); // Thumbnail Storage Information + $small_thumbnail = request()->file($fieldname)->storeAs(config("thumbnail.storage_path", "uploads"), $smallthumbnail, 'public'); // Thumbnail Storage Information + $medium_thumbnail = request()->file($fieldname)->storeAs(config("thumbnail.storage_path", "uploads"), $mediumthumbnail, 'public'); // Thumbnail Storage Information /* --------------------------------- Saving Thumbnail------------------------------------ */