Ejemplo n.º 1
0
 public function show($width = false, $height = false, $crop = false, $protocol = null)
 {
     if (!$this->is_image()) {
         return $this->filename();
     }
     if ($width || $height) {
         $size = $this->versions;
         if ($width) {
             $size = $size->where('width', '=', $width);
         }
         if ($height) {
             $size = $size->where('height', '=', $height);
         }
         $size = $size->find();
         if (!$size->loaded()) {
             $path = img::get($this->path(), $width, $height, $crop, $this->path);
             $pathparts = explode('/', $path);
             $filename = $pathparts[count($pathparts) - 1];
             $parentkeyname = $size->parent_key;
             $size->{$parentkeyname} = $this->id;
             $size->filename = $filename;
             $size->width = $width;
             $size->height = $height;
             $size->time = time();
             $size->save();
         }
         return url::site($this->path . $size->filename, $protocol);
     } else {
         return url::site($this->path . $this->filename(), $protocol);
     }
 }