Exemplo n.º 1
0
function resizeImage($src_img, $destName, $src_width, $src_height, $max_width, $max_height, $force_resize = false, $preferred_format = 0)
{
    global $gd2, $modSettings;
    // Without GD, no image resizing at all.
    if (!checkGD()) {
        return false;
    }
    $success = false;
    // Determine whether to resize to max width or to max height (depending on the limits.)
    if (!empty($max_width) || !empty($max_height)) {
        if (!empty($max_width) && (empty($max_height) || $src_height * $max_width / $src_width <= $max_height)) {
            $dst_width = $max_width;
            $dst_height = floor($src_height * $max_width / $src_width);
        } elseif (!empty($max_height)) {
            $dst_width = floor($src_width * $max_height / $src_height);
            $dst_height = $max_height;
        }
        // Don't bother resizing if it's already smaller...
        if (!empty($dst_width) && !empty($dst_height) && ($dst_width < $src_width || $dst_height < $src_height || $force_resize)) {
            // (make a true color image, because it just looks better for resizing.)
            if ($gd2) {
                $dst_img = imagecreatetruecolor($dst_width, $dst_height);
                // Deal nicely with a PNG - because we can.
                if (!empty($preferred_format) && $preferred_format == 3) {
                    imagealphablending($dst_img, false);
                    if (function_exists('imagesavealpha')) {
                        imagesavealpha($dst_img, true);
                    }
                }
            } else {
                $dst_img = imagecreate($dst_width, $dst_height);
            }
            // Resize it!
            if ($gd2) {
                imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
            } else {
                imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
            }
        } else {
            $dst_img = $src_img;
        }
    } else {
        $dst_img = $src_img;
    }
    // Save the image as ...
    if (!empty($preferred_format) && $preferred_format == 3 && function_exists('imagepng')) {
        $success = imagepng($dst_img, $destName);
    } elseif (!empty($preferred_format) && $preferred_format == 1 && function_exists('imagegif')) {
        $success = imagegif($dst_img, $destName);
    } elseif (function_exists('imagejpeg')) {
        $success = imagejpeg($dst_img, $destName);
    }
    // Free the memory.
    imagedestroy($src_img);
    if ($dst_img != $src_img) {
        imagedestroy($dst_img);
    }
    return $success;
}
 public function check_requirements()
 {
     function t($category, $message, $params = array())
     {
         return $message;
     }
     function checkProtectedDirectory()
     {
         $testfile = Yii::app()->getRequest()->getHostInfo() . Yii::app()->getBaseUrl() . '/protected/data/daemon/schema.mysql.sql';
         $f = @file_get_contents($testfile);
         if (strlen($f)) {
             return 'The "protected" directory of your front end must not be accessible through the webserver, please see:<br/><a href="http://multicraft.org/site/page?view=troubleshooting#protected_accessible" target="_blank">Troubleshooting: "protected" directory</a>';
         }
         return '';
     }
     //BEGIN YII REQUIREMENTS CHECK SCRIPT
     /**
      * Yii Requirement Checker script
      *
      * This script will check if your system meets the requirements for running
      * Yii-powered Web applications.
      *
      * @author Qiang Xue <*****@*****.**>
      * @link http://www.yiiframework.com/
      * @copyright Copyright &copy; 2008-2011 Yii Software LLC
      * @license http://www.yiiframework.com/license/
      * @version $Id: index.php 2986 2011-02-20 17:08:50Z alexander.makarow $
      * @package system
      * @since 1.0
      */
     function checkServerVar()
     {
         $vars = array('HTTP_HOST', 'SERVER_NAME', 'SERVER_PORT', 'SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF', 'HTTP_ACCEPT', 'HTTP_USER_AGENT');
         $missing = array();
         foreach ($vars as $var) {
             if (!isset($_SERVER[$var])) {
                 $missing[] = $var;
             }
         }
         if (!empty($missing)) {
             return t('yii', '$_SERVER does not have {vars}.', array('{vars}' => implode(', ', $missing)));
         }
         if (realpath($_SERVER["SCRIPT_FILENAME"]) !== realpath(dirname(__FILE__) . '/../../install.php')) {
             return t('yii', '$_SERVER["SCRIPT_FILENAME"] must be the same as the entry script file path.');
         }
         if (!isset($_SERVER["REQUEST_URI"]) && isset($_SERVER["QUERY_STRING"])) {
             return t('yii', 'Either $_SERVER["REQUEST_URI"] or $_SERVER["QUERY_STRING"] must exist.');
         }
         if (!isset($_SERVER["PATH_INFO"]) && strpos($_SERVER["PHP_SELF"], $_SERVER["SCRIPT_NAME"]) !== 0) {
             return t('yii', 'Unable to determine URL path info. Please make sure $_SERVER["PATH_INFO"] (or $_SERVER["PHP_SELF"] and $_SERVER["SCRIPT_NAME"]) contains proper value.');
         }
         return '';
     }
     function checkGD()
     {
         if (extension_loaded('gd')) {
             $gdinfo = gd_info();
             if ($gdinfo['FreeType Support']) {
                 return '';
             }
             return t('yii', 'GD installed<br />FreeType support not installed');
         }
         return t('yii', 'GD not installed');
     }
     /**
      * @var array List of requirements (name, required or not, result, used by, memo)
      */
     $requirements = array(array(t('yii', 'PHP version'), true, version_compare(PHP_VERSION, "5.1.0", ">="), '<a href="http://www.yiiframework.com">Yii Framework</a>', t('yii', 'PHP 5.1.0 or higher is required.')), array(t('yii', '$_SERVER variable'), true, ($message = checkServerVar()) === '', '<a href="http://www.yiiframework.com">Yii Framework</a>', $message), array(t('yii', 'Reflection extension'), true, class_exists('Reflection', false), '<a href="http://www.yiiframework.com">Yii Framework</a>', ''), array(t('yii', 'PCRE extension'), true, extension_loaded("pcre"), '<a href="http://www.yiiframework.com">Yii Framework</a>', ''), array(t('yii', 'SPL extension'), true, extension_loaded("SPL"), '<a href="http://www.yiiframework.com">Yii Framework</a>', ''), array(t('yii', 'Protected directory'), true, ($message = checkProtectedDirectory()) === '', 'System Security', $message), array(t('yii', 'PDO extension'), true, extension_loaded('pdo'), t('mc', 'All database connections'), t('mc', 'The PHP PDO extension is always required.')), array(t('yii', 'PDO SQLite extension'), false, extension_loaded('pdo_sqlite'), t('yii', 'SQLite Database connection'), t('yii', 'This is required if you are using an SQLite database.')), array(t('yii', 'PDO MySQL extension'), false, extension_loaded('pdo_mysql'), t('yii', 'MySQL database connection'), t('yii', 'This is required if you are using a MySQL database.')), array(t('yii', 'GD extension with<br />FreeType support'), false, ($message = checkGD()) === '', t('mc', 'Multicraft status banner and registration captcha'), t('mc', 'Only required if you want to use the status banners or registration captcha.') . ' ' . $message));
     $result = 1;
     // 1: all pass, 0: fail, -1: pass with warnings
     foreach ($requirements as $i => $requirement) {
         if ($requirement[1] && !$requirement[2]) {
             $result = 0;
         } else {
             if ($result > 0 && !$requirement[1] && !$requirement[2]) {
                 $result = -1;
             }
         }
         if ($requirement[4] === '') {
             $requirements[$i][4] = '&nbsp;';
         }
     }
     //END YII REQUIREMENTS CHECK SCRIPT
     if ($result > 0) {
         $this->p['actions'][] = 'All requirements met';
     } else {
         if ($result < 0) {
             $this->p['actions'][] = 'Minimum requirements met, some functionality may be unavailable';
         } else {
             $this->p['actions'][] = 'Minumum requirements not met';
         }
     }
     $this->p['requirements'] = $requirements;
     $this->p['result'] = $result;
     return true;
 }
