|
@@ -10,7 +10,7 @@ discard block |
|
|
block discarded – undo |
|
10
|
10
|
{ |
|
11
|
11
|
public function makeThumbnail($fieldname = 'image', $custom = []) |
|
12
|
12
|
{ |
|
13
|
|
- if (! empty(request()->$fieldname) || $custom['image']) { |
|
|
13
|
+ if (!empty(request()->$fieldname) || $custom['image']) { |
|
14
|
14
|
/* ------------------------------------------------------------------- */ |
|
15
|
15
|
|
|
16
|
16
|
$image_file = $custom['image'] ?? request()->file($fieldname); // Retriving Image File |
|
@@ -43,10 +43,10 @@ discard block |
|
|
block discarded – undo |
|
43
|
43
|
private function makeImg($image_file, $name, $location, $width, $height, $quality) |
|
44
|
44
|
{ |
|
45
|
45
|
$image = $image_file->storeAs($location, $name, 'public'); // Thumbnail Storage Information |
|
46
|
|
- $img = Image::cache(function ($cached_img) use ($image_file, $width, $height) { |
|
|
46
|
+ $img = Image::cache(function($cached_img) use ($image_file, $width, $height) { |
|
47
|
47
|
$baseImage = $cached_img->make($image_file->getRealPath()); |
|
48
|
48
|
if ($config('thumbnail.keep_aspect_ratio')) { |
|
49
|
|
- return $baseImage->resize($width, $height, function ($constraint) { |
|
|
49
|
+ return $baseImage->resize($width, $height, function($constraint) { |
|
50
|
50
|
$constraint->aspectRatio(); |
|
51
|
51
|
$constraint->upsize(); |
|
52
|
52
|
}); |
|
@@ -54,14 +54,14 @@ discard block |
|
|
block discarded – undo |
|
54
|
54
|
return $baseImage->fit($width, $height); |
|
55
|
55
|
} |
|
56
|
56
|
}, config('thumbnail.image_cached_time', 10), true); //Storing Thumbnail |
|
57
|
|
- $img->save(public_path('storage/'.$image), $quality); //Storing Thumbnail |
|
|
57
|
+ $img->save(public_path('storage/' . $image), $quality); //Storing Thumbnail |
|
58
|
58
|
} |
|
59
|
59
|
|
|
60
|
60
|
// Make Custom Thumbnail |
|
61
|
61
|
private function makeCustomThumbnails($image_file, $imageStoreNameOnly, $extension, $storage, $thumbnails) |
|
62
|
62
|
{ |
|
63
|
63
|
foreach ($thumbnails as $thumbnail) { |
|
64
|
|
- $customthumbnail = $imageStoreNameOnly.'-'.str_replace('-', '', $thumbnail['thumbnail-name']).'.'.$extension; // Making Thumbnail Name |
|
|
64
|
+ $customthumbnail = $imageStoreNameOnly . '-' . str_replace('-', '', $thumbnail['thumbnail-name']) . '.' . $extension; // Making Thumbnail Name |
|
65
|
65
|
$this->makeImg( |
|
66
|
66
|
$image_file, |
|
67
|
67
|
$customthumbnail, |
|
@@ -78,10 +78,10 @@ discard block |
|
|
block discarded – undo |
|
78
|
78
|
{ |
|
79
|
79
|
/* --------------------- Thumbnail Info---------------------------------------- */ |
|
80
|
80
|
//small thumbnail name |
|
81
|
|
- $smallthumbnail = $imageStoreNameOnly.'-small'.'.'.$extension; // Making Thumbnail Name |
|
|
81
|
+ $smallthumbnail = $imageStoreNameOnly . '-small' . '.' . $extension; // Making Thumbnail Name |
|
82
|
82
|
|
|
83
|
83
|
//medium thumbnail name |
|
84
|
|
- $mediumthumbnail = $imageStoreNameOnly.'-medium'.'.'.$extension; // Making Thumbnail Name |
|
|
84
|
+ $mediumthumbnail = $imageStoreNameOnly . '-medium' . '.' . $extension; // Making Thumbnail Name |
|
85
|
85
|
|
|
86
|
86
|
// Medium Thumbnail |
|
87
|
87
|
$this->makeImg( |
|
@@ -113,8 +113,8 @@ discard block |
|
|
block discarded – undo |
|
113
|
113
|
$raw_filename = pathinfo($filenamewithextension, PATHINFO_FILENAME); //Retriving Image Raw Filename only |
|
114
|
114
|
$filename = $this->validImageName($raw_filename); // Retrive Filename |
|
115
|
115
|
$extension = $image_file->getClientOriginalExtension(); //Retriving Image extension |
|
116
|
|
- $imageStoreNameOnly = $filename.'-'.time(); //Making Image Store name |
|
117
|
|
- $imageStoreName = $filename.'-'.time().'.'.$extension; //Making Image Store name |
|
|
116
|
+ $imageStoreNameOnly = $filename . '-' . time(); //Making Image Store name |
|
|
117
|
+ $imageStoreName = $filename . '-' . time() . '.' . $extension; //Making Image Store name |
|
118
|
118
|
|
|
119
|
119
|
$image_info['filenamewithextension'] = $filenamewithextension; |
|
120
|
120
|
$image_info['raw_filename'] = $raw_filename; |
|
@@ -136,12 +136,12 @@ discard block |
|
|
block discarded – undo |
|
136
|
136
|
$fieldname => $img->storeAs($custom['storage'] ?? config('thumbnail.storage_path', 'uploads'), $imageStoreName, 'public'), // Storing Parent Image |
|
137
|
137
|
]); |
|
138
|
138
|
|
|
139
|
|
- $image = Image::cache(function ($cached_img) use ($image_file, $custom) { |
|
|
139
|
+ $image = Image::cache(function($cached_img) use ($image_file, $custom) { |
|
140
|
140
|
$height = $custom['height'] ?? config('thumbnail.img_height', 800); |
|
141
|
141
|
$width = $custom['width'] ?? config('thumbnail.img_width', 1000); |
|
142
|
142
|
$baseImage = $cached_img->make($image_file->getRealPath()); |
|
143
|
143
|
if (config('thumbnail.keep_aspect_ratio')) { |
|
144
|
|
- return $baseImage->resize($width, $height, function ($constraint) { |
|
|
144
|
+ return $baseImage->resize($width, $height, function($constraint) { |
|
145
|
145
|
$constraint->aspectRatio(); |
|
146
|
146
|
$constraint->upsize(); |
|
147
|
147
|
}); //Parent Image Interventing |
|
@@ -149,7 +149,7 @@ discard block |
|
|
block discarded – undo |
|
149
|
149
|
return $baseImage->fit($width, $height); //Parent Image Interventing |
|
150
|
150
|
} |
|
151
|
151
|
}, config('thumbnail.image_cached_time', 10), true); |
|
152
|
|
- $image->save(public_path('storage/'.$this->$fieldname), $custom['quality'] ?? config('thumbnail.image_quality', 80)); // Parent Image Locating Save |
|
|
152
|
+ $image->save(public_path('storage/' . $this->$fieldname), $custom['quality'] ?? config('thumbnail.image_quality', 80)); // Parent Image Locating Save |
|
153
|
153
|
} |
|
154
|
154
|
|
|
155
|
155
|
// Thumbnail Path |
|
@@ -183,12 +183,12 @@ discard block |
|
|
block discarded – undo |
|
183
|
183
|
$image = $byLocation ? ($location ?? $this->$fieldname) : $this->$fieldname; // Search By Field or Location |
|
184
|
184
|
$path = explode('/', $image); |
|
185
|
185
|
$extension = \File::extension($image); |
|
186
|
|
- $name = basename($image, '.'.$extension); |
|
187
|
|
- $image_fullname = isset($size) ? $name.'-'.(string) $size.'.'.$extension : $name.'.'.$extension; |
|
|
186
|
+ $name = basename($image, '.' . $extension); |
|
|
187
|
+ $image_fullname = isset($size) ? $name . '-' . (string) $size . '.' . $extension : $name . '.' . $extension; |
|
188
|
188
|
array_pop($path); |
|
189
|
189
|
$location = implode('/', $path); |
|
190
|
|
- $path = 'storage/'.$location.'/'.$image_fullname; |
|
191
|
|
- $image_files = File::files(public_path('storage/'.$location)); |
|
|
190
|
+ $path = 'storage/' . $location . '/' . $image_fullname; |
|
|
191
|
+ $image_files = File::files(public_path('storage/' . $location)); |
|
192
|
192
|
$images_property = $this->imageProperty($image_files, $name); |
|
193
|
193
|
$image_detail = [ |
|
194
|
194
|
'image' => $image, |
|
@@ -196,8 +196,8 @@ discard block |
|
|
block discarded – undo |
|
196
|
196
|
'fullname' => $image_fullname, |
|
197
|
197
|
'extension' => $extension, |
|
198
|
198
|
'path' => $path, |
|
199
|
|
- 'directory' => public_path('storage/'.$location), |
|
200
|
|
- 'location' => public_path('storage/'.$image), |
|
|
199
|
+ 'directory' => public_path('storage/' . $location), |
|
|
200
|
+ 'location' => public_path('storage/' . $image), |
|
201
|
201
|
'property' => $images_property, |
|
202
|
202
|
]; |
|
203
|
203
|
|
|
@@ -217,7 +217,7 @@ discard block |
|
|
block discarded – undo |
|
217
|
217
|
|
|
218
|
218
|
$image_partition = explode('-', basename($image)); |
|
219
|
219
|
if (isset($image_partition[0]) && isset($image_partition[1])) { |
|
220
|
|
- $parent_thumbnail_name = $image_partition[0].'-'.$image_partition[1]; |
|
|
220
|
+ $parent_thumbnail_name = $image_partition[0] . '-' . $image_partition[1]; |
|
221
|
221
|
if ($parent_name == $parent_thumbnail_name) { |
|
222
|
222
|
$thumbnail_count++; |
|
223
|
223
|
$thumbnail_exists = $this->imageExists($image); |
|
@@ -270,6 +270,6 @@ discard block |
|
|
block discarded – undo |
|
270
|
270
|
// Valid Image Name |
|
271
|
271
|
private function validImageName($name) |
|
272
|
272
|
{ |
|
273
|
|
- return strtolower(str_replace([' ', '-', '$', '<', '>', '&', '{', '}', '*', '\\', '/', ':'.';', ',', "'", '"'], '_', trim($name))); |
|
|
273
|
+ return strtolower(str_replace([' ', '-', '$', '<', '>', '&', '{', '}', '*', '\\', '/', ':' . ';', ',', "'", '"'], '_', trim($name))); |
|
274
|
274
|
} |
|
275
|
275
|
} |