Last active
August 13, 2019 19:22
-
-
Save Edofre/49403f6c38f8ec6c4f91ab8a79b157a4 to your computer and use it in GitHub Desktop.
Revisions
-
Edofre renamed this gist
Jul 23, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Edofre created this gist
Jul 23, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ <?php // Create instance $img = \Image::make(storage_path("app/{$uploadPath}" . $fileName)); // Make sure $img->orientate(); // Resize only the width of the image $img->resize(250, null, function ($constraint) { $constraint->aspectRatio(); }); // Create a thumbnail from the image $imageThumbnailPath = "app/{$uploadPath}" . get_thumbnail($fileName); // Finally we save the image as a new file $img->save(storage_path($imageThumbnailPath)); if (!function_exists('get_thumbnail')) { /** * Adds the image suffix to get the thumbnail of the image instead * @param string $imageName * @return string */ function get_thumbnail(string $imageName) { // Thumbnail suffix, generated by hand for now // TODO $suffix = '_tn'; $imageExtension = pathinfo($imageName, PATHINFO_EXTENSION); $thumbailName = (str_replace('.' . $imageExtension, "", $imageName)); return "{$thumbailName}{$suffix}.{$imageExtension}"; } }