Browse Source

Add a try catch in Picture to prevent crashes, #215

pull/238/head
Timothée Jaussoin 9 years ago
parent
commit
0443798631
  1. 53
      system/Picture.php

53
system/Picture.php

@ -177,35 +177,40 @@ class Picture {
$path = $this->_path.md5($this->_key).'_'.$width.$this->_formats[$format];
$im = new Imagick;
$im->readImageBlob($this->_bin);
$im->setImageFormat($format);
if($format == 'jpeg') {
$im->setImageCompression(Imagick::COMPRESSION_JPEG);
$im->setImageAlphaChannel(11);
// Put 11 as a value for now, see http://php.net/manual/en/imagick.flattenimages.php#116956
//$im->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
$im->setImageBackgroundColor('#ffffff');
$im = $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
}
//$crop = new CropEntropy;
//$crop->setImage($im);
try {
$im->readImageBlob($this->_bin);
$im->setImageFormat($format);
if($format == 'jpeg') {
$im->setImageCompression(Imagick::COMPRESSION_JPEG);
$im->setImageAlphaChannel(11);
// Put 11 as a value for now, see http://php.net/manual/en/imagick.flattenimages.php#116956
//$im->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
$im->setImageBackgroundColor('#ffffff');
$im = $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
}
$geo = $im->getImageGeometry();
//$crop = new CropEntropy;
//$crop->setImage($im);
$im->cropThumbnailImage($width, $height);
if($width > $geo['width']) {
$factor = floor($width/$geo['width']);
$im->blurImage($factor, 10);
}
$geo = $im->getImageGeometry();
//$im = $crop->resizeAndCrop($width, $height);
$im->cropThumbnailImage($width, $height);
if($width > $geo['width']) {
$factor = floor($width/$geo['width']);
$im->blurImage($factor, 10);
}
//$im = $crop->resizeAndCrop($width, $height);
$im->setImageCompressionQuality(85);
$im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$im->setImageCompressionQuality(85);
$im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$im->writeImage($path);
$im->clear();
$im->writeImage($path);
$im->clear();
} catch (ImagickException $e) {
error_log($e->getMessage());
}
}
}
Loading…
Cancel
Save