|
|
@ -105,7 +105,6 @@ class rcube_image
|
|
|
|
if ($convert) {
|
|
|
|
if ($convert) {
|
|
|
|
$p['out'] = $filename;
|
|
|
|
$p['out'] = $filename;
|
|
|
|
$p['in'] = $this->image_file;
|
|
|
|
$p['in'] = $this->image_file;
|
|
|
|
$p['size'] = $size.'x'.$size;
|
|
|
|
|
|
|
|
$type = $props['type'];
|
|
|
|
$type = $props['type'];
|
|
|
|
|
|
|
|
|
|
|
|
if (!$type && ($data = $this->identify())) {
|
|
|
|
if (!$type && ($data = $this->identify())) {
|
|
|
@ -120,11 +119,37 @@ class rcube_image
|
|
|
|
$type = 'jpg';
|
|
|
|
$type = 'jpg';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$p += array('type' => $type, 'types' => "bmp,eps,gif,jp2,jpg,png,svg,tif", 'quality' => 75);
|
|
|
|
// If only one dimension is greater than the limit convert doesn't
|
|
|
|
$p['-opts'] = array('-resize' => $p['size'].'>');
|
|
|
|
// work as expected, we need to calculate new dimensions
|
|
|
|
|
|
|
|
$scale = $size / max($props['width'], $props['height']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if file is smaller than the limit, we do nothing
|
|
|
|
|
|
|
|
// but copy original file to destination file
|
|
|
|
|
|
|
|
if ($scale >= 1 && $p['intype'] == $type) {
|
|
|
|
|
|
|
|
$result = ($this->image_file == $filename || copy($this->image_file, $filename)) ? '' : false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
if ($scale >= 1) {
|
|
|
|
|
|
|
|
$width = $props['width'];
|
|
|
|
|
|
|
|
$height = $props['height'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
$width = intval($props['width'] * $scale);
|
|
|
|
|
|
|
|
$height = intval($props['height'] * $scale);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$valid_types = "bmp,eps,gif,jp2,jpg,png,svg,tif";
|
|
|
|
|
|
|
|
|
|
|
|
if (in_array($type, explode(',', $p['types']))) { // Valid type?
|
|
|
|
$p += array(
|
|
|
|
$result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace sRGB -strip -quality {quality} {-opts} {intype}:{in} {type}:{out}', $p);
|
|
|
|
'type' => $type,
|
|
|
|
|
|
|
|
'quality' => 75,
|
|
|
|
|
|
|
|
'size' => $width . 'x' . $height,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (in_array($type, explode(',', $valid_types))) { // Valid type?
|
|
|
|
|
|
|
|
$result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace sRGB -strip'
|
|
|
|
|
|
|
|
. ' -quality {quality} -resize {size} {intype}:{in} {type}:{out}', $p);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($result === '') {
|
|
|
|
if ($result === '') {
|
|
|
@ -161,13 +186,12 @@ class rcube_image
|
|
|
|
// Imagemagick resize is implemented in shrinking mode (see -resize argument above)
|
|
|
|
// Imagemagick resize is implemented in shrinking mode (see -resize argument above)
|
|
|
|
// we do the same here, if an image is smaller than specified size
|
|
|
|
// we do the same here, if an image is smaller than specified size
|
|
|
|
// we do nothing but copy original file to destination file
|
|
|
|
// we do nothing but copy original file to destination file
|
|
|
|
if ($scale > 1) {
|
|
|
|
if ($scale >= 1) {
|
|
|
|
return $this->image_file == $filename || copy($this->image_file, $filename) ? $type : false;
|
|
|
|
$result = $this->image_file == $filename || copy($this->image_file, $filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
$width = $props['width'] * $scale;
|
|
|
|
$width = intval($props['width'] * $scale);
|
|
|
|
$height = $props['height'] * $scale;
|
|
|
|
$height = intval($props['height'] * $scale);
|
|
|
|
|
|
|
|
|
|
|
|
$new_image = imagecreatetruecolor($width, $height);
|
|
|
|
$new_image = imagecreatetruecolor($width, $height);
|
|
|
|
|
|
|
|
|
|
|
|
// Fix transparency of gif/png image
|
|
|
|
// Fix transparency of gif/png image
|
|
|
@ -190,6 +214,7 @@ class rcube_image
|
|
|
|
elseif($props['gd_type'] == IMAGETYPE_PNG) {
|
|
|
|
elseif($props['gd_type'] == IMAGETYPE_PNG) {
|
|
|
|
$result = imagepng($image, $filename, 6, PNG_ALL_FILTERS);
|
|
|
|
$result = imagepng($image, $filename, 6, PNG_ALL_FILTERS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
if ($result) {
|
|
|
|
@chmod($filename, 0600);
|
|
|
|
@chmod($filename, 0600);
|
|
|
|