/** * @param string $file * @param int $width * @param int $height * @param string $fileType * @param int $quality on percentage scale from 0 to 100 (only for JPEG and PNG) * * @return string Thumbnail image path */ public static function thumbnalize($file, $width = null, $height = null, $fileType = self::TYPE_PNG, $quality = self::QUALITY_MEDIUM) { $file = static::$wwwDir . '/' . $file; if (!is_file($file)) { return; } switch ($fileType) { case self::TYPE_JPEG: $type = Image::JPEG; break; case self::TYPE_PNG: $type = Image::PNG; break; case self::TYPE_GIF: $type = Image::GIF; break; default: $type = Image::PNG; break; } $fileName = self::getFileName($file, $fileType); $destinationDir = $width . '_' . $height . '/' . $fileType . '/' . $quality; $thumbDir = static::$wwwDir . static::$thumbDir; if (file_exists($thumbDir . '/' . $destinationDir . '/' . $fileName)) { return static::$thumbDir . '/' . $destinationDir . '/' . $fileName; } static::$image = Image::fromFile($file); if (static::isWidthSet($width) && static::isHeightSet($height)) { static::resizeImageExactly($width, $height); } elseif (static::isWidthSet($width)) { static::resizeImageProportionally($width, $height); } else { static::resizeImageProportionally(static::$image->getWidth(), $height); } FileSystem::createDir($thumbDir . '/' . $destinationDir); static::$image->save($thumbDir . '/' . $destinationDir . '/' . $fileName, $quality, $type); return static::$thumbDir . '/' . $destinationDir . '/' . $fileName; }
public function setImage(ImageManager $image) { static::$image = $image; }
/** * Creates an image resource with the dimensions specified in config. * If a background image is supplied, the image dimensions are used. * * @throws Kohana_Exception if no GD2 support * @param string path to the background image file * @return void */ protected function image_create($background = null) { // Check for GD2 support if (!\function_exists('imagegd2')) { \Core::show_500(\__('captcha.requires_GD2')); } // Create a new image (black) static::$image = \imagecreatetruecolor(static::$config['width'], static::$config['height']); // Use a background image if (!empty($background)) { /* // Create the image using the right function for the filetype $function = '\\imagecreatefrom' . static::image_type($filename); static::$background_image = $function($background); // Resize the image if needed if ( \imagesx(static::background_image) !== static::$config['width'] || \imagesy(static::background_image) !== static::$config['height'] ) { \imagecopyresampled(static::image, static::background_image, 0, 0, 0, 0, static::$config['width'], static::$config['height'], \imagesx(static::background_image), \imagesy(static::background_image)); } // Free up resources \imagedestroy(static::background_image); */ } }