Skip to content

Commit f8a0286

Browse files
committed
v_1.0.1
1 parent f53649f commit f8a0286

File tree

3 files changed

+98
-23
lines changed

3 files changed

+98
-23
lines changed

README.md

Lines changed: 91 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
![Laravel Thumbnails](https://github.com/pratiksh404/laravel-thumbnails/blob/master/img/laravel-thumbnail.png)
22

3-
[![Issues](https://img.shields.io/github/issues/pratiksh404/laravel-thumbnails)](https://github.com/pratiksh404/laravel-thumbnails/issues)
4-
[![Stars](https://img.shields.io/github/stars/pratiksh404/laravel-thumbnails)](https://github.com/pratiksh404/laravel-thumbnails/stargazers)
3+
[![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)
54

65
## Laravel Thumbnail Generator
76

@@ -79,23 +78,100 @@ What about thumbnail...
7978
well thumbnail uses it's parent image name followed by -size
8079
i.e batman-1521549-medium-jpg, batman-1521549-small.jpg
8180

81+
## How to make thumbnail ?
82+
83+
There are the options you can have for making thumbnails :-
84+
85+
- Default Option
86+
- Universal Custom Thumbnails
87+
- Specfic Custom Thumbnails
88+
89+
### Default Option
90+
91+
you can just call the following and the packages will handle the rest
92+
93+
```sh
94+
95+
$image->makeThumbnail('image'); //Here the first parameter is image attribute name saved in db
96+
97+
```
98+
99+
Note : if the attribute dedicated for storing image is named 'image' you don't have to pass image attribute name jusr use \$image->makeThumbnail();
100+
101+
### Universal Custom Thumbnails
102+
103+
here you should mention the thumbnails that you want to be applied on every case.
104+
when you publish thumbnail.php config file you will find 'thumbnails' property where you can mention your custom thumbnails
105+
106+
```sh
107+
/*
108+
|--------------------------------------------------------------------------
109+
| Custom Thumbnail Creation
110+
|--------------------------------------------------------------------------
111+
| Uncomment to create...
112+
*/
113+
114+
/* "thumbnails" => [
115+
[
116+
"thumbnail-name" => "medium",
117+
"thumbnail-width" => 800,
118+
"thumbnail-height" => 600,
119+
"thumbnail-quality" => 60
120+
],
121+
[
122+
"thumbnail-name" => "small",
123+
"thumbnail-width" => 400,
124+
"thumbnail-height" => 300,
125+
"thumbnail-quality" => 30
126+
]
127+
] */
128+
```
129+
130+
Note: This will override default option
131+
132+
### Specfic Custom Thumbnails
133+
134+
Suppose you have applied Universal Custom Thumbnails but need to have changes for specific image field then you can pass array of custom requirements :
135+
136+
```sh
137+
$thumbnails = [
138+
'storage' => 'customs/embed',
139+
'width' => '600',
140+
'height' => '400',
141+
'quality' => '70',
142+
'thumbnails' => [
143+
[
144+
'thumbnail-name' => 'customSmall',
145+
'thumbnail-width' => '300',
146+
'thumbnail-height' => '200',
147+
'thumbnail-quality' => '50'
148+
]
149+
]
150+
];
151+
$image->makeThumbnail('image', $thumbnails);
152+
```
153+
82154
## How to use thumbnail ?
83155
84156
Just call as following
85157
86158
```sh
159+
// Here the first parameter 'image' is the name of sttribute that is saved in db for image
160+
87161
@foreach ($images as $image)
88-
<img src="{{asset($image->thumbnail('small'))}}"> // For small thumbnail
89-
<img src="{{asset($image->thumbnail('medium'))}}"> // For medium thumbnail
162+
<img src="{{asset($image->thumbnail('image','small'))}}"> // For small thumbnail
163+
<img src="{{asset($image->thumbnail('image','medium'))}}"> // For medium thumbnail
90164
@endforeach
91165
```
92166
93167
if you are using custom thumbnail configured from config file just call as follows
94168
95169
```sh
170+
// Here the first parameter 'image' is the name of sttribute that is saved in db for image
171+
// Second parameter is the name of thumbnail that you gave in 'thumbnail-name' in the config file on custom thumbnail field called 'thumbnails'
96172
@foreach ($images as $image)
97-
<img src="{{asset($image->thumbnail('test-small'))}}"> // For small thumbnail
98-
<img src="{{asset($image->thumbnail('test-medium'))}}"> // For medium thumbnail
173+
<img src="{{asset($image->thumbnail('image','small'))}}"> // For small thumbnail
174+
<img src="{{asset($image->thumbnail('image','medium'))}}"> // For medium thumbnail
99175
@endforeach
100176
```
101177
@@ -120,7 +196,7 @@ return [
120196
| Thumbnail Feature
121197
|--------------------------------------------------------------------------
122198
|
123-
| This option defines whether to use Package's Thumbnail Featured or not
199+
| This option defines whether to use Package's Thumbnail feature or not
124200
| Default option is true
125201
|
126202
*/
@@ -176,7 +252,6 @@ return [
176252
| Custom Thumbnail Creation
177253
|--------------------------------------------------------------------------
178254
| Uncomment to create...
179-
|
180255
*/
181256

182257
/* "thumbnails" => [
@@ -191,31 +266,30 @@ return [
191266
"thumbnail-width" => 400,
192267
"thumbnail-height" => 300,
193268
"thumbnail-quality" => 30
194-
]
195-
] */
196-
269+
],
270+
"thumbnails_storage" => "uploads",
271+
] */
197272
];
198273

274+
199275
```
200276
201277
Feel free to change the values
202278
203-
## Thumbnail
279+
## Default Thumbnail Image Properties
204280
205281
| Thumbnail | Width | Height | Quality |
206282
| ---------------- | ----- | ------ | ------- |
207283
| Uploaded Image | 1000 | 800 | 80 |
208284
| Medium Thumbnail | 800 | 600 | 60 |
209285
| Small Thumbnail | 400 | 300 | 30 |
210286
211-
Don't worry..working on making these thumbnail dynamic.. Stay tuned xoxo.
212-
213287
![Laravel Thumbnails](https://github.com/pratiksh404/laravel-thumbnails/blob/master/img/thumbnails.png)
214288
215289
### Todos
216290
217-
- Dyanmic Thumbnail Categories
218-
- More Functionality
291+
- Error Handling
292+
- Image Caching
219293
- Maintainabilty
220294
221295
## Package Used
@@ -226,4 +300,4 @@ Don't worry..working on making these thumbnail dynamic.. Stay tuned xoxo.
226300
227301
MIT
228302
229-
**DOCTYPE NEPAL ||DR.H2SO4**
303+
**DOCTYPE NEPAL || DR.H2SO4**

config/thumbnail.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"thumbnail-width" => 400,
7979
"thumbnail-height" => 300,
8080
"thumbnail-quality" => 30
81-
]
82-
] */
83-
81+
],
82+
"thumbnails_storage" => "uploads",
83+
] */
8484
];

src/Traits/thumbnail.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ public function makeThumbnail($fieldname = "image", $custom = [])
3434
if (config('thumbnail.thumbnail', true)) {
3535
$thumbnails = false;
3636
$thumbnails = $custom['thumbnails'] ?? config('thumbnail.thumbnails', false) ?? false;
37+
$storage = $custom['storage'] ?? config('thumbnail.thumbnails_storage', false) ?? false;
3738
if ($thumbnails) {
3839
/* --------------------------------Custom Thumbnails------------------------------------------------- */
3940
foreach ($thumbnails as $thumbnail) {
4041
$customthumbnail = $imageStoreNameOnly . '-' . $thumbnail['thumbnail-name'] . '.' . $extension; // Making Thumbnail Name
41-
$custom_thumbnail = request()->file($fieldname)->storeAs($custom['storage'] ?? config("thumbnail.storage_path", "upload"), $customthumbnail, 'public'); // Thumbnail Storage Information
42+
$custom_thumbnail = request()->file($fieldname)->storeAs($storage ?? config("thumbnail.storage_path", "uploads"), $customthumbnail, 'public'); // Thumbnail Storage Information
4243
$make_custom_thumbnail = Image::make(request()->file($fieldname)->getRealPath())->fit($thumbnail['thumbnail-width'], $thumbnail['thumbnail-height']); //Storing Thumbnail
4344
$make_custom_thumbnail->save(public_path('storage/' . $custom_thumbnail), $thumbnail['thumbnail-quality']); //Storing Thumbnail
4445
}
@@ -51,8 +52,8 @@ public function makeThumbnail($fieldname = "image", $custom = [])
5152
//medium thumbnail name
5253
$mediumthumbnail = $imageStoreNameOnly . '-medium' . '.' . $extension; // Making Thumbnail Name
5354

54-
$small_thumbnail = request()->file($fieldname)->storeAs(config("thumbnail.storage_path", "upload"), $smallthumbnail, 'public'); // Thumbnail Storage Information
55-
$medium_thumbnail = request()->file($fieldname)->storeAs(config("thumbnail.storage_path", "upload"), $mediumthumbnail, 'public'); // Thumbnail Storage Information
55+
$small_thumbnail = request()->file($fieldname)->storeAs(config("thumbnail.storage_path", "uploads"), $smallthumbnail, 'public'); // Thumbnail Storage Information
56+
$medium_thumbnail = request()->file($fieldname)->storeAs(config("thumbnail.storage_path", "uploads"), $mediumthumbnail, 'public'); // Thumbnail Storage Information
5657

5758
/* --------------------------------- Saving Thumbnail------------------------------------ */
5859

0 commit comments

Comments
 (0)