Exemplo n.º 3
0
/**
 * Resizes an image proportionally to fit within the defined max_width and max_height limits
 *
 * - Will do nothing to the image if the file fits within the size limits
 * - If Image Magick is present it will use those function over any GD solutions
 * - If GD2 is present, it'll use it to achieve better quality (imagecopyresampled)
 * - Saves the new image to destination_filename, in the preferred_format
 * if possible, default is jpeg.
 *
 * @uses GD
 * @uses Imagick
 *
 * @package Graphics
 * @param resource|null $src_img null for Imagick images, resource form imagecreatefrom for GD
 * @param string $destName
 * @param int $src_width
 * @param int $src_height
 * @param int $max_width
 * @param int $max_height
 * @param bool $force_resize = false
 * @param int $preferred_format = 0
 */
function resizeImage($src_img, $destName, $src_width, $src_height, $max_width, $max_height, $force_resize = false, $preferred_format = 0)
{
    global $gd2;
    if (checkImagick()) {
        // These are the file formats we know about
        static $default_formats = array('1' => 'gif', '2' => 'jpeg', '3' => 'png', '6' => 'bmp', '15' => 'wbmp');
        $preferred_format = empty($preferred_format) || !isset($default_formats[$preferred_format]) ? 2 : $preferred_format;
        // Since Imagick can throw exceptions, lets catch them
        try {
            // Get a new instance of Imagick for use
            $imagick = new Imagick($destName);
            // Set the input and output image size
            $src_width = empty($src_width) ? $imagick->getImageWidth() : $src_width;
            $src_height = empty($src_height) ? $imagick->getImageHeight() : $src_height;
            $dest_width = empty($max_width) ? $src_width : $max_width;
            $dest_height = empty($max_height) ? $src_height : $max_height;
            // Create a new image in our prefered format and resize it if needed
            $imagick->setImageFormat($default_formats[$preferred_format]);
            $imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true);
            // Save the new image in the destination location
            $success = $imagick->writeImage($destName);
            // Free resources associated with the Imagick object
            $imagick->destroy();
        } catch (Exception $e) {
            // Not currently used, but here is the error
            $success = $e->getMessage();
            $success = false;
        }
        return !empty($success);
    } elseif (checkGD()) {
        $success = false;
        // Determine whether to resize to max width or to max height (depending on the limits.)
        if (!empty($max_width) || !empty($max_height)) {
            if (!empty($max_width) && (empty($max_height) || $src_height * $max_width / $src_width <= $max_height)) {
                $dst_width = $max_width;
                $dst_height = floor($src_height * $max_width / $src_width);
            } elseif (!empty($max_height)) {
                $dst_width = floor($src_width * $max_height / $src_height);
                $dst_height = $max_height;
            }
            // Don't bother resizing if it's already smaller...
            if (!empty($dst_width) && !empty($dst_height) && ($dst_width < $src_width || $dst_height < $src_height || $force_resize)) {
                // (make a true color image, because it just looks better for resizing.)
                if ($gd2) {
                    $dst_img = imagecreatetruecolor($dst_width, $dst_height);
                    // Deal nicely with a PNG - because we can.
                    if (!empty($preferred_format) && $preferred_format == 3) {
                        imagealphablending($dst_img, false);
                        if (function_exists('imagesavealpha')) {
                            imagesavealpha($dst_img, true);
                        }
                    }
                } else {
                    $dst_img = imagecreate($dst_width, $dst_height);
                }
                // Resize it!
                if ($gd2) {
                    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
                } else {
                    imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
                }
            } else {
                $dst_img = $src_img;
            }
        } else {
            $dst_img = $src_img;
        }
        // Save the image as ...
        if (!empty($preferred_format) && $preferred_format == 3 && function_exists('imagepng')) {
            $success = imagepng($dst_img, $destName);
        } elseif (!empty($preferred_format) && $preferred_format == 1 && function_exists('imagegif')) {
            $success = imagegif($dst_img, $destName);
        } elseif (function_exists('imagejpeg')) {
            $success = imagejpeg($dst_img, $destName, 80);
        }
        // Free the memory.
        imagedestroy($src_img);
        if ($dst_img != $src_img) {
            imagedestroy($dst_img);
        }
        return $success;
    } else {
        return false;
    }
}
Exemplo n.º 4
0
 *
 * This script will check if your system meets the requirements for running
 * Yii-powered Web applications.
 *
 * @author Qiang Xue <*****@*****.**>
 * @link http://www.yiiframework.com/
 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 * @version $Id$
 * @package system
 * @since 1.0
 */
