public function resolve() { parent::resolve(); if ($this->exists) { $rq = $this->request; if ($rq->get('width') || $rq->get('height')) { $thumb = \System\Cache\Thumb::from_image($this->file_point, array('height' => $rq->get('height'), 'width' => $rq->get('width'))); $cname = self::CLASS_FILE; $thumb->crop = $rq->get('crop') == '' || !!$rq->get('crop'); $thumb->check(); if (!$thumb->id) { $thumb->save(); } $this->file_path = BASE_DIR . $thumb->get_path(); $this->file_point = $cname::from_path($this->file_path); $this->exists = true; } } }
/** Get image thumb url * @param int $width Desired width * @param int $height Desired height * @param bool $crop Crop image if it does not fit (width, height):original(width, height) ratio * @return string */ public function thumb($width = null, $height = null, $crop = true) { if (is_null($width) && is_null($height)) { throw new \System\Error\Argument('You must pass width or height to \\System\\Image::thumb.'); } $opts = array("width" => $width, "height" => $height, "crop" => $crop); try { $thumb = \System\Cache\Thumb::from_image($this, $opts); } catch (\System\Error\File $e) { $thumb = \System\Cache\Thumb::create_blank($opts); } if (!$thumb->id) { $thumb->save(); } return $thumb->url(); }