Skip to content

Commit 5610094

Browse files
committed
2 parents 52f69dc + 8dfa212 commit 5610094

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/Traits/Thumbnail.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ trait Thumbnail
1010
{
1111
public function makeThumbnail($fieldname = 'image', $custom = [])
1212
{
13-
if (!empty(request()->$fieldname) || $custom['image']) {
13+
if (! empty(request()->$fieldname) || $custom['image']) {
1414
/* ------------------------------------------------------------------- */
1515

16-
$image_file = $custom['image'] ?? request()->file($fieldname); // Retriving Image File
16+
$image_file = $custom['image'] ?? request()->file($fieldname); // Retriving Image File
1717
$extension = $this->image_info($image_file)->extension; //Retriving Image extension
1818
$imageStoreNameOnly = $this->image_info($image_file)->imageStoreNameOnly; //Making Image Store name
1919

20-
2120
/* ------------------------------------------------------------------- */
2221

2322
/* ----------------------------------------Parent Image Upload----------------------------------------- */
@@ -30,7 +29,7 @@ public function makeThumbnail($fieldname = 'image', $custom = [])
3029
if ($thumbnails) {
3130
/* -----------------------------------------Custom Thumbnails------------------------------------------------- */
3231
$this->makeCustomThumbnails($image_file, $imageStoreNameOnly, $extension, $storage, $thumbnails);
33-
/* -------------------------------------------------------------------------------------------------- */
32+
/* -------------------------------------------------------------------------------------------------- */
3433
} else {
3534
/* ---------------------------------------Default Thumbnails--------------------------------------- */
3635
$this->makeDefaultThumbnails($image_file, $extension, $imageStoreNameOnly);
@@ -47,14 +46,14 @@ private function makeImg($image_file, $name, $location, $width, $height, $qualit
4746
$img = Image::cache(function ($cached_img) use ($image_file, $width, $height) {
4847
return $cached_img->make($image_file->getRealPath())->fit($width, $height);
4948
}, config('thumbnail.image_cached_time', 10), true); //Storing Thumbnail
50-
$img->save(public_path('storage/' . $image), $quality); //Storing Thumbnail
49+
$img->save(public_path('storage/'.$image), $quality); //Storing Thumbnail
5150
}
5251

5352
// Make Custom Thumbnail
5453
private function makeCustomThumbnails($image_file, $imageStoreNameOnly, $extension, $storage, $thumbnails)
5554
{
5655
foreach ($thumbnails as $thumbnail) {
57-
$customthumbnail = $imageStoreNameOnly . '-' . str_replace('-', '', $thumbnail['thumbnail-name']) . '.' . $extension; // Making Thumbnail Name
56+
$customthumbnail = $imageStoreNameOnly.'-'.str_replace('-', '', $thumbnail['thumbnail-name']).'.'.$extension; // Making Thumbnail Name
5857
$this->makeImg(
5958
$image_file,
6059
$customthumbnail,
@@ -71,10 +70,10 @@ private function makeDefaultThumbnails($image_file, $extension, $imageStoreNameO
7170
{
7271
/* --------------------- Thumbnail Info---------------------------------------- */
7372
//small thumbnail name
74-
$smallthumbnail = $imageStoreNameOnly . '-small' . '.' . $extension; // Making Thumbnail Name
73+
$smallthumbnail = $imageStoreNameOnly.'-small'.'.'.$extension; // Making Thumbnail Name
7574

7675
//medium thumbnail name
77-
$mediumthumbnail = $imageStoreNameOnly . '-medium' . '.' . $extension; // Making Thumbnail Name
76+
$mediumthumbnail = $imageStoreNameOnly.'-medium'.'.'.$extension; // Making Thumbnail Name
7877

7978
// Medium Thumbnail
8079
$this->makeImg(
@@ -106,15 +105,16 @@ private function image_info($image_file)
106105
$raw_filename = pathinfo($filenamewithextension, PATHINFO_FILENAME); //Retriving Image Raw Filename only
107106
$filename = str_replace(['-', ' '], '', $raw_filename); // Retrive Filename
108107
$extension = $image_file->getClientOriginalExtension(); //Retriving Image extension
109-
$imageStoreNameOnly = $filename . '-' . time(); //Making Image Store name
110-
$imageStoreName = $filename . '-' . time() . '.' . $extension; //Making Image Store name
108+
$imageStoreNameOnly = $filename.'-'.time(); //Making Image Store name
109+
$imageStoreName = $filename.'-'.time().'.'.$extension; //Making Image Store name
111110

112111
$image_info['filenamewithextension'] = $filenamewithextension;
113112
$image_info['raw_filename'] = $raw_filename;
114113
$image_info['filename'] = $filename;
115114
$image_info['extension'] = $extension;
116115
$image_info['imageStoreNameOnly'] = $imageStoreNameOnly;
117116
$image_info['imageStoreName'] = $imageStoreName;
117+
118118
return json_decode(json_encode($image_info));
119119
}
120120

@@ -131,7 +131,7 @@ public function uploadImage($fieldname = 'image', $custom = [])
131131
$image = Image::cache(function ($cached_img) use ($image_file, $custom) {
132132
return $cached_img->make($image_file->getRealPath())->fit($custom['width'] ?? config('thumbnail.img_width', 1000), $custom['height'] ?? config('thumbnail.img_height', 800)); //Parent Image Interventing
133133
}, config('thumbnail.image_cached_time', 10), true);
134-
$image->save(public_path('storage/' . $this->$fieldname), $custom['quality'] ?? config('thumbnail.image_quality', 80)); // Parent Image Locating Save
134+
$image->save(public_path('storage/'.$this->$fieldname), $custom['quality'] ?? config('thumbnail.image_quality', 80)); // Parent Image Locating Save
135135
}
136136

137137
// Thumbnail Path
@@ -164,21 +164,21 @@ public function imageDetail($fieldname = 'image', $size = null)
164164
$image = $this->$fieldname;
165165
$path = explode('/', $image);
166166
$extension = \File::extension($image);
167-
$name = basename($image, '.' . $extension);
168-
$image_fullname = isset($size) ? $name . '-' . (string) $size . '.' . $extension : $name . '.' . $extension;
167+
$name = basename($image, '.'.$extension);
168+
$image_fullname = isset($size) ? $name.'-'.(string) $size.'.'.$extension : $name.'.'.$extension;
169169
array_pop($path);
170170
$location = implode('/', $path);
171-
$path = 'storage/' . $location . '/' . $image_fullname;
172-
$image_files = File::files(public_path('storage/' . $location));
171+
$path = 'storage/'.$location.'/'.$image_fullname;
172+
$image_files = File::files(public_path('storage/'.$location));
173173
$images_property = $this->imageProperty($image_files, $name);
174174
$image_detail = [
175175
'image' => $image,
176176
'name' => $name,
177177
'fullname' => $image_fullname,
178178
'extension' => $extension,
179179
'path' => $path,
180-
'directory' => public_path('storage/' . $location),
181-
'location' => public_path('storage/' . $image),
180+
'directory' => public_path('storage/'.$location),
181+
'location' => public_path('storage/'.$image),
182182
'property' => $images_property,
183183
];
184184

@@ -188,13 +188,12 @@ public function imageDetail($fieldname = 'image', $size = null)
188188
// Image Property
189189
private function imageProperty($image_files, $parent_name)
190190
{
191-
192191
$images_property = [];
193192
$thumbnails_property = [];
194193
$thumbnail_count = 0;
195194
foreach ($image_files as $image) {
196195
$image_partition = explode('-', basename($image));
197-
$parent_thumbnail_name = $image_partition[0] . '-' . $image_partition[1];
196+
$parent_thumbnail_name = $image_partition[0].'-'.$image_partition[1];
198197
if ($parent_name == $parent_thumbnail_name) {
199198
$thumbnail_count++;
200199
$thumbnail_exists = $this->imageExists($image);

0 commit comments

Comments
 (0)