Skip to content

Commit

Permalink
v_1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pratiksh404 committed Jul 28, 2020
1 parent f53649f commit f8a0286
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 23 deletions.
108 changes: 91 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
<img src="{{asset($image->thumbnail('small'))}}"> // For small thumbnail
<img src="{{asset($image->thumbnail('medium'))}}"> // For medium thumbnail
<img src="{{asset($image->thumbnail('image','small'))}}"> // For small thumbnail
<img src="{{asset($image->thumbnail('image','medium'))}}"> // 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)
<img src="{{asset($image->thumbnail('test-small'))}}"> // For small thumbnail
<img src="{{asset($image->thumbnail('test-medium'))}}"> // For medium thumbnail
<img src="{{asset($image->thumbnail('image','small'))}}"> // For small thumbnail
<img src="{{asset($image->thumbnail('image','medium'))}}"> // For medium thumbnail
@endforeach
```
Expand All @@ -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
|
*/
Expand Down Expand Up @@ -176,7 +252,6 @@ return [
| Custom Thumbnail Creation
|--------------------------------------------------------------------------
| Uncomment to create...
|
*/

/* "thumbnails" => [
Expand All @@ -191,31 +266,30 @@ 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 |
| ---------------- | ----- | ------ | ------- |
| Uploaded Image | 1000 | 800 | 80 |
| 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
Expand All @@ -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**
6 changes: 3 additions & 3 deletions config/thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"thumbnail-width" => 400,
"thumbnail-height" => 300,
"thumbnail-quality" => 30
]
] */

],
"thumbnails_storage" => "uploads",
] */
];
7 changes: 4 additions & 3 deletions src/Traits/thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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------------------------------------ */

Expand Down

0 comments on commit f8a0286

Please sign in to comment.