FEATURE: #2166 - Ability to set deafult for all resampeld JPEGs (dio5)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@56939 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew O'Neil 2008-06-25 05:22:56 +00:00
parent 3af8299b0b
commit 5ec9ff8862

View File

@ -6,7 +6,9 @@
*/ */
class GD extends Object { class GD extends Object {
protected $gd, $width, $height; protected $gd, $width, $height;
protected $quality = 75; protected $quality;
protected static $default_quality = 75;
function __construct($filename = null) { function __construct($filename = null) {
// If we're working with image resampling, things could take a while. Bump up the time-limit // If we're working with image resampling, things could take a while. Bump up the time-limit
@ -23,6 +25,8 @@ class GD extends Object {
case 3: $this->setGD(imagecreatefrompng($filename)); break; case 3: $this->setGD(imagecreatefrompng($filename)); break;
} }
} }
$this->quality = self::$default_quality;
parent::__construct(); parent::__construct();
} }
protected function setGD($gd) { protected function setGD($gd) {
@ -31,6 +35,16 @@ class GD extends Object {
$this->height = imagesy($gd); $this->height = imagesy($gd);
} }
/**
* Set the default image quality.
* @param quality int A number from 0 to 100, 100 being the best quality.
*/
static function set_default_quality($quality) {
if(is_numeric($quality) && (int) $quality >= 0 && (int) $quality <= 100) {
self::$default_quality = (int) $quality;
}
}
/** /**
* Set the image quality, used when saving JPEGs. * Set the image quality, used when saving JPEGs.
*/ */
@ -129,7 +143,7 @@ class GD extends Object {
* Rotates image by given angle. * Rotates image by given angle.
* *
* @param angle * @param angle
*
* @return GD * @return GD
*/ */
@ -152,7 +166,7 @@ class GD extends Object {
* using built-in function. Used when imagerotate function is not available(i.e. Ubuntu) * using built-in function. Used when imagerotate function is not available(i.e. Ubuntu)
* *
* @param angle * @param angle
*
* @return GD * @return GD
*/ */
@ -196,7 +210,7 @@ class GD extends Object {
* @param left x position of left upper corner of crop rectangle * @param left x position of left upper corner of crop rectangle
* @param width rectangle width * @param width rectangle width
* @param height rectangle height * @param height rectangle height
*
* @return GD * @return GD
*/ */
@ -211,7 +225,7 @@ class GD extends Object {
/** /**
* Method return width of image. * Method return width of image.
*
* @return integer width. * @return integer width.
*/ */
function getWidth() { function getWidth() {
@ -220,7 +234,7 @@ class GD extends Object {
/** /**
* Method return height of image. * Method return height of image.
*
* @return integer height * @return integer height
*/ */