/**
 * @var array List of requirements (name, required or not, result, used by, memo)
 */
$requirements = array(array(t('yii', 'PHP version'), true, version_compare(PHP_VERSION, "5.1.0", ">="), '<a href="http://www.yiiframework.com">Yii Framework</a>', t('yii', 'PHP 5.1.0 or higher is required.')), array(t('yii', '$_SERVER variable'), true, ($message = checkServerVar()) === '', '<a href="http://www.yiiframework.com">Yii Framework</a>', $message), array(t('yii', 'Reflection extension'), true, class_exists('Reflection', false), '<a href="http://www.yiiframework.com">Yii Framework</a>', ''), array(t('yii', 'PCRE extension'), true, extension_loaded("pcre"), '<a href="http://www.yiiframework.com">Yii Framework</a>', ''), array(t('yii', 'SPL extension'), true, extension_loaded("SPL"), '<a href="http://www.yiiframework.com">Yii Framework</a>', ''), array(t('yii', 'DOM extension'), false, class_exists("DOMDocument", false), '<a href="http://www.yiiframework.com/doc/api/CHtmlPurifier">CHtmlPurifier</a>, <a href="http://www.yiiframework.com/doc/api/CWsdlGenerator">CWsdlGenerator</a>', ''), array(t('yii', 'PDO extension'), false, extension_loaded('pdo'), t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'), ''), array(t('yii', 'PDO SQLite extension'), false, extension_loaded('pdo_sqlite'), t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'), t('yii', 'This is required if you are using SQLite database.')), array(t('yii', 'PDO MySQL extension'), false, extension_loaded('pdo_mysql'), t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'), t('yii', 'This is required if you are using MySQL database.')), array(t('yii', 'PDO PostgreSQL extension'), false, extension_loaded('pdo_pgsql'), t('yii', 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'), t('yii', 'This is required if you are using PostgreSQL database.')), array(t('yii', 'Memcache extension'), false, extension_loaded("memcache") || extension_loaded("memcached"), '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>', extension_loaded("memcached") ? t('yii', 'To use memcached set <a href="http://www.yiiframework.com/doc/api/CMemCache#useMemcached-detail">CMemCache::useMemcached</a> to <code>true</code>.') : ''), array(t('yii', 'APC extension'), false, extension_loaded("apc"), '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>', ''), array(t('yii', 'Mcrypt extension'), false, extension_loaded("mcrypt"), '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>', t('yii', 'This is required by encrypt and decrypt methods.')), array(t('yii', 'SOAP extension'), false, extension_loaded("soap"), '<a href="http://www.yiiframework.com/doc/api/CWebService">CWebService</a>, <a href="http://www.yiiframework.com/doc/api/CWebServiceAction">CWebServiceAction</a>', ''), array(t('yii', 'GD extension with<br />FreeType support'), false, ($message = checkGD()) === '', '<a href="http://www.yiiframework.com/doc/api/CCaptchaAction">CCaptchaAction</a>', $message), array(t('yii', 'Ctype extension'), false, extension_loaded("ctype"), '<a href="http://www.yiiframework.com/doc/api/CDateFormatter">CDateFormatter</a>, <a href="http://www.yiiframework.com/doc/api/CDateFormatter">CDateTimeParser</a>, <a href="http://www.yiiframework.com/doc/api/CTextHighlighter">CTextHighlighter</a>, <a href="http://www.yiiframework.com/doc/api/CHtmlPurifier">CHtmlPurifier</a>', ''));
function checkServerVar()
{
    $vars = array('HTTP_HOST', 'SERVER_NAME', 'SERVER_PORT', 'SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF', 'HTTP_ACCEPT', 'HTTP_USER_AGENT');
    $missing = array();
    foreach ($vars as $var) {
        if (!isset($_SERVER[$var])) {
            $missing[] = $var;
        }
    }
    if (!empty($missing)) {
        return t('yii', '$_SERVER does not have {vars}.', array('{vars}' => implode(', ', $missing)));
    }
    if (realpath($_SERVER["SCRIPT_FILENAME"]) !== realpath(__FILE__)) {
        return t('yii', '$_SERVER["SCRIPT_FILENAME"] must be the same as the entry script file path.');
    }
Exemplo n.º 5
0
/**
 * Resizes src_img proportionally to fit within max_width and max_height limits
 * if it is too large.
 * If GD2 is present, it'll use it to achieve better quality.
 * It saves the new image to destination_filename, as preferred_format
 * if possible, default is jpeg.
 * @uses GD
 *
 * @param resource $src_img
 * @param string $destName
 * @param int $src_width
 * @param int $src_height
 * @param int $max_width
 * @param int $max_height
 * @param bool $force_resize = false
 * @param int $preferred_format = 0
 */
function resizeImage($src_img, $destName, $src_width, $src_height, $max_width, $max_height, $force_resize = false, $preferred_format = 0)
{
    global $gd2, $modSettings;
    if (checkImagick()) {
        static $default_formats = array('1' => 'gif', '2' => 'jpeg', '3' => 'png', '6' => 'bmp', '15' => 'wbmp');
        $preferred_format = empty($preferred_format) || !isset($default_formats[$preferred_format]) ? 2 : $preferred_format;
        $imagick = new Imagick($destName);
        $src_width = empty($src_width) ? $imagick->getImageWidth() : $src_width;
        $src_height = empty($src_height) ? $imagick->getImageHeight() : $src_height;
        $dest_width = empty($max_width) ? $src_width : $max_width;
        $dest_height = empty($max_height) ? $src_height : $max_height;
        $imagick->setImageFormat($default_formats[$preferred_format]);
        $imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true);
        $success = $imagick->writeImage($destName);
        return !empty($success);
    } elseif (checkGD()) {
        $success = false;
        // Determine whether to resize to max width or to max height (depending on the limits.)
        if (!empty($max_width) || !empty($max_height)) {
            if (!empty($max_width) && (empty($max_height) || $src_height * $max_width / $src_width <= $max_height)) {
                $dst_width = $max_width;
                $dst_height = floor($src_height * $max_width / $src_width);
            } elseif (!empty($max_height)) {
                $dst_width = floor($src_width * $max_height / $src_height);
                $dst_height = $max_height;
            }
            // Don't bother resizing if it's already smaller...
            if (!empty($dst_width) && !empty($dst_height) && ($dst_width < $src_width || $dst_height < $src_height || $force_resize)) {
                // (make a true color image, because it just looks better for resizing.)
                if ($gd2) {
                    $dst_img = imagecreatetruecolor($dst_width, $dst_height);
                    // Deal nicely with a PNG - because we can.
                    if (!empty($preferred_format) && $preferred_format == 3) {
                        imagealphablending($dst_img, false);
                        if (function_exists('imagesavealpha')) {
                            imagesavealpha($dst_img, true);
                        }
                    }
                } else {
                    $dst_img = imagecreate($dst_width, $dst_height);
                }
                // Resize it!
                if ($gd2) {
                    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
                } else {
                    imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
                }
            } else {
                $dst_img = $src_img;
            }
        } else {
            $dst_img = $src_img;
        }
        // Save the image as ...
        if (!empty($preferred_format) && $preferred_format == 3 && function_exists('imagepng')) {
            $success = imagepng($dst_img, $destName);
        } elseif (!empty($preferred_format) && $preferred_format == 1 && function_exists('imagegif')) {
            $success = imagegif($dst_img, $destName);
        } elseif (function_exists('imagejpeg')) {
            $success = imagejpeg($dst_img, $destName);
        }
        // Free the memory.
        imagedestroy($src_img);
        if ($dst_img != $src_img) {
            imagedestroy($dst_img);
        }
        return $success;
    } else {
        // Without GD, no image resizing at all.
        return false;
    }
}
Exemplo n.º 6
0
<?php

