public function resolve() { $hash = $this->name; if (!is_null($thumb = \System\Cache\Thumb::from_hash($hash))) { if ($thumb->check()) { $this->file_point = \System\Image::from_path(BASE_DIR . $thumb->get_path()); $this->file_path = $this->file_point->get_path(); $this->exists = $this->file_point->exists(); } else { throw new \System\Error\File('Failed to generate image thumb.'); } } else { $this->exists = false; } }
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; } } }
public function find_all_thumbs() { return \System\Cache\Thumb::find_all_by_hash($this->hash()); }
/** Generate thumb using GD library * @param self $obj Instance of image * @return bool */ public static function gen_gd(self $obj) { $obj->image->refresh_info(); $coords = array('w_new' => $obj->width, 'h_new' => $obj->height, 'w_org' => intval($obj->image->width()), 'h_org' => intval($obj->image->height())); $tpth = BASE_DIR . $obj->get_path(); \System\Directory::check(dirname($tpth)); if ($coords['w_new'] < $coords['w_org'] || $coords['h_new'] < $coords['h_org']) { $coords = self::calc_thumb_coords($coords, $obj->crop); $im = \System\Image::get_gd_resource($obj->image); $th = imagecreatetruecolor($coords['w_new'], $coords['h_new']); $trans = $obj->image->format() == 3; if ($trans) { $transparent = imagecolorallocatealpha($th, 0, 0, 0, 127); imagefill($th, 0, 0, $transparent); } else { $wh = imagecolorallocate($th, 255, 255, 255); imagefill($th, 0, 0, $wh); } imagecopyresampled($th, $im, intval($coords['dst_x']), intval($coords['dst_y']), 0, 0, intval($coords['xw']), intval($coords['xh']), $coords['w_org'], $coords['h_org']); if (file_exists($tpth)) { unlink($tpth); } if ($trans) { imagealphablending($th, false); imagesavealpha($th, true); imagepng($th, $tpth); } else { imagejpeg($th, $tpth, 99); } imagedestroy($th); } else { $obj->image->copy($tpth); } return $obj; }