Skip to content

Instantly share code, notes, and snippets.

@Edofre
Last active August 13, 2019 19:22
Show Gist options
  • Select an option

  • Save Edofre/49403f6c38f8ec6c4f91ab8a79b157a4 to your computer and use it in GitHub Desktop.

Select an option

Save Edofre/49403f6c38f8ec6c4f91ab8a79b157a4 to your computer and use it in GitHub Desktop.

Revisions

  1. Edofre renamed this gist Jul 23, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Edofre created this gist Jul 23, 2018.
    32 changes: 32 additions & 0 deletions gistfile1.txt
    Original 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}";
    }
    }