Commit 903383b3 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 853662: Removing the old pear Image libraries"

parents 80b7f84b 96312e68
This diff is collapsed.
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
/**
* Image_Canvas
*
* Canvas based creation of images to facilitate different output formats
*
* PHP versions 4 and 5
*
* LICENSE: This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This library is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this library; if not, see
* <http://www.gnu.org/licenses/>
*
* @category Images
* @package Image_Canvas
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
* @copyright 2003-2009 The PHP Group
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version SVN: $Id$
* @link http://pear.php.net/package/Image_Canvas
*/
/**
* Color class to be extended; from package PEAR::Image_Color
*/
require_once 'Image/Color.php';
/**
* Class for color-handling
*
* This is used to extend the functionality of the current PEAR::Image_Color v0.4.
* I hope to be allowed to incorporate some of the improvements in a new Image_Color release.
*
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
* @package Image_Canvas
* @access public
*/
class Image_Canvas_Color extends Image_Color
{
/**
* Allocates a color in the given image.
*
* Userdefined color specifications get translated into
* an array of rgb values.
*
* @param resource &$img GD-resource
* @param mixed $color Any color representation supported by color2RGB()
*
* @return resource Image color handle
* @see color2RGB()
* @access public
* @static
*/
function allocateColor(&$img, $color)
{
$color = Image_Canvas_Color::color2RGB($color);
if (($color[3] == 255) || (!function_exists("imagecolorallocatealpha"))) {
return imagecolorallocate($img, $color[0], $color[1], $color[2]);
} else {
return imagecolorallocatealpha($img, $color[0], $color[1], $color[2], 127-round(($color[3]*127)/255));
}
}
/**
* Convert any color-representation into an array of 4 ints (RGBA).
*
* Userdefined color specifications get translated into
* an array of rgb values.
*
* @param mixed $color Any color representation supported by Image_Canvas_Color::color2RGB()
*
* @return array Array of 4 ints (RGBA-representation)
* @access public
* @static
*/
function color2RGB($color)
{
if (is_array($color)) {
if (!is_numeric($color[0])) {
return null; // error
}
if (count($color) == 3) { // assume RGB-color
// 255 = alpha-value; full opaque
return array((int) $color[0],
(int) $color[1],
(int) $color[2],
255);
}
if (count($color) == 4) { // assume RGBA-color
// 255 = alpha-value; full opaque
return array((int) $color[0],
(int) $color[1],
(int) $color[2],
(int) $color[3]);
}
return null; // error
} elseif (is_string($color)) {
$alphaPos = strpos($color, '@');
if ($alphaPos === false) {
$alpha = 255;
} else {
$alphaFloat = (float) substr($color, $alphaPos+1);
// restrict to range 0..1
$alphaFloat = max(min($alphaFloat, 1), 0);
$alpha = (int) round((float) 255 * $alphaFloat);
$color = substr($color, 0, $alphaPos);
}
if ($color[0] == '#') { // hex-color given, e.g. #FFB4B4
$tempColor = parent::hex2rgb($color);
return array((int) $tempColor[0],
(int) $tempColor[1],
(int) $tempColor[2],
$alpha);
}
if (strpos($color, '%') !== false) {
$tempColor = parent::percentageColor2RGB($color);
return array((int) $tempColor[0],
(int) $tempColor[1],
(int) $tempColor[2],
$alpha);
} else {
$tempColor = parent::namedColor2RGB($color);
return array((int) $tempColor[0],
(int) $tempColor[1],
(int) $tempColor[2],
$alpha);
}
} else {
return null; // error
}
}
/**
* getRange
* Given a degree, you can get the range of colors between one color and
* another color.
*
* @param string $degrees How much each 'step' between the colors we should take.
*
* @return array Array of all the colors, one element for each color.
* @access public
*/
function getRange ($degrees)
{
$tempColors = parent::getRange($degrees);
// now add alpha-channel information
$steps = count($tempColors);
for ($counter=0;$counter<$steps;$counter++) {
$tempColors[$counter] = parent::hex2rgb($tempColors[$counter]);
unset($tempColors[$counter]['hex']);
$tempColors[$counter][3] = (int) round(
(((float) $this->color1[3]*($steps-$counter))+
((float) $this->color2[3]*($counter))
) / $steps
);
}
return $tempColors;
}
/**
* Internal method to correctly set the colors.
*
* @param mixed $col1 color 1
* @param mixed $col2 color 2
*
* @return void
* @access private
*/
function _setColors ( $col1, $col2 )
{
$this->color1 = Image_Canvas_Color::color2RGB($col1);
$this->color2 = Image_Canvas_Color::color2RGB($col2);
}
}
?>
\ No newline at end of file
This is where the font files are located.
Font files can be found at:
MS CoreFonts
http://corefonts.sourceforge.net/
Divide By Zero (most are cartoonish)
http://fonts.tom7.com/
MING FDB Fonts
http://ming.sf.net/
\ No newline at end of file
Arial,arial.ttf
Arial Bold,arialbd.ttf
Arial Bold Italic,arialbi.ttf
Arial Italic,ariali.ttf
Courier New,cour.ttf
Courier New Bold,courbd.ttf
Courier New Bold Italic,courbi.ttf
Courier New Italic,couri.ttf
Garamond,gara.ttf
Garamond Bold,garabd.ttf
Garamond Italic,garait.ttf
Gothic,gothic.ttf
Gothic Bold,gothicb.ttf
Gothic Bold Italic,gothicbi.ttf
Gothic Italic,gothici.ttf
Sans Serif,micross.ttf
Reference Sans Serif,refsan.ttf
Times New Roman,times.ttf
Times New Roman Bold,timesbd.ttf
Times New Roman Bold Italic,timesbi.ttf
Times New Roman Italic,timesi.ttf
Verdana,verdana.ttf
Verdana Bold,verdanab.ttf
Verdana Bold Italic,verdanaz.ttf
Verdana Italic,verdanai.ttf
\ No newline at end of file
This diff is collapsed.
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Canvas
*
* Canvas class to handle JPEG format.
*
* PHP versions 4 and 5
*
* LICENSE: This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This library is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this library; if not, see
* <http://www.gnu.org/licenses/>
*
* @category Images
* @package Image_Canvas
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
* @copyright 2003-2009 The PHP Group
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version SVN: $Id$
* @link http://pear.php.net/package/Image_Canvas
*/
/**
* Include file Image/Canvas/GD.php
*/
require_once 'Image/Canvas/GD.php';
/**
* JPEG Canvas class.
*
* @category Images
* @package Image_Canvas
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
* @copyright 2003-2009 The PHP Group
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Canvas
*/
class Image_Canvas_GD_JPG extends Image_Canvas_GD
{
/**
* The JPEG quality
* @var int
* @access private
*/
var $_quality = 75;
/**
* Create the JPEG canvas
*
* Additional parameters other than those available for common {@link
* Image_Graph_Canvas_GD} class are:
*
* 'quality' The JPEG quality in as a percentage value from 0 (lowest
* quality, smallest file) to 100 (highest quality, biggest file)
*
* @param array $param Parameter array
*/
function Image_Canvas_GD_JPG($param)
{
parent::Image_Canvas_GD($param);
if (isset($param['quality'])) {
$this->_quality = max(0, min(100, $param['quality']));
}
$this->rectangle(
array(
'x0' => $this->_left,
'y0' => $this->_top,
'x1' => $this->_left + $this->_width - 1,
'y1' => $this->_top + $this->_height - 1,
'fill' => 'white',
'line' => 'transparent'
)
);
}
/**
* Output the result of the canvas
*
* @param array $param Parameter array
*
* @return void
* @abstract
*/
function show($param = false)
{
parent::show($param);
header('Content-type: image/jpg');
header('Content-Disposition: inline; filename = \"'. basename($_SERVER['PHP_SELF'], '.php') . '.jpg\"');
ImageJPEG($this->_canvas, '', $this->_quality);
ImageDestroy($this->_canvas);
}
/**
* Output the result of the canvas
*
* @param array $param Parameter array
*
* @return void
* @abstract
*/
function save($param = false)
{
parent::save($param);
ImageJPEG($this->_canvas, $param['filename'], $this->_quality);
ImageDestroy($this->_canvas);
}
}
?>
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Canvas
*
* Canvas class to handle PNG format.
*
* PHP versions 4 and 5
*
* LICENSE: This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This library is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this library; if not, see
* <http://www.gnu.org/licenses/>
*
* @category Images
* @package Image_Canvas
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
* @copyright 2003-2009 The PHP Group
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version SVN: $Id$
* @link http://pear.php.net/package/Image_Canvas
*/
/**
* Include file Image/Canvas/GD.php
*/
require_once 'Image/Canvas/GD.php';
/**
* PNG Canvas class.
*
* @category Images
* @package Image_Canvas
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
* @copyright 2003-2009 The PHP Group
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Canvas
*/
class Image_Canvas_GD_PNG extends Image_Canvas_GD
{
/**
* Create the PNG canvas
*
* @param array $param Parameter array
*/
function Image_Canvas_GD_PNG($param)
{
parent::Image_Canvas_GD($param);
if ((isset($param['transparent'])) && ($param['transparent'])
&& ($this->_gd2)
) {
if ($param['transparent'] === true) {
$transparent = '#123ABD';
} else {
$transparent = $param['transparent'];
}
$color = $this->_color($transparent);
$trans = ImageColorTransparent($this->_canvas, $color);
$this->rectangle(
array(
'x0' => $this->_left,
'y0' => $this->_top,
'x1' => $this->_left + $this->_width - 1,
'y1' => $this->_top + $this->_height - 1,
'fill' => 'opague',
'line' => 'transparent'
)
);
} else {
$this->rectangle(
array(
'x0' => $this->_left,
'y0' => $this->_top,
'x1' => $this->_left + $this->_width - 1,
'y1' => $this->_top + $this->_height - 1,
'fill' => 'white',
'line' => 'transparent'
)
);
}
}
/**
* Output the result of the canvas
*
* @param array $param Parameter array
*
* @return void
* @abstract
*/
function show($param = false)
{
parent::show($param);
header('Content-type: image/png');
header('Content-Disposition: inline; filename = \"'. basename($_SERVER['PHP_SELF'], '.php') . '.png\"');
ImagePNG($this->_canvas);
ImageDestroy($this->_canvas);
}
/**
* Output the result of the canvas
*
* @param array $param Parameter array
*
* @return void
* @abstract
*/
function save($param = false)
{
parent::save($param);
ImagePNG($this->_canvas, $param['filename']);
ImageDestroy($this->_canvas);
}
}
?>
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Canvas
*
* Class for handling output as a HTML imagemap
*
* PHP versions 4 and 5
*
* LICENSE: This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This library is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this library; if not, see
* <http://www.gnu.org/licenses/>
*
* @category Images
* @package Image_Canvas
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
* @copyright 2003-2009 The PHP Group
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version SVN: $Id$
* @link http://pear.php.net/package/Image_Canvas
*/
/**
* Class for handling output as a HTML imagemap
*
* @category Images
* @package Image_Canvas
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
* @copyright 2003-2009 The PHP Group
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Canvas
* @since version 0.2.0
*/
class Image_Canvas_ImageMap extends Image_Canvas
{
/**
* The image map (if any)
* @var array
* @access private
*/
var $_map = array();
/**
* Add a map tag
*
* @param string $shape The shape, either rect, circle or polygon
* @param string $coords The list of coordinates for the shape
* @param array $params Parameter array
*
* @return void
*/
function _addMapTag($shape, $coords, $params)
{
if (isset($params['url'])) {
$url = $params['url'];
$target = (isset($params['target']) ? $params['target'] : false);
$alt = (isset($params['alt']) ? $params['alt'] : false);
$tags = '';
if (isset($params['htmltags'])) {
foreach ($params['htmltags'] as $key => $value) {
$tags .= ' ';
if (strpos($value, '"') !== false) {
$tags .= $key . '=\'' . $value . '\'';
} else {
$tags .= $key . '="' . $value . '"';
}
}
}
$this->_map[] = '<area shape="' . $shape . '" coords="' . $coords . '" href="' . $url . '"' .
($target ? ' target="' . $target . '"' : '') .
($alt ? ' alt="' . $alt . '"' : '') .
(isset($params['id']) ? ' id="' . $params['id'] . '"' : '') .
$tags .
' />';
}
}
/**
* Draw a line
*
* Parameter array:
* 'x0': int X start point
* 'y0': int Y start point
* 'x1': int X end point
* 'y1': int Y end point
* 'color': mixed [optional] The line color
* 'mapsize': int [optional] The size of the image map (surrounding the line)
*
* @param array $params Parameter array
*
* @return void
*/
function line($params)
{
if (isset($params['url'])) {
$mapsize = (isset($params['mapsize']) ? $params['mapsize'] : 2);
$this->_addMapTag(
'poly',
$this->_getX($params['x0'] - $mapsize) . ',' .
$this->_getY($params['y0'] - $mapsize) . ',' .
$this->_getX($params['x1'] + $mapsize) . ',' .
$this->_getY($params['y1'] - $mapsize) . ',' .
//
$this->_getX($params['x1'] + $mapsize) . ',' .
$this->_getY($params['y1'] + $mapsize) . ',' .
$this->_getX($params['x0'] - $mapsize) . ',' .
$this->_getY($params['y0'] + $mapsize),
$params