Changeset 6022 in subversion
- Timestamp:
- Mar 19, 2012 6:44:57 AM (14 months ago)
- Location:
- trunk/roundcubemail
- Files:
-
- 1 added
- 3 edited
-
CHANGELOG (modified) (1 diff)
-
program/include/rcmail.php (modified) (1 diff)
-
program/include/rcube_image.php (added)
-
program/steps/addressbook/upload_photo.inc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/CHANGELOG
r6012 r6022 2 2 =========================== 3 3 4 - Image resize with GD extension (#1488383) 4 5 - Fix lack of warning when switching task in compose window (#1488399) 5 6 - Fix bug where it wasn't possible to enter ( or & characters in autocomplete fields -
trunk/roundcubemail/program/include/rcmail.php
r5904 r6022 1538 1538 1539 1539 /** 1540 * Use imagemagick or GD lib to read image properties1541 *1542 * @param string Absolute file path1543 * @return mixed Hash array with image props like type, width, height or False on error1544 */1545 public static function imageprops($filepath)1546 {1547 $rcmail = rcmail::get_instance();1548 if ($cmd = $rcmail->config->get('im_identify_path', false)) {1549 list(, $type, $size) = explode(' ', strtolower(rcmail::exec($cmd. ' 2>/dev/null {in}', array('in' => $filepath))));1550 if ($size)1551 list($width, $height) = explode('x', $size);1552 }1553 else if (function_exists('getimagesize')) {1554 $imsize = @getimagesize($filepath);1555 $width = $imsize[0];1556 $height = $imsize[1];1557 $type = preg_replace('!image/!', '', $imsize['mime']);1558 }1559 1560 return $type ? array('type' => $type, 'width' => $width, 'height' => $height) : false;1561 }1562 1563 1564 /**1565 * Convert an image to a given size and type using imagemagick (ensures input is an image)1566 *1567 * @param $p['in'] Input filename (mandatory)1568 * @param $p['out'] Output filename (mandatory)1569 * @param $p['size'] Width x height of resulting image, e.g. "160x60"1570 * @param $p['type'] Output file type, e.g. "jpg"1571 * @param $p['-opts'] Custom command line options to ImageMagick convert1572 * @return Success of convert as true/false1573 */1574 public static function imageconvert($p)1575 {1576 $result = false;1577 $rcmail = rcmail::get_instance();1578 $convert = $rcmail->config->get('im_convert_path', false);1579 $identify = $rcmail->config->get('im_identify_path', false);1580 1581 // imagemagick is required for this1582 if (!$convert)1583 return false;1584 1585 if (!(($imagetype = @exif_imagetype($p['in'])) && ($type = image_type_to_extension($imagetype, false))))1586 list(, $type) = explode(' ', strtolower(rcmail::exec($identify . ' 2>/dev/null {in}', $p))); # for things like eps1587 1588 $type = strtr($type, array("jpeg" => "jpg", "tiff" => "tif", "ps" => "eps", "ept" => "eps"));1589 $p += array('type' => $type, 'types' => "bmp,eps,gif,jp2,jpg,png,svg,tif", 'quality' => 75);1590 $p['-opts'] = array('-resize' => $p['size'].'>') + (array)$p['-opts'];1591 1592 if (in_array($type, explode(',', $p['types']))) # Valid type?1593 $result = rcmail::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p) === "";1594 1595 return $result;1596 }1597 1598 1599 /**1600 1540 * Construct shell command, execute it and return output as string. 1601 1541 * Keywords {keyword} are replaced with arguments -
trunk/roundcubemail/program/steps/addressbook/upload_photo.inc
r5787 r6022 32 32 if ($filepath = $_FILES['_photo']['tmp_name']) { 33 33 // check file type and resize image 34 $imageprop = rcmail::imageprops($_FILES['_photo']['tmp_name']); 34 $image = new rcube_image($_FILES['_photo']['tmp_name']); 35 $imageprop = $image->props(); 35 36 36 37 if (in_array(strtolower($imageprop['type']), $IMAGE_TYPES) 37 && $imageprop['width'] && $imageprop['height']38 && $imageprop['width'] && $imageprop['height'] 38 39 ) { 39 $maxsize = intval($RCMAIL->config->get('contact_photo_size', 160));40 $tmpfname = tempnam($RCMAIL->config->get('temp_dir'), 'rcmImgConvert');40 $maxsize = intval($RCMAIL->config->get('contact_photo_size', 160)); 41 $tmpfname = tempnam($RCMAIL->config->get('temp_dir'), 'rcmImgConvert'); 41 42 $save_hook = 'attachment_upload'; 42 43 43 44 // scale image to a maximum size 44 if (($imageprop['width'] > $maxsize || $imageprop['height'] > $maxsize) && 45 (rcmail::imageconvert(array('in' => $filepath, 'out' => $tmpfname, 46 'size' => $maxsize.'x'.$maxsize, 'type' => $imageprop['type'])) !== false)) { 47 $filepath = $tmpfname; 45 if (($imageprop['width'] > $maxsize || $imageprop['height'] > $maxsize) && $image->resize($maxsize, $tmpfname)) { 46 $filepath = $tmpfname; 48 47 $save_hook = 'attachment_save'; 49 48 } … … 58 57 )); 59 58 } 60 else 59 else { 61 60 $attachment['error'] = rcube_label('invalidimageformat'); 61 } 62 62 63 63 if ($attachment['status'] && !$attachment['abort']) {
Note: See TracChangeset
for help on using the changeset viewer.
