Skip to content

Commit

Permalink
Merge pull request #10 from pratiksh404/analysis-7awpyk
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
pratiksh404 authored Nov 2, 2021
2 parents 96feaef + 94b2eb3 commit 41f2447
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/Traits/Thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait Thumbnail
{
public function makeThumbnail($fieldname = 'image', $custom = [])
{
if (!empty(request()->$fieldname) || $custom['image']) {
if (! empty(request()->$fieldname) || $custom['image']) {
/* ------------------------------------------------------------------- */

$image_file = $custom['image'] ?? request()->file($fieldname); // Retriving Image File
Expand All @@ -29,7 +29,7 @@ public function makeThumbnail($fieldname = 'image', $custom = [])
if ($thumbnails) {
/* -----------------------------------------Custom Thumbnails------------------------------------------------- */
$this->makeCustomThumbnails($image_file, $imageStoreNameOnly, $extension, $storage, $thumbnails);
/* -------------------------------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------------------------------- */
} else {
/* ---------------------------------------Default Thumbnails--------------------------------------- */
$this->makeDefaultThumbnails($image_file, $extension, $imageStoreNameOnly);
Expand All @@ -46,14 +46,14 @@ private function makeImg($image_file, $name, $location, $width, $height, $qualit
$img = Image::cache(function ($cached_img) use ($image_file, $width, $height) {
return $cached_img->make($image_file->getRealPath())->fit($width, $height);
}, config('thumbnail.image_cached_time', 10), true); //Storing Thumbnail
$img->save(public_path('storage/' . $image), $quality); //Storing Thumbnail
$img->save(public_path('storage/'.$image), $quality); //Storing Thumbnail
}

// Make Custom Thumbnail
private function makeCustomThumbnails($image_file, $imageStoreNameOnly, $extension, $storage, $thumbnails)
{
foreach ($thumbnails as $thumbnail) {
$customthumbnail = $imageStoreNameOnly . '-' . str_replace('-', '', $thumbnail['thumbnail-name']) . '.' . $extension; // Making Thumbnail Name
$customthumbnail = $imageStoreNameOnly.'-'.str_replace('-', '', $thumbnail['thumbnail-name']).'.'.$extension; // Making Thumbnail Name
$this->makeImg(
$image_file,
$customthumbnail,
Expand All @@ -70,10 +70,10 @@ private function makeDefaultThumbnails($image_file, $extension, $imageStoreNameO
{
/* --------------------- Thumbnail Info---------------------------------------- */
//small thumbnail name
$smallthumbnail = $imageStoreNameOnly . '-small' . '.' . $extension; // Making Thumbnail Name
$smallthumbnail = $imageStoreNameOnly.'-small'.'.'.$extension; // Making Thumbnail Name

//medium thumbnail name
$mediumthumbnail = $imageStoreNameOnly . '-medium' . '.' . $extension; // Making Thumbnail Name
$mediumthumbnail = $imageStoreNameOnly.'-medium'.'.'.$extension; // Making Thumbnail Name

// Medium Thumbnail
$this->makeImg(
Expand Down Expand Up @@ -105,8 +105,8 @@ private function image_info($image_file)
$raw_filename = pathinfo($filenamewithextension, PATHINFO_FILENAME); //Retriving Image Raw Filename only
$filename = str_replace(['-', ' '], '', $raw_filename); // Retrive Filename
$extension = $image_file->getClientOriginalExtension(); //Retriving Image extension
$imageStoreNameOnly = $filename . '-' . time(); //Making Image Store name
$imageStoreName = $filename . '-' . time() . '.' . $extension; //Making Image Store name
$imageStoreNameOnly = $filename.'-'.time(); //Making Image Store name
$imageStoreName = $filename.'-'.time().'.'.$extension; //Making Image Store name

$image_info['filenamewithextension'] = $filenamewithextension;
$image_info['raw_filename'] = $raw_filename;
Expand All @@ -131,7 +131,7 @@ public function uploadImage($fieldname = 'image', $custom = [])
$image = Image::cache(function ($cached_img) use ($image_file, $custom) {
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
}, config('thumbnail.image_cached_time', 10), true);
$image->save(public_path('storage/' . $this->$fieldname), $custom['quality'] ?? config('thumbnail.image_quality', 80)); // Parent Image Locating Save
$image->save(public_path('storage/'.$this->$fieldname), $custom['quality'] ?? config('thumbnail.image_quality', 80)); // Parent Image Locating Save
}

// Thumbnail Path
Expand Down Expand Up @@ -165,21 +165,21 @@ public function imageDetail($fieldname = 'image', $size = null, $byLocation = fa
$image = $byLocation ? ($location ?? $this->$fieldname) : $this->$fieldname; // Search By Field or Location
$path = explode('/', $image);
$extension = \File::extension($image);
$name = basename($image, '.' . $extension);
$image_fullname = isset($size) ? $name . '-' . (string) $size . '.' . $extension : $name . '.' . $extension;
$name = basename($image, '.'.$extension);
$image_fullname = isset($size) ? $name.'-'.(string) $size.'.'.$extension : $name.'.'.$extension;
array_pop($path);
$location = implode('/', $path);
$path = 'storage/' . $location . '/' . $image_fullname;
$image_files = File::files(public_path('storage/' . $location));
$path = 'storage/'.$location.'/'.$image_fullname;
$image_files = File::files(public_path('storage/'.$location));
$images_property = $this->imageProperty($image_files, $name);
$image_detail = [
'image' => $image,
'name' => $name,
'fullname' => $image_fullname,
'extension' => $extension,
'path' => $path,
'directory' => public_path('storage/' . $location),
'location' => public_path('storage/' . $image),
'directory' => public_path('storage/'.$location),
'location' => public_path('storage/'.$image),
'property' => $images_property,
];

Expand All @@ -199,7 +199,7 @@ private function imageProperty($image_files, $parent_name)

$image_partition = explode('-', basename($image));
if (isset($image_partition[0]) && isset($image_partition[1])) {
$parent_thumbnail_name = $image_partition[0] . '-' . $image_partition[1];
$parent_thumbnail_name = $image_partition[0].'-'.$image_partition[1];
if ($parent_name == $parent_thumbnail_name) {
$thumbnail_count++;
$thumbnail_exists = $this->imageExists($image);
Expand All @@ -222,7 +222,6 @@ private function imageProperty($image_files, $parent_name)
$images_property['directory'] = $image->getPath();
$images_property['location'] = $image->getRealPath();
} else {
false;
}
}
}
Expand Down Expand Up @@ -253,6 +252,6 @@ public function hardDeleteWithParent($fieldname = 'image'): void
// Valid Image Name
private function validImageName($name)
{
return strtolower(str_replace([' ', '-', '$', '<', '>', '&', '{', '}', '*', '\\', '/', ':' . ';', ',', "'", '"'], '_', trim($name)));
return strtolower(str_replace([' ', '-', '$', '<', '>', '&', '{', '}', '*', '\\', '/', ':'.';', ',', "'", '"'], '_', trim($name)));
}
}

0 comments on commit 41f2447

Please sign in to comment.