Beispiel #1
0
 /**
  * REsize the File
  * @param type $file
  * @param type $w
  * @param type $h
  * @param type $q
  */
 public function postFileResize($path, $width, $height, $q = 80)
 {
     if (!class_exists('\\Image')) {
         $image = zbase_file_serve_image($path, $width, $height, $q);
         if (!empty($image)) {
             header('Content-type: ' . $image['mime']);
             return \Response::make(readfile($image['src'], $image['size'])->header('Content-Type', $image['mime']));
         }
         return zbase_abort(404);
     }
     return \Image::cache(function ($image) use($width, $height, $path) {
         if (empty($width)) {
             $size = getimagesize($path);
             $width = $size[0];
             $height = $size[1];
         }
         if (!empty($width) && !empty($height)) {
             return $image->make($path)->resize($width, $height, function ($constraint) {
                 $constraint->upsize();
                 $constraint->aspectRatio();
             });
         }
         if (!empty($width) && empty($height)) {
             return $image->make($path)->resize($width, null, function ($constraint) {
                 $constraint->upsize();
                 $constraint->aspectRatio();
             });
         }
         if (empty($width) && !empty($height)) {
             return $image->make($path)->resize(null, $height, function ($constraint) {
                 $constraint->upsize();
                 $constraint->aspectRatio();
             });
         }
         return $image->make($path)->resize($width, $height);
     });
 }
Beispiel #2
0
 /**
  * Serve the File
  * @param integer $width
  * @param integer $height
  * @param integer $quality Image Quality
  * @param boolean $download If to download
  * @return boolean
  */
 public function serveImage($width, $height = null, $quality = null, $download = false, $image = null)
 {
     $folder = zbase_storage_path() . '/' . zbase_tag() . '/user/' . $this->id() . '/';
     if (!empty($image)) {
         $path = $folder . $image;
     } else {
         $path = $folder . $this->avatar;
     }
     if (!class_exists('\\Image')) {
         $image = zbase_file_serve_image($path, $width, $height, $quality, $download);
         if (!empty($image)) {
             return \Response::make(readfile($image['src'], $image['size'])->header('Content-Type', $image['mime']));
         }
         return zbase_abort(404);
     }
     // dd($this, $path, file_exists($path));
     if (file_exists($path)) {
         $cachedImage = \Image::cache(function ($image) use($width, $height, $path) {
             if (empty($width)) {
                 $size = getimagesize($path);
                 $width = $size[0];
                 $height = $size[1];
             }
             if (!empty($width) && empty($height)) {
                 return $image->make($path)->resize($width, null, function ($constraint) {
                     $constraint->upsize();
                     $constraint->aspectRatio();
                 });
             }
             if (empty($width) && !empty($height)) {
                 return $image->make($path)->resize(null, $height, function ($constraint) {
                     $constraint->upsize();
                     $constraint->aspectRatio();
                 });
             }
             return $image->make($path)->resize($width, $height);
         });
         return \Response::make($cachedImage, 200, array('Content-Type' => 'image/png'));
     }
     return false;
 }