*/
public function createView($view, $style = null)
{
- // HACK: Need to replace the image object with a JPG typed image if
- // we are generating a screen image. Need to do the replacement
- // and do it *here* for BC reasons with Horde_Image...and this
- // needs to be done FIRST, since the view might already be cached
- // in the VFS.
+ /* Force screen images to ALWAYS be jpegs for performance/size */
if ($view == 'screen' && $GLOBALS['conf']['image']['type'] != 'jpeg') {
- $this->_image = Ansel::getImageObject(array('type' => 'jpeg'));
- $this->_image->reset();
+ $this->_image->setType('jpeg');
}
/* Get the VFS info. */
}
/**
+ * Setter for the image type.
+ *
+ * @param string $type The simple type for the imag (png, jpg, etc...)
+ *
+ * @return void
+ */
+ public function setType($type)
+ {
+ $this->_type = $type;
+ }
+
+ /**
* Draw a shaped point at the specified (x,y) point. Useful for
* scatter diagrams, debug points, etc. Draws squares, circles,
* diamonds, and triangles.
if (!Horde_Util::loadExtension('imagick')) {
throw new Horde_Image_Exception('Required PECL Imagick extension not found.');
}
- parent::__construct($params, $context);
+ parent::__construct($params, $context);
ini_set('imagick.locale_fix', 1);
$this->_imagick = new Imagick();
if (!empty($params['filename'])) {
}
}
- $this->_imagick->setImageFormat($this->_type);
+ try {
+ $this->_imagick->setImageFormat($this->_type);
+ } catch (ImagickException $e) {
+ throw new Horde_Image_Exception($e);
+ }
}
/**
$this->_imagick->clear();
try {
$this->_imagick->readImageBlob($this->_data);
+ $this->_imagick->setImageFormat($this->_type);
+ $this->_imagick->setIteratorIndex(0);
} catch (ImagickException $e) {
throw new Horde_Image_Exception($e);
}
- $this->_imagick->setImageFormat($this->_type);
unset($this->_data);
- $this->_imagick->setIteratorIndex(0);
}
/**
$this->_imagick->clear();
try {
$this->_imagick->readImageBlob($this->_data);
+ $this->_imagick->setImageFormat($this->_type);
+ $this->_imagick->setIteratorIndex(0);
} catch (ImagickException $e) {
throw new Horde_Image_Exception($e);
}
- $this->_imagick->setImageFormat($this->_type);
- $this->_imagick->setIteratorIndex(0);
unset($this->_data);
}
+ /**
+ * Set the image type
+ *
+ * @see Horde_Image_Base::setType()
+ */
+ public function setType($type)
+ {
+ parent::setType($type);
+ try {
+ $this->_imagick->setImageFormat($this->_type);
+ } catch (ImagickException $e) {
+ // Don't care about an empty wand here.
+ }
+ }
+
/*
* Return the raw image data.
*
$image->display();
break;
+case 'testDefaultImageFormatDuringLoad':
+ // Tests image format during load
+ $image = getImageObject(array('filename' => 'img1.jpg'));
+ $image->display();
+ break;
+
+case 'testForceImageFormatDuringLoad':
+ // Tests forcing image format during load
+ $image = getImageObject(array('filename' => 'img1.jpg', 'type' => 'jpeg'));
+ $image->display();
+ break;
+case 'testChangeImageFormatAfterLoad':
+ // Tests changing image format after load
+ $image = getImageObject(array('filename' => 'img1.jpg')); // Loads as PNG
+ $image->setType('jpeg');
+ $image->display();
+ break;
+
case 'testResize':
$time = xdebug_time_index();
$image = getImageObject(array('filename' => 'img2.jpg'));
$allTests = array(
'testInitialState' => 'Test initial state. Solid blue square',
+ 'testDefaultImageFormatDuringLoad' => 'Should load as default image type of PNG even though source file is JPG',
+ 'testForceImageFormatDuringLoad' => 'Forces image format to JPG during loadFile (Default is PNG)',
+ 'testChangeImageFormatAfterLoad' => 'Changes image format after loaded from file (Should be JPG)',
'testPrimitivesTransparentBG' => 'Transparent background, various primitives. Cirlce should be above the rectangles.',
'testTransparentBGWithBorder' => 'Test transparent background with border preserving transparency.',
'testTransparentPrimitivesReversed' => 'Test ordering of primitives. This should show the circle *below* the rectangles.',