Aleksander Machniak
2013-08-09 328876db5c760dc1c2bda1fed1e6daab285a8e2f
Fix image scaling issues when image has only one dimension smaller than the limit (#1489274)
Other small code improvements.
4 files modified
53 ■■■■ changed files
CHANGELOG 1 ●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_image.php 47 ●●●● patch | view | raw | blame | history
skins/classic/addressbook.css 3 ●●●● patch | view | raw | blame | history
skins/larry/addressbook.css 2 ●●● patch | view | raw | blame | history
CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
- Fix image scaling issues when image has only one dimension smaller than the limit (#1489274)
- Fix issue where uploaded photo was lost when contact form did not validate (#1489274)
- Fix base URL resolving on attribute values with no quotes (#1489275)
- Fix wrong handling of links with '|' character (#1489276)
program/lib/Roundcube/rcube_image.php
@@ -105,7 +105,6 @@
        if ($convert) {
            $p['out']  = $filename;
            $p['in']   = $this->image_file;
            $p['size'] = $size.'x'.$size;
            $type      = $props['type'];
            if (!$type && ($data = $this->identify())) {
@@ -120,11 +119,37 @@
                $type = 'jpg';
            }
            $p += array('type' => $type, 'types' => "bmp,eps,gif,jp2,jpg,png,svg,tif", 'quality' => 75);
            $p['-opts'] = array('-resize' => $p['size'].'>');
            // If only one dimension is greater than the limit convert doesn't
            // work as expected, we need to calculate new dimensions
            $scale = $size / max($props['width'], $props['height']);
            if (in_array($type, explode(',', $p['types']))) { // Valid type?
                $result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace sRGB -strip -quality {quality} {-opts} {intype}:{in} {type}:{out}', $p);
            // 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";
                $p += array(
                    '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 === '') {
@@ -161,13 +186,12 @@
            // 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 nothing but copy original file to destination file
            if ($scale > 1) {
                return $this->image_file == $filename || copy($this->image_file, $filename) ? $type : false;
            if ($scale >= 1) {
                $result = $this->image_file == $filename || copy($this->image_file, $filename);
            }
            $width  = $props['width']  * $scale;
            $height = $props['height'] * $scale;
            else {
                $width     = intval($props['width']  * $scale);
                $height    = intval($props['height'] * $scale);
            $new_image = imagecreatetruecolor($width, $height);
            // Fix transparency of gif/png image
@@ -190,6 +214,7 @@
            elseif($props['gd_type'] == IMAGETYPE_PNG) {
                $result = imagepng($image, $filename, 6, PNG_ALL_FILTERS);
            }
            }
            if ($result) {
                @chmod($filename, 0600);
skins/classic/addressbook.css
@@ -357,7 +357,8 @@
}
#contactpic img {
    width: 60px;
    max-width: 60px;
    max-height: 80px;
}
#contactpic.droptarget.hover {
skins/larry/addressbook.css
@@ -219,7 +219,7 @@
}
#contactpic img {
    width: 112px;
    max-width: 112px;
    visibility: inherit;
}