public function __construct($file) { if (!Image_GD::$_checked) { // Run the install check Image_GD::check(); } parent::__construct($file); // Set the image creation function name switch ($this->type) { case IMAGETYPE_JPEG: $create = 'imagecreatefromjpeg'; break; case IMAGETYPE_GIF: $create = 'imagecreatefromgif'; break; case IMAGETYPE_PNG: $create = 'imagecreatefrompng'; break; } if (!isset($create) or !function_exists($create)) { throw new Kohana_Exception('Installed GD does not support :type images', array(':type' => image_type_to_extension($this->type, FALSE))); } // Save function for future use $this->_create_function = $create; // Save filename for lazy loading $this->_image = $this->file; }
public function __construct($file) { if (!Image_GD::$_checked) { // Run the install check Image_GD::check(); } parent::__construct($file); // Set the image creation function name switch ($this->type) { case IMAGETYPE_JPEG: $create = 'imagecreatefromjpeg'; break; case IMAGETYPE_GIF: $create = 'imagecreatefromgif'; break; case IMAGETYPE_PNG: $create = 'imagecreatefrompng'; break; } if (!isset($create) or !function_exists($create)) { throw new Kohana_Exception('Installed GD does not support :type images', array(':type' => image_type_to_extension($this->type, FALSE))); } // Open the temporary image $this->_image = $create($this->file); // Preserve transparency when saving imagesavealpha($this->_image, TRUE); }
public static function check() { if (!function_exists('gd_info')) { throw new Exception('GD is either not installed or not enabled, check your configuration'); } if (defined('GD_BUNDLED')) { // Get the version via a constant, available in PHP 5. $bundled = GD_BUNDLED; } else { // Get the version information $bundled = current(gd_info()); // Extract the bundled status $bundled = (bool) preg_match('/\\bbundled\\b/i', $bundled); } if (!$bundled) { throw new Exception('Image_GD requires GD to be bundled with PHP'); } if (defined('GD_VERSION')) { // Get the version via a constant, available in PHP 5.2.4+ $version = GD_VERSION; } else { // Get the version information $version = current(gd_info()); // Extract the version number preg_match('/\\d+\\.\\d+(?:\\.\\d+)?/', $version, $matches); // Get the major version $version = $matches[0]; } if (!version_compare($version, '2.0', '>=')) { throw new KoException('Image_GD requires GD version 2.0 or greater, you have :version', array(':version' => $version)); } return Image_GD::$_checked = TRUE; }
/** * Checks if GD is enabled and bundled. Bundled GD is required for some * methods to work. Exceptions will be thrown from those methods when GD is * not bundled. * * @return boolean */ public static function check() { parent::check(); // Chema-> theres a bug here sometimes returns 0 as version :( if (defined('GD_BUNDLED')) { // Get the version via a constant, available in PHP 5. Image_GD::$_bundled = GD_BUNDLED == 0 ? 1 : GD_BUNDLED; } else { // Get the version information $info = gd_info(); // Extract the bundled status Image_GD::$_bundled = (bool) preg_match('/\\bbundled\\b/i', $info['GD Version']); } }
public function actionIndex() { $image = new Image_GD(Yii::getPathOfAlias("system") . "/yii-powered.png"); $image->resize(800, 150); Yii::app()->request->sendFile("image.png", $image->render()); }
/** * Checks if GD is enabled and verify that key methods exist, some of which require GD to * be bundled with PHP. Exceptions will be thrown from those methods when GD is not * bundled. * * @return boolean */ public static function check() { if (!function_exists('gd_info')) { throw new Kohana_Exception('GD is either not installed or not enabled, check your configuration'); } $functions = [Image_GD::IMAGEROTATE, Image_GD::IMAGECONVOLUTION, Image_GD::IMAGEFILTER, Image_GD::IMAGELAYEREFFECT]; foreach ($functions as $function) { Image_GD::$_available_functions[$function] = function_exists($function); } if (defined('GD_VERSION')) { // Get the version via a constant, available in PHP 5.2.4+ $version = GD_VERSION; } else { // Get the version information $info = gd_info(); // Extract the version number preg_match('/\\d+\\.\\d+(?:\\.\\d+)?/', $info['GD Version'], $matches); // Get the major version $version = $matches[0]; } if (!version_compare($version, '2.0.1', '>=')) { throw new Kohana_Exception('Image_GD requires GD version :required or greater, you have :version', ['required' => '2.0.1', ':version' => $version]); } return Image_GD::$_checked = true; }