$requirements = array(array('PHP版本', true, version_compare(PHP_VERSION, "5.2.1", ">="), 'PHP 5.2.1或更高版本是必须的。'), array('$_SERVER变量', true, ($message = checkServerVar()) === '', $message), array('Reflection扩展模块', true, class_exists('Reflection', false), ''), array('PCRE扩展模块', true, extension_loaded("pcre"), ''), array('SPL扩展模块', true, extension_loaded("SPL"), ''), array('DOM扩展模块', false, class_exists("DOMDocument", false), ''), array('PDO扩展模块', false, extension_loaded('pdo'), '要使用数据库,此模块是必须'), array('PDO MySQL扩展模块', false, extension_loaded('pdo_mysql'), '如果使用MySQL数据库,这是必须的。'), array('Memcache扩展模块', false, extension_loaded("memcache") || extension_loaded("memcached"), '如果要使用memcached缓存服务器,需要此模块'), array('Mcrypt扩展模块', false, extension_loaded("mcrypt"), '如果用到加密解密功能,会需要此模块'), array('GD extension with<br />FreeType support', false, ($message = checkGD()) === '', $message === '' ? '验证码及图表功能会用到GD模块' : $message), array('Ctype extension', false, extension_loaded("ctype"), ''));
function checkServerVar()
{
    $vars = array('HTTP_HOST', 'SERVER_NAME', 'SERVER_PORT', 'SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF', 'HTTP_ACCEPT', 'HTTP_USER_AGENT');
    $missing = array();
    foreach ($vars as $var) {
        if (!isset($_SERVER[$var])) {
            $missing[] = $var;
        }
    }
    if (!empty($missing)) {
        return '$_SERVER does not have .' . array('{vars}' => implode(', ', $missing));
    }
    //     if(realpath($_SERVER["SCRIPT_FILENAME"]) !== realpath(__FILE__))
    //         return '$_SERVER["SCRIPT_FILENAME"] must be the same as the entry script file path.';
    if (!isset($_SERVER["REQUEST_URI"]) && isset($_SERVER["QUERY_STRING"])) {
        return 'Either $_SERVER["REQUEST_URI"] or $_SERVER["QUERY_STRING"] must exist.';
    }
    if (!isset($_SERVER["PATH_INFO"]) && strpos($_SERVER["PHP_SELF"], $_SERVER["SCRIPT_NAME"]) !== 0) {
        return 'Unable to determine URL path info. Please make sure $_SERVER["PATH_INFO"] (or $_SERVER["PHP_SELF"] and $_SERVER["SCRIPT_NAME"]) contains proper value.';
    }
    return '';
}
function checkGD()
{
    if (extension_loaded('gd')) {
        $gdinfo = gd_info();
        if ($gdinfo['FreeType Support']) {
            return '';