Image_Tools
[ class tree: Image_Tools ] [ index: Image_Tools ] [ all elements ]

Source for file Utils.php

Documentation is available at Utils.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
  3.  
  4. /**
  5.  * This file contains the Image_Tools_Utils class.
  6.  *
  7.  * PHP version 4 and 5
  8.  *
  9.  * LICENSE:
  10.  * Copyright (c) 2008 Firman Wandayandi <firman@php.net>
  11.  * All rights reserved.
  12.  *
  13.  * This source file is subject to the BSD License license that is bundled
  14.  * with this package in the file LICENSE.txt.
  15.  * It is also available through the world-wide-web at this URL:
  16.  * http://www.opensource.org/licenses/bsd-license.php
  17.  * If you did not receive a copy of the license and are unable to
  18.  * obtain it through the world-wide-web, please send an email
  19.  * to pear-dev@list.php.net so we can send you a copy immediately.
  20.  *
  21.  * @category    Images
  22.  * @package     Image_Tools
  23.  * @author      Firman Wandayandi <firman@php.net>
  24.  * @copyright   Copyright (c) 2008 Firman Wandayandi <firman@php.net>
  25.  * @license     http://www.opensource.org/licenses/bsd-license.php
  26.  *               BSD License
  27.  * @version     $Id: Utils.php,v 1.1 2008/05/26 05:03:59 firman Exp $
  28.  * @since       File available since Release 1.0.0RC1
  29.  */
  30.  
  31. /**
  32.  * Image tools utilities class.
  33.  *
  34.  * @category    Images
  35.  * @package     Image_Tools
  36.  * @author      Firman Wandayandi <firman@php.net>
  37.  * @copyright   Copyright (c) 2008 Firman Wandayandi <firman@php.net>
  38.  * @license     http://www.opensource.org/licenses/bsd-license.php
  39.  *               BSD License
  40.  * @version     Release: 1.0.0RC1
  41.  * @since       Class available since Release 1.0.0RC1
  42.  */
  43. {
  44.     // {{{ colorToRGBA()
  45.  
  46.     /**
  47.      * Convert various color format to RGBA array.
  48.      *
  49.      * @param mixed $color Color value (array, string or integer)
  50.      * @return array|FALSEAn RGBA array or FALSE on failure
  51.      * @access public
  52.      * @static
  53.      */
  54.     function colorToRGBA($color)
  55.     {
  56.         if (is_array($color)) {
  57.             if (isset($color['r']&& isset($color['g']&& isset($color['b'])) {
  58.                 $color['a'= isset($color['a']$color['a': 0;
  59.                 return $color;
  60.             else if (isset($color[0]&& isset($color[1]&& isset($color[2])) {
  61.                 $color[3= isset($color[3]$color[3: 0;
  62.                 return array(
  63.                     'r' => $color[0],
  64.                     'g' => $color[1],
  65.                     'b' => $color[2],
  66.                     'a' => $color[3]
  67.                 );
  68.             }
  69.         else if (is_string($color)) {
  70.             $regex '/^[#|]?([a-f0-9]{2})?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/i';
  71.             if (preg_match($regex$color$matches)) {
  72.                 return array(
  73.                     'r' => hexdec($matches[2]),
  74.                     'g' => hexdec($matches[3]),
  75.                     'b' => hexdec($matches[4]),
  76.                     'a' => !empty($matches[1]hexdec($matches[1]: 0
  77.                 );
  78.             }
  79.         elseif (is_int($color)) {
  80.             return array(
  81.                 'r' => ($color >> 160xff,
  82.                 'g' => ($color >> 80xff,
  83.                 'b' => ($color >> 00xff,
  84.                 'a' => ($color >> 240xff
  85.             );
  86.         }
  87.         return false;
  88.     }
  89.  
  90.     // }}}
  91.     // {{{ getGDVersion()
  92.  
  93.     /**
  94.      * Get the loaded GD version.
  95.      *
  96.      * @return string Version
  97.      * @access protected
  98.      * @static
  99.      */
  100.     function getGDVersion()
  101.     {
  102.         $info gd_info();
  103.         if (preg_match('/\((.+)\)/'$info['GD Version']$matches)) {
  104.             return $matches[1];
  105.         }
  106.         return false;
  107.     }
  108.  
  109.     // }}}
  110.     // {{{ compareGDVersion()
  111.  
  112.     /**
  113.      * Compare the "PHP-standardized" version number string with the
  114.      * current loaded GD.
  115.      *
  116.      * @param string $version 
  117.      * @param string $operator 
  118.      * @return boolean 
  119.      * @static
  120.      */
  121.     function compareGDVersion($version$operator)
  122.     {
  123.         return version_compare(Image_Tools_Utils::getGDVersion()$version$operator);
  124.     }
  125.  
  126.     // }}}
  127. }

Documentation generated on Mon, 26 May 2008 06:30:15 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.