Giter VIP home page Giter VIP logo

Comments (2)

lakshmaji avatar lakshmaji commented on August 16, 2024

Hi @septierg, Thanks for raising the issue related to performance.
I don't know the actual cause, could you be able to find the reason or when it is happening like when execution context is making the call to library, or when it is exiting ?

Could be able to provide me reproducible repo!

from thumbnail.

septierg avatar septierg commented on August 16, 2024

HI @lakshmaji thank you for your response, here is my code:
Route:
Route::get('/media/thumbnail/{size}/{file}', 'MediaController@getThumbnail')->name('media.get_thumbnail');

Controller:

public function getThumbnail($size, $file) {
    $media = Media::where('title', $file)->first();

    if(!is_numeric($size) || !isset($media)) {
        return response("", 400);
    }


    $thumb_size = $size > config('app.limit_size_thumbnail') ? config('app.limit_size_thumbnail') : ($size <= 0 
            ? config('app.default_size_thumbnail') : $size);

    return $this->generateThumbnail($media, $thumb_size);
}

private function generateThumbnail(Media $media, $size) {
  
    if(!\File::exists(storage_path("app/public/uploads/thumbnail"))) {
        \File::makeDirectory(storage_path("app/public/uploads/thumbnail"));
    }

    $file_source = storage_path($media->directory);
    $file_target = storage_path("app/public/uploads/thumbnail")."/". pathinfo($media->title, PATHINFO_FILENAME)."-".$size."-thumbnail.jpg";
    
    // generate video thumbnail
    if(strstr(mime_content_type($file_source), "video/")) {
        $thumbnail_status = Thumbnail::getThumbnail($file_source,pathinfo($file_target, PATHINFO_DIRNAME),pathinfo($file_target, PATHINFO_FILENAME).'.jpg');
        if($thumbnail_status)
  {
    echo "Thumbnail generated";
  }
  else
  {
    echo "thumbnail generation has failed";
  }
           
        }
     
    else if(strstr(mime_content_type($file_source), "image/")) {
        if (\File::copy($file_source , $file_target)) {
              return $this->createThumbnail($file_target, $size, $size);
        }
        return null;
    }
}

private function createThumbnail($path, $width, $height) {
    $img = Image::make($path)->resize($width, $height, function ($constraint) {
        $constraint->aspectRatio();
    });
    $img->save($path);  
    return $img->response();
}

from thumbnail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.