Changeset a71a97f in github


Ignore:
Timestamp:
Mar 19, 2012 6:44:57 AM (15 months ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.8
Children:
4cf42fd
Parents:
d1e3430
Message:
  • Image resize with GD extension (#1488383)
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    rb9ce92d ra71a97f  
    22=========================== 
    33 
     4- Image resize with GD extension (#1488383) 
    45- Fix lack of warning when switching task in compose window (#1488399) 
    56- Fix bug where it wasn't possible to enter ( or & characters in autocomplete fields 
  • program/include/rcmail.php

    r40d246f ra71a97f  
    15381538 
    15391539  /** 
    1540    * Use imagemagick or GD lib to read image properties 
    1541    * 
    1542    * @param string Absolute file path 
    1543    * @return mixed Hash array with image props like type, width, height or False on error 
    1544    */ 
    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 convert 
    1572    * @return Success of convert as true/false 
    1573    */ 
    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 this 
    1582     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 eps 
    1587  
    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   /** 
    16001540   * Construct shell command, execute it and return output as string. 
    16011541   * Keywords {keyword} are replaced with arguments 
  • program/steps/addressbook/upload_photo.inc

    r7fe3811 ra71a97f  
    3232if ($filepath = $_FILES['_photo']['tmp_name']) { 
    3333    // 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(); 
    3536 
    3637    if (in_array(strtolower($imageprop['type']), $IMAGE_TYPES) 
    37         && $imageprop['width'] && $imageprop['height'] 
     38        && $imageprop['width'] && $imageprop['height'] 
    3839    ) { 
    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'); 
    4142        $save_hook = 'attachment_upload'; 
    4243 
    4344        // 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; 
    4847            $save_hook = 'attachment_save'; 
    4948        } 
     
    5857        )); 
    5958    } 
    60     else 
     59    else { 
    6160        $attachment['error'] = rcube_label('invalidimageformat'); 
     61    } 
    6262 
    6363    if ($attachment['status'] && !$attachment['abort']) { 
Note: See TracChangeset for help on using the changeset viewer.