vendredi 10 avril 2015

Laravel Image thumb

I making a web app where uploaded photos are stored in /app/storage. To show the file I am using a route ex: showphoto/{id} (Paths are stored in DB)



public function showphoto($id){
$photo = Photo::findOrFail($id);
return $this->getFile($photo);
}
private function getFile($f){
if($f->path){
$file = storage_path().'/'.$f->path.'/'.$f->origin_name;
if (File::exists($file)) {
$contents = File::get($file);
switch($f->ext) {
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpeg"; break;
case "pdf": $ctype="application/pdf"; break;
default:
}
$response = Response::make($contents, 200);
$response->header('Content-Type', $ctype);
return $response;
}
}
}


To show image I am using



{{ HTML::image(route('showphoto', $photo->id), $photo->getName(), array('class'=>'img-thumbnail', 'width' => '100', 'height'=>'100')) }}


Question: Some file are more then 2 MB and when I have a list of them they are loading very slowly, So on the list I want to show just a Thumb of the photo. It is possible to create a temporary thumb that will not be stored anywhere? Or it is not a good idea to create a temporary thumb each time I load a page. Thank you in advance.


Aucun commentaire:

Enregistrer un commentaire