From: <wis...@us...> - 2012-04-18 14:19:42
|
Revision: 9365 http://xoops.svn.sourceforge.net/xoops/?rev=9365&view=rev Author: wishcraft Date: 2012-04-18 14:19:27 +0000 (Wed, 18 Apr 2012) Log Message: ----------- turn.js - Book Flipping Module using - turn.min.js - Prebeta Added Paths: ----------- XoopsModules/turn/ XoopsModules/turn/trunk/ XoopsModules/turn/trunk/docs/ XoopsModules/turn/trunk/htdocs/ XoopsModules/turn/trunk/htdocs/Frameworks/ XoopsModules/turn/trunk/htdocs/Frameworks/tcpdf/ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Canvas.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Coordinate.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Exception.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/GDF.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/PS.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/TTF.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Image.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/BMP.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/GD.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/GD2.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/GIF.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/JPEG.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/PNG.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/TGA.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/MapperFactory.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/AddNoise.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/ApplyConvolution.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/ApplyFilter.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/ApplyMask.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/AsGrayscale.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/AsNegative.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/AutoCrop.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/CopyChannelsPalette.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/CopyChannelsTrueColor.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/CorrectGamma.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/Crop.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/Flip.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/GetMask.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/Merge.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/Mirror.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/Resize.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/ResizeCanvas.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/Rotate.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/RoundCorners.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Operation/Unsharp.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/OperationFactory.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/PaletteImage.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/TrueColorImage.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/WideImage.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/index.html XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/vendor/ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/vendor/de77/ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/vendor/de77/BMP.php XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/vendor/de77/TGA.php XoopsModules/turn/trunk/htdocs/modules/ XoopsModules/turn/trunk/htdocs/modules/turn/ XoopsModules/turn/trunk/htdocs/modules/turn/admin/ XoopsModules/turn/trunk/htdocs/modules/turn/admin/header.php XoopsModules/turn/trunk/htdocs/modules/turn/admin/index.html XoopsModules/turn/trunk/htdocs/modules/turn/admin/index.php XoopsModules/turn/trunk/htdocs/modules/turn/admin/menu.php XoopsModules/turn/trunk/htdocs/modules/turn/background.php XoopsModules/turn/trunk/htdocs/modules/turn/blocks/ XoopsModules/turn/trunk/htdocs/modules/turn/blocks/index.html XoopsModules/turn/trunk/htdocs/modules/turn/blocks/turn_block_book.php XoopsModules/turn/trunk/htdocs/modules/turn/class/ XoopsModules/turn/trunk/htdocs/modules/turn/class/books.php XoopsModules/turn/trunk/htdocs/modules/turn/class/index.html XoopsModules/turn/trunk/htdocs/modules/turn/class/page_links.php XoopsModules/turn/trunk/htdocs/modules/turn/class/pages.php XoopsModules/turn/trunk/htdocs/modules/turn/class/xlanguage_ext.php XoopsModules/turn/trunk/htdocs/modules/turn/css/ XoopsModules/turn/trunk/htdocs/modules/turn/css/css.php XoopsModules/turn/trunk/htdocs/modules/turn/css/index.html XoopsModules/turn/trunk/htdocs/modules/turn/header.php XoopsModules/turn/trunk/htdocs/modules/turn/images/ XoopsModules/turn/trunk/htdocs/modules/turn/images/icons/ XoopsModules/turn/trunk/htdocs/modules/turn/images/icons/index.html XoopsModules/turn/trunk/htdocs/modules/turn/images/index.html XoopsModules/turn/trunk/htdocs/modules/turn/images/turn_slogo.png XoopsModules/turn/trunk/htdocs/modules/turn/include/ XoopsModules/turn/trunk/htdocs/modules/turn/include/formobjects.turn.php XoopsModules/turn/trunk/htdocs/modules/turn/include/forms.turn.php XoopsModules/turn/trunk/htdocs/modules/turn/include/formselectbooks.php XoopsModules/turn/trunk/htdocs/modules/turn/include/formselectlanguage.php XoopsModules/turn/trunk/htdocs/modules/turn/include/functions.php XoopsModules/turn/trunk/htdocs/modules/turn/include/index.html XoopsModules/turn/trunk/htdocs/modules/turn/include/uploader.php XoopsModules/turn/trunk/htdocs/modules/turn/index.php XoopsModules/turn/trunk/htdocs/modules/turn/js/ XoopsModules/turn/trunk/htdocs/modules/turn/js/index.html XoopsModules/turn/trunk/htdocs/modules/turn/js/turn.min.js XoopsModules/turn/trunk/htdocs/modules/turn/language/ XoopsModules/turn/trunk/htdocs/modules/turn/language/english/ XoopsModules/turn/trunk/htdocs/modules/turn/language/english/admin.php XoopsModules/turn/trunk/htdocs/modules/turn/language/english/blocks.php XoopsModules/turn/trunk/htdocs/modules/turn/language/english/forms.php XoopsModules/turn/trunk/htdocs/modules/turn/language/english/index.html XoopsModules/turn/trunk/htdocs/modules/turn/language/english/main.php XoopsModules/turn/trunk/htdocs/modules/turn/language/english/modinfo.php XoopsModules/turn/trunk/htdocs/modules/turn/language/english/plugins.php XoopsModules/turn/trunk/htdocs/modules/turn/language/index.html XoopsModules/turn/trunk/htdocs/modules/turn/pages/ XoopsModules/turn/trunk/htdocs/modules/turn/pages/.htaccess XoopsModules/turn/trunk/htdocs/modules/turn/pages/background.php XoopsModules/turn/trunk/htdocs/modules/turn/pages/image.php XoopsModules/turn/trunk/htdocs/modules/turn/pages/index.html XoopsModules/turn/trunk/htdocs/modules/turn/pages/large/ XoopsModules/turn/trunk/htdocs/modules/turn/pages/large/.htaccess XoopsModules/turn/trunk/htdocs/modules/turn/pages/large/image.php XoopsModules/turn/trunk/htdocs/modules/turn/pages/large/index.html XoopsModules/turn/trunk/htdocs/modules/turn/pages/pdf/ XoopsModules/turn/trunk/htdocs/modules/turn/pages/pdf/.htaccess XoopsModules/turn/trunk/htdocs/modules/turn/pages/pdf/image.php XoopsModules/turn/trunk/htdocs/modules/turn/pages/pdf/index.html XoopsModules/turn/trunk/htdocs/modules/turn/pages/print/ XoopsModules/turn/trunk/htdocs/modules/turn/pages/print/.htaccess XoopsModules/turn/trunk/htdocs/modules/turn/pages/print/image.php XoopsModules/turn/trunk/htdocs/modules/turn/pages/print/index.html XoopsModules/turn/trunk/htdocs/modules/turn/pdf.php XoopsModules/turn/trunk/htdocs/modules/turn/sql/ XoopsModules/turn/trunk/htdocs/modules/turn/sql/index.html XoopsModules/turn/trunk/htdocs/modules/turn/sql/mysql.sql XoopsModules/turn/trunk/htdocs/modules/turn/templates/ XoopsModules/turn/trunk/htdocs/modules/turn/templates/blocks/ XoopsModules/turn/trunk/htdocs/modules/turn/templates/blocks/index.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/blocks/turn_block_book.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/index.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/turn_book.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/turn_books.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/turn_cpanel_books_edit.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/turn_cpanel_books_list.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/turn_cpanel_pages_edit.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/turn_cpanel_pages_list.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/turn_css.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/turn_index.html XoopsModules/turn/trunk/htdocs/modules/turn/templates/turn_pdf.html XoopsModules/turn/trunk/htdocs/modules/turn/thumbnail.php XoopsModules/turn/trunk/htdocs/modules/turn/xoops_version.php XoopsModules/turn/trunk/htdocs/uploads/ XoopsModules/turn/trunk/htdocs/uploads/turn/ Added: XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Canvas.php =================================================================== --- XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Canvas.php (rev 0) +++ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Canvas.php 2012-04-18 14:19:27 UTC (rev 9365) @@ -0,0 +1,167 @@ +<?php + /** + * @author Gasper Kozak + * @copyright 2007-2011 + + This file is part of WideImage. + + WideImage 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. + + WideImage 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 WideImage; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + * @package WideImage + **/ + + /** + * @package Exceptions + */ + class WideImage_NoFontException extends WideImage_Exception {} + + /** + * @package Exceptions + */ + class WideImage_InvalidFontFileException extends WideImage_Exception {} + + /** + * @package Exceptions + */ + class WideImage_InvalidCanvasMethodException extends WideImage_Exception {} + + /** + * @package WideImage + */ + class WideImage_Canvas + { + protected $handle = 0; + protected $image = null; + protected $font = null; + + /** + * Creates a canvas object that writes to the image passed as a parameter + * + * Shouldn't be used directly, use WideImage_Image::getCanvas() instead. + * + * @param WideImage_Image $img Image object + */ + function __construct($img) + { + $this->handle = $img->getHandle(); + $this->image = $img; + } + + /** + * Sets the active font. Can be an instance of + * WideImage_Font_TTF, WideImage_Font_PS, or WideImage_Font_GDF. + * + * + * + * + * @param object $font Font object to set for writeText() + */ + function setFont($font) + { + $this->font = $font; + } + + /** + * Creates and sets the current font + * + * The supported font types are: TTF/OTF, PS, and GDF. + * Font type is detected from the extension. If the $file parameter doesn't have an extension, TTF font is presumed. + * + * Note: not all parameters are supported by all fonts. + * + * @param string $file Font file name (string) + * @param int $size Font size (supported for TTF/OTF and PS fonts, ignored for GDF) + * @param int $color Text color + * @param int $bgcolor Background color (supported only for PS font, ignored for TTF and PS) + * @return mixed One of the WideImage_Font_* objects + */ + function useFont($file, $size = 12, $color = 0, $bgcolor = null) + { + $p = strrpos($file, '.'); + if ($p === false || $p < strlen($file) - 4) + $ext = 'ttf'; + else + $ext = strtolower(substr($file, $p + 1)); + + if ($ext == 'ttf' || $ext == 'otf') + $font = new WideImage_Font_TTF($file, $size, $color); + elseif ($ext == 'ps') + $font = new WideImage_Font_PS($file, $size, $color, $bgcolor); + elseif ($ext == 'gdf') + $font = new WideImage_Font_GDF($file, $color); + else + throw new WideImage_InvalidFontFileException("'$file' appears to be an invalid font file."); + + $this->setFont($font); + return $font; + } + + /** + * Write text on the image at specified position + * + * You must set a font with a call to WideImage_Canvas::setFont() prior to writing text to the image. + * + * Smart coordinates are supported for $x and $y arguments, but currently only for TTF/OTF fonts. + * + * Example: + * <code> + * $img = WideImage::load('pic.jpg'); + * $canvas = $img->getCanvas(); + * $canvas->useFont('Verdana.ttf', 16, $img->allocateColor(255, 0, 0)); + * $canvas->writeText('right', 'bottom', 'www.website.com'); + * </code> + * + * @param int $x Left + * @param int $y Top + * @param string $text Text to write + * @param int $angle The angle, defaults to 0 + */ + function writeText($x, $y, $text, $angle = 0) + { + if ($this->font === null) + throw new WideImage_NoFontException("Can't write text without a font."); + + $angle = - floatval($angle); + if ($angle < 0) + $angle = 360 + $angle; + $angle = $angle % 360; + + $this->font->writeText($this->image, $x, $y, $text, $angle); + } + + /** + * A magic method that allows you to call any PHP function that starts with "image". + * + * This is a shortcut to call custom functions on the image handle. + * + * Example: + * <code> + * $img = WideImage::load('pic.jpg'); + * $canvas = $img->getCanvas(); + * $canvas->filledRect(10, 10, 20, 30, $img->allocateColor(0, 0, 0)); + * $canvas->line(60, 80, 30, 100, $img->allocateColor(255, 0, 0)); + * </code> + */ + function __call($method, $params) + { + if (function_exists('image' . $method)) + { + array_unshift($params, $this->handle); + call_user_func_array('image' . $method, $params); + } + else + throw new WideImage_InvalidCanvasMethodException("Function doesn't exist: image{$method}."); + } + } Added: XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Coordinate.php =================================================================== --- XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Coordinate.php (rev 0) +++ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Coordinate.php 2012-04-18 14:19:27 UTC (rev 9365) @@ -0,0 +1,208 @@ +<?php + /** + * @author Gasper Kozak + * @copyright 2007-2011 + + This file is part of WideImage. + + WideImage 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. + + WideImage 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 WideImage; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + * @package Internals + **/ + + + /** + * @package Exceptions + */ + class WideImage_InvalidCoordinateException extends WideImage_Exception {} + + /** + * A utility class for smart coordinates + * + * @package Internals + **/ + class WideImage_Coordinate + { + static protected $coord_align = array("left", "center", "right", "top", "middle", "bottom"); + static protected $coord_numeric = array("[0-9]+", "[0-9]+\.[0-9]+", "[0-9]+%", "[0-9]+\.[0-9]+%"); + + /** + * Parses a numeric or string representation of a corrdinate into a structure + * + * @param string $coord Smart coordinate + * @return array Parsed smart coordinate + */ + static function parse($c) + { + $tokens = array(); + $operators = array('+', '-'); + + $flush_operand = false; + $flush_operator = false; + $current_operand = ''; + $current_operator = ''; + $coordinate = strval($c); + $expr_len = strlen($coordinate); + + for ($i = 0; $i < $expr_len; $i++) + { + $char = $coordinate[$i]; + + if (in_array($char, $operators)) + { + $flush_operand = true; + $flush_operator = true; + $current_operator = $char; + } + else + { + $current_operand .= $char; + if ($i == $expr_len - 1) + $flush_operand = true; + } + + if ($flush_operand) + { + if (trim($current_operand) != '') + $tokens[] = array('type' => 'operand', 'value' => trim($current_operand)); + + $current_operand = ''; + $flush_operand = false; + } + + if ($flush_operator) + { + $tokens[] = array('type' => 'operator', 'value' => $char); + $flush_operator = false; + } + } + return $tokens; + } + + /** + * Evaluates the $coord relatively to $dim + * + * @param string $coord A numeric value or percent string + * @param int $dim Dimension + * @param int $sec_dim Secondary dimension (for align) + * @return int Calculated value + */ + static function evaluate($coord, $dim, $sec_dim = null) + { + $comp_regex = implode('|', self::$coord_align) . '|' . implode('|', self::$coord_numeric); + if (preg_match("/^([+-])?({$comp_regex})$/", $coord, $matches)) + { + $sign = intval($matches[1] . "1"); + $val = $matches[2]; + if (in_array($val, self::$coord_align)) + { + if ($sec_dim === null) + { + switch ($val) + { + case 'left': + case 'top': + return 0; + break; + case 'center': + case 'middle': + return $sign * intval($dim / 2); + break; + case 'right': + case 'bottom': + return $sign * $dim; + break; + default: + return null; + } + } + else + { + switch ($val) + { + case 'left': + case 'top': + return 0; + break; + case 'center': + case 'middle': + return $sign * intval($dim / 2 - $sec_dim / 2); + break; + case 'right': + case 'bottom': + return $sign * ($dim - $sec_dim); + break; + default: + return null; + } + } + } + elseif (substr($val, -1) === '%') + return intval(round($sign * $dim * floatval(str_replace('%', '', $val)) / 100)); + else + return $sign * intval(round($val)); + } + } + + /** + * Calculates and fixes a smart coordinate into a numeric value + * + * @param mixed $value Smart coordinate, relative to $dim + * @param int $dim Coordinate to which $value is relative + * @param int $sec_dim Secondary dimension (for align) + * @return int Calculated value + */ + static function fix($value, $dim, $sec_dim = null) + { + $coord_tokens = self::parse($value); + + if (count($coord_tokens) == 0 || $coord_tokens[count($coord_tokens) - 1]['type'] != 'operand') + throw new WideImage_InvalidCoordinateException("Couldn't parse coordinate '$value' properly."); + + $value = 0; + $operation = 1; + foreach ($coord_tokens as $token) + { + if ($token['type'] == 'operand') + { + $operand_value = self::evaluate($token['value'], $dim, $sec_dim); + if ($operation == 1) + $value = $value + $operand_value; + elseif ($operation == -1) + $value = $value - $operand_value; + else + throw new WideImage_InvalidCoordinateException("Invalid coordinate syntax."); + + $operation = 0; + } + elseif ($token['type'] == 'operator') + { + if ($token['value'] == '-') + { + if ($operation == 0) + $operation = -1; + else + $operation = $operation * -1; + } + elseif ($token['value'] == '+') + { + if ($operation == 0) + $operation = '1'; + } + } + } + return $value; + } + } Added: XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Exception.php =================================================================== --- XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Exception.php (rev 0) +++ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Exception.php 2012-04-18 14:19:27 UTC (rev 9365) @@ -0,0 +1,31 @@ +<?php + /** + * @author Gasper Kozak + * @copyright 2007-2011 + + This file is part of WideImage. + + WideImage 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. + + WideImage 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 WideImage; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + * @package WideImage + **/ + + /** + * Base Exception class + * + * @package Exceptions + **/ + class WideImage_Exception extends RuntimeException {} + \ No newline at end of file Added: XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/GDF.php =================================================================== --- XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/GDF.php (rev 0) +++ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/GDF.php 2012-04-18 14:19:27 UTC (rev 9365) @@ -0,0 +1,48 @@ +<?php + /** + * @author Gasper Kozak + * @copyright 2007-2011 + + This file is part of WideImage. + + WideImage 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. + + WideImage 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 WideImage; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + * @package WideImage + **/ + + /** + * GDF font support class + * + * @package WideImage + */ + class WideImage_Font_GDF + { + protected $font; + protected $color; + + function __construct($face, $color) + { + if (is_int($face) && $face >= 1 && $face <= 5) + $this->font = $face; + else + $this->font = imageloadfont($face); + $this->color = $color; + } + + function writeText($image, $x, $y, $text) + { + imagestring($image->getHandle(), $this->font, $x, $y, $text, $this->color); + } + } Added: XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/PS.php =================================================================== --- XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/PS.php (rev 0) +++ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/PS.php 2012-04-18 14:19:27 UTC (rev 9365) @@ -0,0 +1,60 @@ +<?php + /** + * @author Gasper Kozak + * @copyright 2007-2011 + + This file is part of WideImage. + + WideImage 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. + + WideImage 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 WideImage; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + * @package WideImage + **/ + + /** + * PS font support class + * + * @package WideImage + */ + class WideImage_Font_PS + { + public $size; + public $color; + public $handle; + + function __construct($file, $size, $color, $bgcolor = null) + { + $this->handle = imagepsloadfont($file); + $this->size = $size; + $this->color = $color; + if ($bgcolor === null) + $this->bgcolor = $color; + else + $this->color = $color; + } + + function writeText($image, $x, $y, $text, $angle = 0) + { + if ($image->isTrueColor()) + $image->alphaBlending(true); + + imagepstext($image->getHandle(), $text, $this->handle, $this->size, $this->color, $this->bgcolor, $x, $y, 0, 0, $angle, 4); + } + + function __destruct() + { + imagepsfreefont($this->handle); + $this->handle = null; + } + } Added: XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/TTF.php =================================================================== --- XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/TTF.php (rev 0) +++ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Font/TTF.php 2012-04-18 14:19:27 UTC (rev 9365) @@ -0,0 +1,75 @@ +<?php + /** + * @author Gasper Kozak + * @copyright 2007-2011 + + This file is part of WideImage. + + WideImage 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. + + WideImage 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 WideImage; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + * @package WideImage + **/ + + /** + * TTF font support class + * + * @package WideImage + */ + class WideImage_Font_TTF + { + public $face; + public $size; + public $color; + + function __construct($face, $size, $color) + { + $this->face = $face; + $this->size = $size; + $this->color = $color; + } + + /** + * Writes text onto an image + * + * @param WideImage_Image $image + * @param mixed $x smart coordinate + * @param mixed $y smart coordinate + * @param string $text + * @param int $angle Angle in degrees clockwise + */ + function writeText($image, $x, $y, $text, $angle = 0) + { + if ($image->isTrueColor()) + $image->alphaBlending(true); + + $box = imageftbbox($this->size, $angle, $this->face, $text); + $obox = array( + 'left' => min($box[0], $box[2], $box[4], $box[6]), + 'top' => min($box[1], $box[3], $box[5], $box[7]), + 'right' => max($box[0], $box[2], $box[4], $box[6]) - 1, + 'bottom' => max($box[1], $box[3], $box[5], $box[7]) - 1 + ); + $obox['width'] = abs($obox['left']) + abs($obox['right']); + $obox['height'] = abs($obox['top']) + abs($obox['bottom']); + + $x = WideImage_Coordinate::fix($x, $image->getWidth(), $obox['width']); + $y = WideImage_Coordinate::fix($y, $image->getHeight(), $obox['height']); + + $fixed_x = $x - $obox['left']; + $fixed_y = $y - $obox['top']; + + imagettftext($image->getHandle(), $this->size, $angle, $fixed_x, $fixed_y, $this->color, $this->face, $text); + } + } Added: XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Image.php =================================================================== --- XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Image.php (rev 0) +++ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Image.php 2012-04-18 14:19:27 UTC (rev 9365) @@ -0,0 +1,964 @@ +<?php + /** + * @author Gasper Kozak + * @copyright 2007-2011 + + This file is part of WideImage. + + WideImage 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. + + WideImage 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 WideImage; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + * @package WideImage + **/ + + /** + * Thrown when an invalid dimension is passed for some operations + * + * @package Exceptions + */ + class WideImage_InvalidImageDimensionException extends WideImage_Exception {} + + /** + * Thrown when an image can't be saved (returns false by the mapper) + * + * @package Exceptions + */ + class WideImage_UnknownErrorWhileMappingException extends WideImage_Exception {} + + /** + * Base class for images + * + * @package WideImage + */ + abstract class WideImage_Image + { + /** + * Holds the image resource + * @var resource + */ + protected $handle = null; + + /** + * Flag that determines if WideImage should call imagedestroy() upon object destruction + * @var bool + */ + protected $handleReleased = false; + + /** + * Canvas object + * @var WideImage_Canvas + */ + protected $canvas = null; + + /** + * @var string + */ + protected $sdata = null; + + /** + * The base class constructor + * + * @param resource $handle Image handle (GD2 resource) + */ + function __construct($handle) + { + WideImage::assertValidImageHandle($handle); + $this->handle = $handle; + } + + /** + * Cleanup + * + * Destroys the handle via WideImage_Image::destroy() when called by the GC. + */ + function __destruct() + { + $this->destroy(); + } + + /** + * This method destroy the image handle, and releases the image resource. + * + * After this is called, the object doesn't hold a valid image any more. + * No operation should be called after that. + */ + function destroy() + { + if ($this->isValid() && !$this->handleReleased) + imagedestroy($this->handle); + + $this->handle = null; + } + + /** + * Returns the GD image resource + * + * @return resource GD image resource + */ + function getHandle() + { + return $this->handle; + } + + /** + * @return bool True, if the image object holds a valid GD image, false otherwise + */ + function isValid() + { + return WideImage::isValidImageHandle($this->handle); + } + + /** + * Releases the handle + */ + function releaseHandle() + { + $this->handleReleased = true; + } + + /** + * Saves an image to a file + * + * The file type is recognized from the $uri. If you save to a GIF8, truecolor images + * are automatically converted to palette. + * + * This method supports additional parameters: quality (for jpeg images) and + * compression quality and filters (for png images). See http://www.php.net/imagejpeg and + * http://www.php.net/imagepng for details. + * + * Examples: + * <code> + * // save to a GIF + * $image->saveToFile('image.gif'); + * + * // save to a PNG with compression=7 and no filters + * $image->saveToFile('image.png', 7, PNG_NO_FILTER); + * + * // save to a JPEG with quality=80 + * $image->saveToFile('image.jpg', 80); + * + * // save to a JPEG with default quality=100 + * $image->saveToFile('image.jpg'); + * </code> + * + * @param string $uri File location + */ + function saveToFile($uri) + { + $mapper = WideImage_MapperFactory::selectMapper($uri, null); + $args = func_get_args(); + array_unshift($args, $this->getHandle()); + $res = call_user_func_array(array($mapper, 'save'), $args); + if (!$res) + throw new WideImage_UnknownErrorWhileMappingException(get_class($mapper) . " returned an invalid result while saving to $uri"); + } + + /** + * Returns binary string with image data in format specified by $format + * + * Additional parameters may be passed to the function. See WideImage_Image::saveToFile() for more details. + * + * @param string $format The format of the image + * @return string The binary image data in specified format + */ + function asString($format) + { + ob_start(); + $args = func_get_args(); + $args[0] = null; + array_unshift($args, $this->getHandle()); + + $mapper = WideImage_MapperFactory::selectMapper(null, $format); + $res = call_user_func_array(array($mapper, 'save'), $args); + if (!$res) + throw new WideImage_UnknownErrorWhileMappingException(get_class($mapper) . " returned an invalid result while writing the image data"); + + return ob_get_clean(); + } + + /** + * Output a header to browser. + * + * @param $name Name of the header + * @param $data Data + */ + protected function writeHeader($name, $data) + { + header($name . ": " . $data); + } + + /** + * Outputs the image to browser + * + * Sets headers Content-length and Content-type, and echoes the image in the specified format. + * All other headers (such as Content-disposition) must be added manually. + * + * Example: + * <code> + * WideImage::load('image1.png')->resize(100, 100)->output('gif'); + * </code> + * + * @param string $format Image format + */ + function output($format) + { + $args = func_get_args(); + $data = call_user_func_array(array($this, 'asString'), $args); + + $this->writeHeader('Content-length', strlen($data)); + $this->writeHeader('Content-type', WideImage_MapperFactory::mimeType($format)); + echo $data; + } + + /** + * @return int Image width + */ + function getWidth() + { + return imagesx($this->handle); + } + + /** + * @return int Image height + */ + function getHeight() + { + return imagesy($this->handle); + } + + /** + * Allocate a color by RGB values. + * + * @param mixed $R Red-component value or an RGB array (with red, green, blue keys) + * @param int $G If $R is int, this is the green component + * @param int $B If $R is int, this is the blue component + * @return int Image color index + */ + function allocateColor($R, $G = null, $B = null) + { + if (is_array($R)) + return imageColorAllocate($this->handle, $R['red'], $R['green'], $R['blue']); + else + return imageColorAllocate($this->handle, $R, $G, $B); + } + + /** + * @return bool True if the image is transparent, false otherwise + */ + function isTransparent() + { + return $this->getTransparentColor() >= 0; + } + + /** + * @return int Transparent color index + */ + function getTransparentColor() + { + return imagecolortransparent($this->handle); + } + + /** + * Sets the current transparent color index. Only makes sense for palette images (8-bit). + * + * @param int $color Transparent color index + */ + function setTransparentColor($color) + { + return imagecolortransparent($this->handle, $color); + } + + /** + * Returns a RGB array of the transparent color or null if none. + * + * @return mixed Transparent color RGBA array + */ + function getTransparentColorRGB() + { + $total = imagecolorstotal($this->handle); + $tc = $this->getTransparentColor(); + + if ($tc >= $total && $total > 0) + return null; + else + return $this->getColorRGB($tc); + } + + /** + * Returns a RGBA array for pixel at $x, $y + * + * @param int $x + * @param int $y + * @return array RGB array + */ + function getRGBAt($x, $y) + { + return $this->getColorRGB($this->getColorAt($x, $y)); + } + + /** + * Writes a pixel at the designated coordinates + * + * Takes an associative array of colours and uses getExactColor() to + * retrieve the exact index color to write to the image with. + * + * @param int $x + * @param int $y + * @param array $color + */ + function setRGBAt($x, $y, $color) + { + $this->setColorAt($x, $y, $this->getExactColor($color)); + } + + /** + * Returns a color's RGB + * + * @param int $colorIndex Color index + * @return mixed RGBA array for a color with index $colorIndex + */ + function getColorRGB($colorIndex) + { + return imageColorsForIndex($this->handle, $colorIndex); + } + + /** + * Returns an index of the color at $x, $y + * + * @param int $x + * @param int $y + * @return int Color index for a pixel at $x, $y + */ + function getColorAt($x, $y) + { + return imagecolorat($this->handle, $x, $y); + } + + /** + * Set the color index $color to a pixel at $x, $y + * + * @param int $x + * @param int $y + * @param int $color Color index + */ + function setColorAt($x, $y, $color) + { + return imagesetpixel($this->handle, $x, $y, $color); + } + + /** + * Returns closest color index that matches the given RGB value. Uses + * PHP's imagecolorclosest() + * + * @param mixed $R Red or RGBA array + * @param int $G Green component (or null if $R is an RGB array) + * @param int $B Blue component (or null if $R is an RGB array) + * @return int Color index + */ + function getClosestColor($R, $G = null, $B = null) + { + if (is_array($R)) + return imagecolorclosest($this->handle, $R['red'], $R['green'], $R['blue']); + else + return imagecolorclosest($this->handle, $R, $G, $B); + } + + /** + * Returns the color index that exactly matches the given RGB value. Uses + * PHP's imagecolorexact() + * + * @param mixed $R Red or RGBA array + * @param int $G Green component (or null if $R is an RGB array) + * @param int $B Blue component (or null if $R is an RGB array) + * @return int Color index + */ + function getExactColor($R, $G = null, $B = null) + { + if (is_array($R)) + return imagecolorexact($this->handle, $R['red'], $R['green'], $R['blue']); + else + return imagecolorexact($this->handle, $R, $G, $B); + } + + /** + * Copies transparency information from $sourceImage. Optionally fills + * the image with the transparent color at (0, 0). + * + * @param object $sourceImage + * @param bool $fill True if you want to fill the image with transparent color + */ + function copyTransparencyFrom($sourceImage, $fill = true) + { + if ($sourceImage->isTransparent()) + { + $rgba = $sourceImage->getTransparentColorRGB(); + if ($rgba === null) + return; + + if ($this->isTrueColor()) + { + $rgba['alpha'] = 127; + $color = $this->allocateColorAlpha($rgba); + } + else + $color = $this->allocateColor($rgba); + + $this->setTransparentColor($color); + if ($fill) + $this->fill(0, 0, $color); + } + } + + /** + * Fill the image at ($x, $y) with color index $color + * + * @param int $x + * @param int $y + * @param int $color + */ + function fill($x, $y, $color) + { + return imagefill($this->handle, $x, $y, $color); + } + + /** + * Used internally to create Operation objects + * + * @param string $name + * @return object + */ + protected function getOperation($name) + { + return WideImage_OperationFactory::get($name); + } + + /** + * Returns the image's mask + * + * Mask is a greyscale image where the shade defines the alpha channel (black = transparent, white = opaque). + * + * For opaque images (JPEG), the result will be white. For images with single-color transparency (GIF, 8-bit PNG), + * the areas with the transparent color will be black. For images with alpha channel transparenct, + * the result will be alpha channel. + * + * @return WideImage_Image An image mask + **/ + function getMask() + { + return $this->getOperation('GetMask')->execute($this); + } + + /** + * Resize the image to given dimensions. + * + * $width and $height are both smart coordinates. This means that you can pass any of these values in: + * - positive or negative integer (100, -20, ...) + * - positive or negative percent string (30%, -15%, ...) + * - complex coordinate (50% - 20, 15 + 30%, ...) + * + * If $width is null, it's calculated proportionally from $height, and vice versa. + * + * Example (resize to half-size): + * <code> + * $smaller = $image->resize('50%'); + * + * $smaller = $image->resize('100', '100', 'inside', 'down'); + * is the same as + * $smaller = $image->resizeDown(100, 100, 'inside'); + * </code> + * + * @param mixed $width The new width (smart coordinate), or null. + * @param mixed $height The new height (smart coordinate), or null. + * @param string $fit 'inside', 'outside', 'fill' + * @param string $scale 'down', 'up', 'any' + * @return WideImage_Image The resized image + */ + function resize($width = null, $height = null, $fit = 'inside', $scale = 'any') + { + return $this->getOperation('Resize')->execute($this, $width, $height, $fit, $scale); + } + + /** + * Same as WideImage_Image::resize(), but the image is only applied if it is larger then the given dimensions. + * Otherwise, the resulting image retains the source's dimensions. + * + * @param int $width New width, smart coordinate + * @param int $height New height, smart coordinate + * @param string $fit 'inside', 'outside', 'fill' + * @return WideImage_Image resized image + */ + function resizeDown($width = null, $height = null, $fit = 'inside') + { + return $this->resize($width, $height, $fit, 'down'); + } + + /** + * Same as WideImage_Image::resize(), but the image is only applied if it is smaller then the given dimensions. + * Otherwise, the resulting image retains the source's dimensions. + * + * @param int $width New width, smart coordinate + * @param int $height New height, smart coordinate + * @param string $fit 'inside', 'outside', 'fill' + * @return WideImage_Image resized image + */ + function resizeUp($width = null, $height = null, $fit = 'inside') + { + return $this->resize($width, $height, $fit, 'up'); + } + + /** + * Rotate the image for angle $angle clockwise. + * + * Preserves transparency. Has issues when saving to a BMP. + * + * @param int $angle Angle in degrees, clock-wise + * @param int $bgColor color of the new background + * @param bool $ignoreTransparent + * @return WideImage_Image The rotated image + */ + function rotate($angle, $bgColor = null, $ignoreTransparent = true) + { + return $this->getOperation('Rotate')->execute($this, $angle, $bgColor, $ignoreTransparent); + } + + /** + * This method lays the overlay (watermark) on the image. + * + * Hint: if the overlay is a truecolor image with alpha channel, you should leave $pct at 100. + * + * This operation supports alignment notation in coordinates: + * <code> + * $watermark = WideImage::load('logo.gif'); + * $base = WideImage::load('picture.jpg'); + * $result = $base->merge($watermark, "right - 10", "bottom - 10", 50); + * // applies a logo aligned to bottom-right corner with a 10 pixel margin + * </code> + * + * @param WideImage_Image $overlay The overlay image + * @param mixed $left Left position of the overlay, smart coordinate + * @param mixed $top Top position of the overlay, smart coordinate + * @param int $pct The opacity of the overlay + * @return WideImage_Image The merged image + */ + function merge($overlay, $left = 0, $top = 0, $pct = 100) + { + return $this->getOperation('Merge')->execute($this, $overlay, $left, $top, $pct); + } + + /** + * Resizes the canvas of the image, but doesn't scale the content of the image + * + * This operation creates an empty canvas with dimensions $width x $height, filled with + * background color $bg_color and draws the original image onto it at position [$pos_x, $pos_y]. + * + * Arguments $width, $height, $pos_x and $pos_y are all smart coordinates. $width and $height are + * relative to the current image size, $pos_x and $pos_y are relative to the newly calculated + * canvas size. This can be confusing, but it makes sense. See the example below. + * + * The example below loads a 100x150 image and then resizes its canvas to 200% x 100%+20 + * (which evaluates to 200x170). The image is placed at position [10, center+20], which evaluates to [10, 30]. + * <code> + * $image = WideImage::load('someimage.jpg'); // 100x150 + * $white = $image->allocateColor(255, 255, 255); + * $image->resizeCanvas('200%', '100% + 20', 10, 'center+20', $white); + * </code> + * + * The parameter $merge defines whether the original image should be merged onto the new canvas. + * This means it blends transparent color and alpha colors into the background color. If set to false, + * the original image is just copied over, preserving the transparency/alpha information. + * + * You can set the $scale parameter to limit when to resize the canvas. For example, if you want + * to resize the canvas only if the image is smaller than the new size, but leave the image intact + * if it's larger, set it to 'up'. Likewise, if you want to shrink the canvas, but don't want to + * change images that are already smaller, set it to 'down'. + * + * @param mixed $width Width of the new canvas (smart coordinate, relative to current image width) + * @param mixed $height Height of the new canvas (smart coordinate, relative to current image height) + * @param mixed $pos_x x-position of the image (smart coordinate, relative to the new width) + * @param mixed $pos_y y-position of the image (smart coordinate, relative to the new height) + * @param int $bg_color Background color (created with allocateColor or allocateColorAlpha), defaults to null (tries to use a transparent color) + * @param string $scale Possible values: 'up' (enlarge only), 'down' (downsize only), 'any' (resize precisely to $width x $height). Defaults to 'any'. + * @param bool $merge Merge the original image (flatten alpha channel and transparency) or copy it over (preserve). Defaults to false. + * @return WideImage_Image The resulting image with resized canvas + */ + function resizeCanvas($width, $height, $pos_x, $pos_y, $bg_color = null, $scale = 'any', $merge = false) + { + return $this->getOperation('ResizeCanvas')->execute($this, $width, $height, $pos_x, $pos_y, $bg_color, $scale, $merge); + } + + /** + * Returns an image with round corners + * + * You can either set the corners' color or set them transparent. + * + * Note on $smoothness: 1 means jagged edges, 2 is much better, more than 4 doesn't noticeably improve the quality. + * Rendering becomes increasingly slower if you increase smoothness. + * + * Example: + * <code> + * $nice = $ugly->roundCorners(20, $ugly->allocateColor(255, 0, 0), 2); + * </code> + * + * Use $corners parameter to specify which corners to draw rounded. Possible values are + * WideImage::SIDE_TOP_LEFT, WideImage::SIDE_TOP, + * WideImage::SIDE_TOP_RIGHT, WideImage::SIDE_RIGHT, + * WideImage::SIDE_BOTTOM_RIGHT, WideImage::SIDE_BOTTOM, + * WideImage::SIDE_BOTTOM_LEFT, WideImage::SIDE_LEFT, and WideImage::SIDE_ALL. + * You can specify any combination of corners with a + operation, see example below. + * + * Example: + * <code> + * $white = $image->allocateColor(255, 255, 255); + * $diagonal_corners = $image->roundCorners(15, $white, 2, WideImage::SIDE_TOP_LEFT + WideImage::SIDE_BOTTOM_RIGHT); + * $right_corners = $image->roundCorners(15, $white, 2, WideImage::SIDE_RIGHT); + * </code> + * + * @param int $radius Radius of the corners + * @param int $color The color of corners. If null, corners are rendered transparent (slower than using a solid color). + * @param int $smoothness Specify the level of smoothness. Suggested values from 1 to 4. + * @param int $corners Specify which corners to draw (defaults to WideImage::SIDE_ALL = all corners) + * @return WideImage_Image The resulting image with round corners + */ + function roundCorners($radius, $color = null, $smoothness = 2, $corners = 255) + { + return $this->getOperation('RoundCorners')->execute($this, $radius, $color, $smoothness, $corners); + } + + /** + * Returns an image with applied mask + * + * A mask is a grayscale image, where the shade determines the alpha channel. Black is fully transparent + * and white is fully opaque. + * + * @param WideImage_Image $mask The mask image, greyscale + * @param mixed $left Left coordinate, smart coordinate + * @param mixed $top Top coordinate, smart coordinate + * @return WideImage_Image The resulting image + **/ + function applyMask($mask, $left = 0, $top = 0) + { + return $this->getOperation('ApplyMask')->execute($this, $mask, $left, $top); + } + + /** + * Applies a filter + * + * @param int $filter One of the IMG_FILTER_* constants + * @param int $arg1 + * @param int $arg2 + * @param int $arg3 + * @param int $arg4 + * @return WideImage_Image + */ + function applyFilter($filter, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null) + { + return $this->getOperation('ApplyFilter')->execute($this, $filter, $arg1, $arg2, $arg3, $arg4); + } + + /** + * Applies convolution matrix with imageconvolution() + * + * @param array $matrix + * @param float $div + * @param float $offset + * @return WideImage_Image + */ + function applyConvolution($matrix, $div, $offset) + { + return $this->getOperation('ApplyConvolution')->execute($this, $matrix, $div, $offset); + } + + /** + * Returns a cropped rectangular portion of the image + * + * If the rectangle specifies area that is out of bounds, it's limited to the current image bounds. + * + * Examples: + * <code> + * $cropped = $img->crop(10, 10, 150, 200); // crops a 150x200 rect at (10, 10) + * $cropped = $img->crop(-100, -50, 100, 50); // crops a 100x50 rect at the right-bottom of the image + * $cropped = $img->crop('25%', '25%', '50%', '50%'); // crops a 50%x50% rect from the center of the image + * </code> + * + * This operation supports alignment notation in left/top coordinates. + * Example: + * <code> + * $cropped = $img->crop("right", "bottom", 100, 200); // crops a 100x200 rect from right bottom + * $cropped = $img->crop("center", "middle", 50, 30); // crops a 50x30 from the center of the image + * </code> + * + * @param mixed $left Left-coordinate of the crop rect, smart coordinate + * @param mixed $top Top-coordinate of the crop rect, smart coordinate + * @param mixed $width Width of the crop rect, smart coordinate + * @param mixed $height Height of the crop rect, smart coordinate + * @return WideImage_Image The cropped image + **/ + function crop($left = 0, $top = 0, $width = '100%', $height = '100%') + { + return $this->getOperation('Crop')->execute($this, $left, $top, $width, $height); + } + + /** + * Performs an auto-crop on the image + * + * The image is auto-cropped from each of four sides. All sides are + * scanned for pixels that differ from $base_color for more than + * $rgb_threshold in absolute RGB difference. If more than $pixel_cutoff + * differentiating pixels are found, that line is considered to be the crop line for the side. + * If the line isn't different enough, the algorithm procedes to the next line + * towards the other edge of the image. + * + * When the crop rectangle is found, it's enlarged by the $margin value on each of the four sides. + * + * @param int $margin Margin for the crop rectangle, can be negative. + * @param int $rgb_threshold RGB difference which still counts as "same color". + * @param int $pixel_cutoff How many pixels need to be different to mark a cut line. + * @param int $base_color The base color index. If none specified (or null given), left-top pixel is used. + * @return WideImage_Image The cropped image + */ + function autoCrop($margin = 0, $rgb_threshold = 0, $pixel_cutoff = 1, $base_color = null) + { + return $this->getOperation('AutoCrop')->execute($this, $margin, $rgb_threshold, $pixel_cutoff, $base_color); + } + + /** + * Returns a negative of the image + * + * This operation differs from calling WideImage_Image::applyFilter(IMG_FILTER_NEGATIVE), because it's 8-bit and transparency safe. + * This means it will return an 8-bit image, if the source image is 8-bit. If that 8-bit image has a palette transparency, + * the resulting image will keep transparency. + * + * @return WideImage_Image negative of the image + */ + function asNegative() + { + return $this->getOperation('AsNegative')->execute($this); + } + + /** + * Returns a grayscale copy of the image + * + * @return WideImage_Image grayscale copy + **/ + function asGrayscale() + { + return $this->getOperation('AsGrayscale')->execute($this); + } + + /** + * Returns a mirrored copy of the image + * + * @return WideImage_Image Mirrored copy + **/ + function mirror() + { + return $this->getOperation('Mirror')->execute($this); + } + + /** + * Applies the unsharp filter + * + * @param float $amount + * @param float $radius + * @param float $threshold + * @return WideImage_Image Unsharpened copy of the image + **/ + function unsharp($amount, $radius, $threshold) + { + return $this->getOperation('Unsharp')->execute($this, $amount, $radius, $threshold); + } + + /** + * Returns a flipped (mirrored over horizontal line) copy of the image + * + * @return WideImage_Image Flipped copy + **/ + function flip() + { + return $this->getOperation('Flip')->execute($this); + } + + /** + * Corrects gamma on the image + * + * @param float $inputGamma + * @param float $outputGamma + * @return WideImage_Image Image with corrected gamma + **/ + function correctGamma($inputGamma, $outputGamma) + { + return $this->getOperation('CorrectGamma')->execute($this, $inputGamma, $outputGamma); + } + + /** + * Adds noise to the image + * + * @author Tomasz Kapusta + * + * @param int $amount Number of noise pixels to add + * @param string $type Type of noise 'salt&pepper', 'color' or 'mono' + * @return WideImage_Image Image with noise added + **/ + function addNoise($amount, $type) + { + return $this->getOperation('AddNoise')->execute($this, $amount, $type); + } + + /** + * Used internally to execute operations + * + * @param string $name + * @param array $args + * @return WideImage_Image + */ + function __call($name, $args) + { + $op = $this->getOperation($name); + array_unshift($args, $this); + return call_user_func_array(array($op, 'execute'), $args); + } + + /** + * Returns an image in GIF or PNG format + * + * @return string + */ + function __toString() + { + if ($this->isTransparent()) + return $this->asString('gif'); + else + return $this->asString('png'); + } + + /** + * Returns a copy of the image object + * + * @return WideImage_Image The copy + **/ + function copy() + { + $dest = $this->doCreate($this->getWidth(), $this->getHeight()); + $dest->copyTransparencyFrom($this, true); + $this->copyTo($dest, 0, 0); + return $dest; + } + + /** + * Copies this image onto another image + * + * @param WideImage_Image $dest + * @param int $left + * @param int $top + **/ + function copyTo($dest, $left = 0, $top = 0) + { + if (!imagecopy($dest->getHandle(), $this->handle, $left, $top, 0, 0, $this->getWidth(), $this->getHeight())) + throw new WideImage_GDFunctionResultException("imagecopy() returned false"); + } + + /** + * Returns the canvas object + * + * The Canvas object can be used to draw text and shapes on the image + * + * Examples: + * <code> + * $img = WideImage::load('pic.jpg); + * $canvas = $img->getCanvas(); + * $canvas->useFont('arial.ttf', 15, $img->allocateColor(200, 220, 255)); + * $canvas->writeText(10, 50, "Hello world!"); + * + * $canvas->filledRectangle(10, 10, 80, 40, $img->allocateColor(255, 127, 255)); + * $canvas->line(60, 80, 30, 100, $img->allocateColor(255, 0, 0)); + * $img->saveToFile('new.png'); + * </code> + * + * @return WideImage_Canvas The Canvas object + **/ + function getCanvas() + { + if ($this->canvas == null) + $this->canvas = new WideImage_Canvas($this); + return $this->canvas; + } + + /** + * Returns true if the image is true-color, false otherwise + * + * @return bool + **/ + abstract function isTrueColor(); + + /** + * Returns a true-color copy of the image + * + * @return WideImage_TrueColorImage + **/ + abstract function asTrueColor(); + + /** + * Returns a palette copy (8bit) of the image + * + * @param int $nColors Number of colors in the resulting image, more than 0, less or equal to 255 + * @param bool $dither Use dithering or not + * @param bool $matchPalette Set to true to use imagecolormatch() to match the resulting palette more closely to the original image + * @return WideImage_Image + **/ + abstract function asPalette($nColors = 255, $dither = null, $matchPalette = true); + + /** + * Retrieve an image with selected channels + * + * Examples: + * <code> + * $channels = $img->getChannels('red', 'blue'); + * $channels = $img->getChannels('alpha', 'green'); + * $channels = $img->getChannels(array('green', 'blue')); + * </code> + * + * @return WideImage_Image + **/ + abstract function getChannels(); + + /** + * Returns an image without an alpha channel + * + * @return WideImage_Image + **/ + abstract function copyNoAlpha(); + + /** + * Returns an array of serializable protected variables. Called automatically upon serialize(). + * + * @return array + */ + function __sleep() + { + $this->sdata = $this->asString('png'); + return array('sdata', 'handleReleased'); + } + + /** + * Restores an image from serialization. Called automatically upon unserialize(). + */ + function __wakeup() + { + $temp_image = WideImage::loadFromString($this->sdata); + $temp_image->releaseHandle(); + $this->handle = $temp_image->handle; + $temp_image = null; + $this->sdata = null; + } + } Added: XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/BMP.php =================================================================== --- XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/BMP.php (rev 0) +++ XoopsModules/turn/trunk/htdocs/Frameworks/wideimage/Mapper/BMP.php 2012-04-18 14:19:27 UTC (rev 9365) @@ -0,0 +1,... [truncated message content] |