From 18390e567e237bbba612c7058e3edf6e31ffcbd5 Mon Sep 17 00:00:00 2001 From: Steve Kenow Date: Sat, 10 Jun 2023 11:40:52 -0500 Subject: [PATCH 1/9] Call to an empty method was creating an error in the image editor --- htdocs/plugins/preloads/bootstrap.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/htdocs/plugins/preloads/bootstrap.php b/htdocs/plugins/preloads/bootstrap.php index 5b5878b07519..ed64ce6868ea 100644 --- a/htdocs/plugins/preloads/bootstrap.php +++ b/htdocs/plugins/preloads/bootstrap.php @@ -1,16 +1,17 @@ - * @version $Id:$ + * @copyright The ImpressCMS Project http://www.impresscms.org/ + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL) + * @package libraries + * @since 1.3 + * @author marcan + * @version $Id:$ */ - class icms_BootstrapEventHandler { + static public function setup() { icms_Event::attach('icms', 'loadService', array(__CLASS__, 'loadService')); icms_Event::attach('icms', 'finishcoreboot', array(__CLASS__, 'finishCoreBoot')); @@ -19,7 +20,8 @@ static public function setup() { /** * Called after the kernel initializes a service in icms::loadService - * @return void + * + * @return void */ static public function loadService($params, $event) { switch ($params['name']) { @@ -37,12 +39,13 @@ static public function finishCoreBoot() { /** * Create variables necessary for XOOPS / ICMS < 1.4 BC + * * @param array $params * @param icms_Event $event */ static public function backwardCompatibility($params, $event) { - + return true; } } -icms_BootstrapEventHandler::setup(); \ No newline at end of file +icms_BootstrapEventHandler::setup(); From af50282180859da31551633c78f42e0eff97ec5b Mon Sep 17 00:00:00 2001 From: Steve Kenow Date: Wed, 14 Jun 2023 22:01:13 -0500 Subject: [PATCH 2/9] Updating WideImage to v1.1.4 for PHP8 compatibility Note: upgrade process still needs to deal with removing the old library (for a case sensitive folder) and the online image editor library needs to be further debugged for PHP8 compliance. --- htdocs/libraries/image-editor/image-edit.php | 275 +++-- .../image-editor/plugins/crop/crop_image.php | 2 +- .../plugins/filter/filter_image.php | 55 +- .../image-editor/plugins/filter/preview.php | 3 +- .../image-editor/plugins/resize/preview.php | 3 +- .../plugins/resize/resize_image.php | 20 +- htdocs/libraries/wideimage/index.html | 1 - htdocs/libraries/wideimage/lib/Canvas.php | 167 --- htdocs/libraries/wideimage/lib/Coordinate.php | 208 ---- htdocs/libraries/wideimage/lib/Exception.php | 31 - htdocs/libraries/wideimage/lib/Font/GDF.php | 48 - htdocs/libraries/wideimage/lib/Font/PS.php | 60 -- htdocs/libraries/wideimage/lib/Font/TTF.php | 75 -- .../libraries/wideimage/lib/Font/index.html | 1 - htdocs/libraries/wideimage/lib/Image.php | 964 ----------------- htdocs/libraries/wideimage/lib/Mapper/BMP.php | 51 - htdocs/libraries/wideimage/lib/Mapper/GD.php | 44 - htdocs/libraries/wideimage/lib/Mapper/GD2.php | 41 - htdocs/libraries/wideimage/lib/Mapper/GIF.php | 50 - .../libraries/wideimage/lib/Mapper/JPEG.php | 41 - htdocs/libraries/wideimage/lib/Mapper/PNG.php | 41 - htdocs/libraries/wideimage/lib/Mapper/TGA.php | 48 - .../libraries/wideimage/lib/Mapper/index.html | 1 - .../libraries/wideimage/lib/MapperFactory.php | 126 --- .../wideimage/lib/Operation/AddNoise.php | 153 --- .../lib/Operation/ApplyConvolution.php | 48 - .../wideimage/lib/Operation/ApplyFilter.php | 67 -- .../wideimage/lib/Operation/ApplyMask.php | 105 -- .../wideimage/lib/Operation/AsGrayscale.php | 49 - .../wideimage/lib/Operation/AsNegative.php | 63 -- .../wideimage/lib/Operation/AutoCrop.php | 162 --- .../lib/Operation/CopyChannelsPalette.php | 90 -- .../lib/Operation/CopyChannelsTrueColor.php | 67 -- .../wideimage/lib/Operation/CorrectGamma.php | 48 - .../wideimage/lib/Operation/Crop.php | 86 -- .../wideimage/lib/Operation/Flip.php | 54 - .../wideimage/lib/Operation/GetMask.php | 67 -- .../wideimage/lib/Operation/Merge.php | 78 -- .../wideimage/lib/Operation/Mirror.php | 55 - .../wideimage/lib/Operation/Resize.php | 157 --- .../wideimage/lib/Operation/ResizeCanvas.php | 107 -- .../wideimage/lib/Operation/Rotate.php | 64 -- .../wideimage/lib/Operation/RoundCorners.php | 114 --- .../wideimage/lib/Operation/Unsharp.php | 135 --- .../wideimage/lib/Operation/index.html | 1 - .../wideimage/lib/OperationFactory.php | 57 -- .../libraries/wideimage/lib/PaletteImage.php | 136 --- htdocs/libraries/wideimage/lib/README | 21 - .../wideimage/lib/TrueColorImage.php | 218 ---- htdocs/libraries/wideimage/lib/VERSION | 2 - htdocs/libraries/wideimage/lib/WideImage.php | 377 ------- htdocs/libraries/wideimage/lib/gpl.txt | 339 ------ htdocs/libraries/wideimage/lib/index.html | 1 - htdocs/libraries/wideimage/lib/lgpl.txt | 504 --------- .../wideimage/lib/vendor/JPEXS/bmp.php | 537 ---------- .../wideimage/lib/vendor/JPEXS/ico.php | 965 ------------------ .../wideimage/lib/vendor/JPEXS/index.html | 1 - .../wideimage/lib/vendor/de77/BMP.php | 264 ----- .../wideimage/lib/vendor/de77/TGA.php | 206 ---- .../wideimage/lib/vendor/de77/index.html | 1 - .../libraries/wideimage/lib/vendor/index.html | 1 - htdocs/modules/system/admin/images/main.php | 224 ++-- 62 files changed, 280 insertions(+), 7700 deletions(-) delete mode 100644 htdocs/libraries/wideimage/index.html delete mode 100755 htdocs/libraries/wideimage/lib/Canvas.php delete mode 100755 htdocs/libraries/wideimage/lib/Coordinate.php delete mode 100755 htdocs/libraries/wideimage/lib/Exception.php delete mode 100755 htdocs/libraries/wideimage/lib/Font/GDF.php delete mode 100755 htdocs/libraries/wideimage/lib/Font/PS.php delete mode 100755 htdocs/libraries/wideimage/lib/Font/TTF.php delete mode 100644 htdocs/libraries/wideimage/lib/Font/index.html delete mode 100755 htdocs/libraries/wideimage/lib/Image.php delete mode 100755 htdocs/libraries/wideimage/lib/Mapper/BMP.php delete mode 100755 htdocs/libraries/wideimage/lib/Mapper/GD.php delete mode 100755 htdocs/libraries/wideimage/lib/Mapper/GD2.php delete mode 100755 htdocs/libraries/wideimage/lib/Mapper/GIF.php delete mode 100755 htdocs/libraries/wideimage/lib/Mapper/JPEG.php delete mode 100755 htdocs/libraries/wideimage/lib/Mapper/PNG.php delete mode 100644 htdocs/libraries/wideimage/lib/Mapper/TGA.php delete mode 100644 htdocs/libraries/wideimage/lib/Mapper/index.html delete mode 100755 htdocs/libraries/wideimage/lib/MapperFactory.php delete mode 100644 htdocs/libraries/wideimage/lib/Operation/AddNoise.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/ApplyConvolution.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/ApplyFilter.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/ApplyMask.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/AsGrayscale.php delete mode 100644 htdocs/libraries/wideimage/lib/Operation/AsNegative.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/AutoCrop.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/CopyChannelsPalette.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/CopyChannelsTrueColor.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/CorrectGamma.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/Crop.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/Flip.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/GetMask.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/Merge.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/Mirror.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/Resize.php delete mode 100644 htdocs/libraries/wideimage/lib/Operation/ResizeCanvas.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/Rotate.php delete mode 100644 htdocs/libraries/wideimage/lib/Operation/RoundCorners.php delete mode 100755 htdocs/libraries/wideimage/lib/Operation/Unsharp.php delete mode 100644 htdocs/libraries/wideimage/lib/Operation/index.html delete mode 100755 htdocs/libraries/wideimage/lib/OperationFactory.php delete mode 100755 htdocs/libraries/wideimage/lib/PaletteImage.php delete mode 100644 htdocs/libraries/wideimage/lib/README delete mode 100755 htdocs/libraries/wideimage/lib/TrueColorImage.php delete mode 100644 htdocs/libraries/wideimage/lib/VERSION delete mode 100755 htdocs/libraries/wideimage/lib/WideImage.php delete mode 100644 htdocs/libraries/wideimage/lib/gpl.txt delete mode 100644 htdocs/libraries/wideimage/lib/index.html delete mode 100644 htdocs/libraries/wideimage/lib/lgpl.txt delete mode 100755 htdocs/libraries/wideimage/lib/vendor/JPEXS/bmp.php delete mode 100755 htdocs/libraries/wideimage/lib/vendor/JPEXS/ico.php delete mode 100644 htdocs/libraries/wideimage/lib/vendor/JPEXS/index.html delete mode 100644 htdocs/libraries/wideimage/lib/vendor/de77/BMP.php delete mode 100644 htdocs/libraries/wideimage/lib/vendor/de77/TGA.php delete mode 100644 htdocs/libraries/wideimage/lib/vendor/de77/index.html delete mode 100644 htdocs/libraries/wideimage/lib/vendor/index.html diff --git a/htdocs/libraries/image-editor/image-edit.php b/htdocs/libraries/image-editor/image-edit.php index 3d1382fb75c8..8a6ee0b3f3be 100644 --- a/htdocs/libraries/image-editor/image-edit.php +++ b/htdocs/libraries/image-editor/image-edit.php @@ -4,15 +4,15 @@ * * Tool for resize, crop, rotate, apply filters and much more in images. * - * @copyright The ImpressCMS Project http://www.impresscms.org/ - * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL) - * @package core - * @since 1.2 - * @author Rodrigo Pereira Lima (AKA TheRplima) - * @version $Id: image-edit.php 1244 2008-03-18 17:09:11Z real_therplima $ + * @copyright The ImpressCMS Project http://www.impresscms.org/ + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL) + * @package core + * @since 1.2 + * @author Rodrigo Pereira Lima (AKA TheRplima) + * @version $Id: image-edit.php 1244 2008-03-18 17:09:11Z real_therplima $ */ -$xoopsOption ['nodebug'] = 1; -if (file_exists ( '../../mainfile.php' )) include_once '../../mainfile.php'; +$xoopsOption['nodebug'] = 1; +if (file_exists('../../mainfile.php')) include_once '../../mainfile.php'; defined('ICMS_ROOT_PATH') or die('ImpressCMS root path not defined'); @@ -20,42 +20,23 @@ exit(_NOPERM); } -include_once ICMS_LIBRARIES_PATH . '/wideimage/lib/WideImage.php'; +use WideImage\WideImage; icms_loadLanguageFile('system', 'images', true); $icmsTpl = new icms_view_Tpl(); /* set get and post filters, if not strings */ -$filter_get = array( - 'image_id' => 'int', - 'uniq' => 'str', - 'type' => 'str', - 'target' => 'str', - 'op' => 'str', - 'image_path' => 'str', - 'image_name' => 'str', - 'image_weight' => 'int', - 'image_display' => 'int', - 'image_temp' => 'str', - 'overwrite' => 'int', -); +$filter_get = array('image_id' => 'int', 'uniq' => 'str', 'type' => 'str', 'target' => 'str', 'op' => 'str', 'image_path' => 'str', 'image_name' => 'str', 'image_weight' => 'int', 'image_display' => 'int', 'image_temp' => 'str', 'overwrite' => 'int'); -$filter_post = array( - 'image_id' => 'int', - 'uniq' => 'str', - 'type' => 'str', - 'target' => 'str', - 'op' => 'str', -); +$filter_post = array('image_id' => 'int', 'uniq' => 'str', 'type' => 'str', 'target' => 'str', 'op' => 'str'); /* set default values for variables */ - /* filter the user input */ if (!empty($_GET)) { // in places where strict mode is not used for checkVarArray, make sure filter_ vars are not overwritten - if (isset($_GET['filter_post'])) unset ($_GET['filter_post']); + if (isset($_GET['filter_post'])) unset($_GET['filter_post']); $clean_GET = icms_core_DataFilter::checkVarArray($_GET, $filter_get, FALSE); extract($clean_GET); } @@ -72,7 +53,7 @@ $icmsTpl->assign('icms_imanager_temp_url', ICMS_IMANAGER_FOLDER_URL . '/temp'); if (!file_exists(ICMS_IMANAGER_FOLDER_PATH . '/temp/')) { - if(!@mkdir(ICMS_IMANAGER_FOLDER_PATH . '/temp', 0777)) { + if (!@mkdir(ICMS_IMANAGER_FOLDER_PATH . '/temp', 0777)) { echo ''; exit(); } @@ -83,11 +64,11 @@ session_start(); $_SESSION['icms_imanager'] = array(); } - if (!isset($_SESSION['icms_imanager'] ['imedit_target'])) { - $_SESSION['icms_imanager'] ['imedit_target'] = $target; + if (!isset($_SESSION['icms_imanager']['imedit_target'])) { + $_SESSION['icms_imanager']['imedit_target'] = $target; } - if (!isset($_SESSION['icms_imanager'] ['imedit_type'])) { - $_SESSION['icms_imanager'] ['imedit_type'] = $type; + if (!isset($_SESSION['icms_imanager']['imedit_type'])) { + $_SESSION['icms_imanager']['imedit_type'] = $type; } } @@ -99,116 +80,116 @@ } else { $image_path = NULL; } - + if (file_exists($image_path)) { @unlink($image_path); } - $arr = explode ( '/', $image_path ); - $arr [count ( $arr ) - 1] = 'orig_' . substr ( $arr [count ( $arr ) - 1], 5, strlen ( $arr [count ( $arr ) - 1] ) ); - $orig_img_path = implode ( '/', $arr ); + $arr = explode('/', $image_path); + $arr[count($arr) - 1] = 'orig_' . substr($arr[count($arr) - 1], 5, strlen($arr[count($arr) - 1])); + $orig_img_path = implode('/', $arr); - if (file_exists ( $orig_img_path )) { - @unlink ( $orig_img_path ); + if (file_exists($orig_img_path)) { + @unlink($orig_img_path); } - $plugins_arr = icms_core_Filesystem::getDirList ( ICMS_LIBRARIES_PATH . '/image-editor/plugins' ); - foreach ( $plugins_arr as $plugin_folder ) { - if (file_exists ( ICMS_LIBRARIES_PATH . '/image-editor/plugins/' . $plugin_folder . '/icms_plugin_version.php' )) { - $arr = explode ( '/', $image_path ); - $arr [count ( $arr ) - 1] = $plugin_folder . '_' . $arr [count ( $arr ) - 1]; - $temp_img_path = implode ( '/', $arr ); - @unlink ( $image_path ); + $plugins_arr = icms_core_Filesystem::getDirList(ICMS_LIBRARIES_PATH . '/image-editor/plugins'); + foreach ($plugins_arr as $plugin_folder) { + if (file_exists(ICMS_LIBRARIES_PATH . '/image-editor/plugins/' . $plugin_folder . '/icms_plugin_version.php')) { + $arr = explode('/', $image_path); + $arr[count($arr) - 1] = $plugin_folder . '_' . $arr[count($arr) - 1]; + $temp_img_path = implode('/', $arr); + @unlink($image_path); } } - if (isset ( $_SESSION ['icms_imanager'] )) { - unset ( $_SESSION ['icms_imanager'] ); + if (isset($_SESSION['icms_imanager'])) { + unset($_SESSION['icms_imanager']); } echo 'window.close();'; - exit (); + exit(); } if (!empty($op) && $op == 'save') { $simage_id = $image_id; $simage_name = $image_name; $simage_weight = $image_weight; $simage_display = $image_display; - $simage_temp = str_replace("..","_",$image_temp); + $simage_temp = str_replace("..", "_", $image_temp); $soverwrite = $overwrite; $image_handler = icms::handler('icms_image'); - $simage = & $image_handler->get($simage_id); + $simage = &$image_handler->get($simage_id); $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory = & $imgcat_handler->get ( $simage->getVar ( 'imgcat_id' ) ); + $imagecategory = &$imgcat_handler->get($simage->getVar('imgcat_id')); - $categ_path = $imgcat_handler->getCategFolder ( $imagecategory ); - $categ_path = (substr ( $categ_path, - 1 ) != '/') ? $categ_path . '/' : $categ_path; - $categ_url = $imgcat_handler->getCategFolder ( $imagecategory, 1, 'url' ); - $categ_url = (substr ( $categ_url, - 1 ) != '/') ? $categ_url . '/' : $categ_url; + $categ_path = $imgcat_handler->getCategFolder($imagecategory); + $categ_path = (substr($categ_path, -1) != '/') ? $categ_path . '/' : $categ_path; + $categ_url = $imgcat_handler->getCategFolder($imagecategory, 1, 'url'); + $categ_url = (substr($categ_url, -1) != '/') ? $categ_url . '/' : $categ_url; if ($soverwrite) { - if ($imagecategory->getVar ( 'imgcat_storetype' ) == 'db') { - $fp = @fopen ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp, 'rb' ); - $fbinary = @fread ( $fp, filesize ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp ) ); - @fclose ( $fp ); - $simage->setVar ( 'image_body', $fbinary, true ); - if (! $image_handler->insert ( $simage )) { - $msg = sprintf ( _FAILSAVEIMG, $simage->getVar ( 'image_nicename' ) ); + if ($imagecategory->getVar('imgcat_storetype') == 'db') { + $fp = @fopen(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp, 'rb'); + $fbinary = @fread($fp, filesize(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp)); + @fclose($fp); + $simage->setVar('image_body', $fbinary, true); + if (!$image_handler->insert($simage)) { + $msg = sprintf(_FAILSAVEIMG, $simage->getVar('image_nicename')); } else { $msg = _MD_AM_DBUPDATED; } } else { - if (@unlink ( $categ_path . $simage->getVar ( 'image_name' ) )) { - if (@copy ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp, $categ_path . $simage->getVar ( 'image_name' ) )) { - if (@unlink ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp )) { + if (@unlink($categ_path . $simage->getVar('image_name'))) { + if (@copy(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp, $categ_path . $simage->getVar('image_name'))) { + if (@unlink(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp)) { $msg = _MD_AM_DBUPDATED; } else { - $msg = sprintf ( _FAILSAVEIMG, $simage->getVar ( 'image_nicename' ) ); + $msg = sprintf(_FAILSAVEIMG, $simage->getVar('image_nicename')); } } else { - $msg = sprintf ( _FAILSAVEIMG, $simage->getVar ( 'image_nicename' ) ); + $msg = sprintf(_FAILSAVEIMG, $simage->getVar('image_nicename')); } } else { - $msg = sprintf ( _FAILSAVEIMG, $simage->getVar ( 'image_nicename' ) ); + $msg = sprintf(_FAILSAVEIMG, $simage->getVar('image_nicename')); } } } else { - $ext = substr ( $simage->getVar ( 'image_name' ), strlen ( $simage->getVar ( 'image_name' ) ) - 3, 3 ); - $imgname = 'img' . icms_random_str ( 12 ) . '.' . $ext; - $newimg = & $image_handler->create (); - $newimg->setVar ( 'image_name', $imgname ); - $newimg->setVar ( 'image_nicename', $simage_name ); - $newimg->setVar ( 'image_mimetype', $simage->getVar ( 'image_mimetype' ) ); - $newimg->setVar ( 'image_created', time () ); - $newimg->setVar ( 'image_display', $simage_display ); - $newimg->setVar ( 'image_weight', $simage_weight ); - $newimg->setVar ( 'imgcat_id', $simage->getVar ( 'imgcat_id' ) ); - if ($imagecategory->getVar ( 'imgcat_storetype' ) == 'db') { - $fp = @fopen ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp, 'rb' ); - $fbinary = @fread ( $fp, filesize ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp ) ); - @fclose ( $fp ); - $newimg->setVar ( 'image_body', $fbinary, true ); + $ext = substr($simage->getVar('image_name'), strlen($simage->getVar('image_name')) - 3, 3); + $imgname = 'img' . icms_random_str(12) . '.' . $ext; + $newimg = &$image_handler->create(); + $newimg->setVar('image_name', $imgname); + $newimg->setVar('image_nicename', $simage_name); + $newimg->setVar('image_mimetype', $simage->getVar('image_mimetype')); + $newimg->setVar('image_created', time()); + $newimg->setVar('image_display', $simage_display); + $newimg->setVar('image_weight', $simage_weight); + $newimg->setVar('imgcat_id', $simage->getVar('imgcat_id')); + if ($imagecategory->getVar('imgcat_storetype') == 'db') { + $fp = @fopen(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp, 'rb'); + $fbinary = @fread($fp, filesize(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp)); + @fclose($fp); + $newimg->setVar('image_body', $fbinary, true); } else { - if (copy ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp, $categ_path . $imgname )) { - @unlink ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp ); + if (copy(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp, $categ_path . $imgname)) { + @unlink(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $simage_temp); } } - if (! $image_handler->insert ( $newimg )) { - $msg = sprintf ( _FAILSAVEIMG, $newimg->getVar ( 'image_nicename' ) ); + if (!$image_handler->insert($newimg)) { + $msg = sprintf(_FAILSAVEIMG, $newimg->getVar('image_nicename')); } else { $msg = _MD_AM_DBUPDATED; } } - if (isset ( $_SESSION ['icms_imanager'] )) { //Image Editor open by some editor + if (isset($_SESSION['icms_imanager'])) { // Image Editor open by some editor $params = '?op=save_edit_ok&imgcat_id=' . (int) $simage->getVar('imgcat_id') . '&msg=' . urlencode($msg); - if (isset ( $_SESSION ['icms_imanager'] ['imedit_target'] )) { - $params .= '&target=' . $_SESSION ['icms_imanager'] ['imedit_target']; + if (isset($_SESSION['icms_imanager']['imedit_target'])) { + $params .= '&target=' . $_SESSION['icms_imanager']['imedit_target']; } - if (isset ( $_SESSION ['icms_imanager'] ['imedit_type'] )) { - $params .= '&type=' . $_SESSION ['icms_imanager'] ['imedit_type']; + if (isset($_SESSION['icms_imanager']['imedit_type'])) { + $params .= '&type=' . $_SESSION['icms_imanager']['imedit_type']; } - unset ( $_SESSION ['icms_imanager'] ); - } else { //Image Editor used inside the Image Manager + unset($_SESSION['icms_imanager']); + } else { // Image Editor used inside the Image Manager $params = '?fct=images&op=save_edit_ok&imgcat_id=' . (int) $simage->getVar('imgcat_id') . '&msg=' . urlencode($msg); } echo 'cancel_edit();'; @@ -216,71 +197,71 @@ echo 'window.opener.location.href=url;'; echo 'window.opener.focus();'; echo 'window.close();'; - exit (); + exit(); } $image_handler = icms::handler('icms_image'); -$original_image = & $image_handler->get ( $image_id ); -if (! is_object ( $original_image )) { - die ( _ERROR ); +$original_image = &$image_handler->get($image_id); +if (!is_object($original_image)) { + die(_ERROR); } $imgcat_handler = icms::handler('icms_image_category'); -$imagecategory = & $imgcat_handler->get ( $original_image->getVar ( 'imgcat_id' ) ); -if (! is_object ( $imagecategory )) { - die ( _ERROR ); +$imagecategory = &$imgcat_handler->get($original_image->getVar('imgcat_id')); +if (!is_object($imagecategory)) { + die(_ERROR); } -$categ_path = $imgcat_handler->getCategFolder ( $imagecategory ); -$categ_path = (substr ( $categ_path, - 1 ) != '/') ? $categ_path . '/' : $categ_path; -$categ_url = $imgcat_handler->getCategFolder ( $imagecategory, 1, 'url' ); -$categ_url = (substr ( $categ_url, - 1 ) != '/') ? $categ_url . '/' : $categ_url; +$categ_path = $imgcat_handler->getCategFolder($imagecategory); +$categ_path = (substr($categ_path, -1) != '/') ? $categ_path . '/' : $categ_path; +$categ_url = $imgcat_handler->getCategFolder($imagecategory, 1, 'url'); +$categ_url = (substr($categ_url, -1) != '/') ? $categ_url . '/' : $categ_url; -#Creating the temporary image. This temp image that will be edited and at the end will be converted to the final image. -$temp_img_name = 'temp_' . $uniq . '_' . $original_image->getVar ( 'image_name' ); -$orig_img_name = 'orig_' . $uniq . '_' . $original_image->getVar ( 'image_name' ); -if (! file_exists ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name )) { - if ($imagecategory->getVar ( 'imgcat_storetype' ) == 'db') { - $temp_img = WideImage::loadFromString ( $original_image->getVar ( 'image_body' ) ); - $orig_img = WideImage::loadFromString ( $original_image->getVar ( 'image_body' ) ); +# Creating the temporary image. This temp image that will be edited and at the end will be converted to the final image. +$temp_img_name = 'temp_' . $uniq . '_' . $original_image->getVar('image_name'); +$orig_img_name = 'orig_' . $uniq . '_' . $original_image->getVar('image_name'); +if (!file_exists(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name)) { + if ($imagecategory->getVar('imgcat_storetype') == 'db') { + $temp_img = WideImage::loadFromString($original_image->getVar('image_body')); + $orig_img = WideImage::loadFromString($original_image->getVar('image_body')); } else { - $temp_img = WideImage::load ( $categ_path . $original_image->getVar ( 'image_name' ) ); - $orig_img = WideImage::load ( $categ_path . $original_image->getVar ( 'image_name' ) ); + $temp_img = WideImage::load($categ_path . $original_image->getVar('image_name')); + $orig_img = WideImage::load($categ_path . $original_image->getVar('image_name')); } - $temp_img->saveToFile ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name ); - $orig_img->saveToFile ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $orig_img_name ); + $temp_img->saveToFile(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name); + $orig_img->saveToFile(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $orig_img_name); } else { - $temp_img = WideImage::load ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name ); - $orig_img = WideImage::load ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $orig_img_name ); + $temp_img = WideImage::load(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name); + $orig_img = WideImage::load(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $orig_img_name); } -$img = array ( ); -$img ['name'] = $temp_img_name; -$img ['originalname'] = $original_image->getVar ( 'image_name' ); -$img ['id'] = $original_image->getVar ( 'image_id' ); -$img ['title'] = $original_image->getVar ( 'image_nicename' ); -$img ['url'] = ICMS_IMANAGER_FOLDER_URL . '/temp/' . $temp_img_name; -$img ['previewurl'] = ICMS_IMANAGER_FOLDER_URL . '/temp/' . $temp_img_name . '?' . time (); -$img ['originalurl'] = ICMS_IMANAGER_FOLDER_URL . '/temp/' . $orig_img_name; -$img ['path'] = ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name; -$img ['width'] = $temp_img->getWidth (); -$img ['height'] = $temp_img->getHeight (); -$img ['size'] = icms_convert_size ( filesize ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name ) ); -$img ['ori_width'] = $orig_img->getWidth (); -$img ['ori_height'] = $orig_img->getHeight (); -$img ['ori_size'] = icms_convert_size ( filesize ( ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $orig_img_name ) ); +$img = array(); +$img['name'] = $temp_img_name; +$img['originalname'] = $original_image->getVar('image_name'); +$img['id'] = $original_image->getVar('image_id'); +$img['title'] = $original_image->getVar('image_nicename'); +$img['url'] = ICMS_IMANAGER_FOLDER_URL . '/temp/' . $temp_img_name; +$img['previewurl'] = ICMS_IMANAGER_FOLDER_URL . '/temp/' . $temp_img_name . '?' . time(); +$img['originalurl'] = ICMS_IMANAGER_FOLDER_URL . '/temp/' . $orig_img_name; +$img['path'] = ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name; +$img['width'] = $temp_img->getWidth(); +$img['height'] = $temp_img->getHeight(); +$img['size'] = icms_convert_size(filesize(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $temp_img_name)); +$img['ori_width'] = $orig_img->getWidth(); +$img['ori_height'] = $orig_img->getHeight(); +$img['ori_size'] = icms_convert_size(filesize(ICMS_IMANAGER_FOLDER_PATH . '/temp/' . $orig_img_name)); -$icmsTpl->assign ( 'image', $img ); +$icmsTpl->assign('image', $img); -#Getting the plugins for the editor -$plugins_arr = icms_core_Filesystem::getDirList ( ICMS_LIBRARIES_PATH . '/image-editor/plugins' ); -foreach ( $plugins_arr as $plugin_folder ) { - if (file_exists ( ICMS_LIBRARIES_PATH . '/image-editor/plugins/' . $plugin_folder . '/icms_plugin_version.php' )) { - if (file_exists ( ICMS_LIBRARIES_PATH . '/image-editor/plugins/' . $plugin_folder . '/language/' . $icmsConfig ['language'] . '/main.php' )) { - include_once ICMS_LIBRARIES_PATH . '/image-editor/plugins/' . $plugin_folder . '/language/' . $icmsConfig ['language'] . '/main.php'; +# Getting the plugins for the editor +$plugins_arr = icms_core_Filesystem::getDirList(ICMS_LIBRARIES_PATH . '/image-editor/plugins'); +foreach ($plugins_arr as $plugin_folder) { + if (file_exists(ICMS_LIBRARIES_PATH . '/image-editor/plugins/' . $plugin_folder . '/icms_plugin_version.php')) { + if (file_exists(ICMS_LIBRARIES_PATH . '/image-editor/plugins/' . $plugin_folder . '/language/' . $icmsConfig['language'] . '/main.php')) { + include_once ICMS_LIBRARIES_PATH . '/image-editor/plugins/' . $plugin_folder . '/language/' . $icmsConfig['language'] . '/main.php'; } include_once ICMS_LIBRARIES_PATH . '/image-editor/plugins/' . $plugin_folder . '/icms_plugin_version.php'; - $icmsTpl->append ( 'plugins', $plugversion ); - unset ( $plugversion ); + $icmsTpl->append('plugins', $plugversion); + unset($plugversion); } } -echo $icmsTpl->fetch ( ICMS_LIBRARIES_PATH . '/image-editor/templates/image-editor.html' ); +echo $icmsTpl->fetch(ICMS_LIBRARIES_PATH . '/image-editor/templates/image-editor.html'); diff --git a/htdocs/libraries/image-editor/plugins/crop/crop_image.php b/htdocs/libraries/image-editor/plugins/crop/crop_image.php index 338241885802..b02d60b0a4ec 100644 --- a/htdocs/libraries/image-editor/plugins/crop/crop_image.php +++ b/htdocs/libraries/image-editor/plugins/crop/crop_image.php @@ -11,6 +11,7 @@ */ $xoopsOption['nodebug'] = 1; require_once '../../../../mainfile.php'; +use WideImage\WideImage; /* 2 critical parameters must exist - and must be safe */ $image_path = filter_input(INPUT_GET, 'image_path', FILTER_SANITIZE_STRING); @@ -34,7 +35,6 @@ if (!isset($image_path) || !isset($image_url)) { echo "alert('" . _ERROR . "');"; } else { - include_once ICMS_LIBRARIES_PATH . '/wideimage/lib/WideImage.php'; $x = (int) $_GET['x']; $y = (int) $_GET['y']; diff --git a/htdocs/libraries/image-editor/plugins/filter/filter_image.php b/htdocs/libraries/image-editor/plugins/filter/filter_image.php index dcb1bc74a96b..beb297c945f6 100644 --- a/htdocs/libraries/image-editor/plugins/filter/filter_image.php +++ b/htdocs/libraries/image-editor/plugins/filter/filter_image.php @@ -11,13 +11,13 @@ */ $xoopsOption['nodebug'] = 1; require_once '../../../../mainfile.php'; +use WideImage\WideImage; /* 3 critical parameters must exist - and must be safe */ $image_path = filter_input(INPUT_GET, 'image_path', FILTER_SANITIZE_STRING); $image_url = filter_input(INPUT_GET, 'image_url', FILTER_SANITIZE_URL); $filter = filter_input(INPUT_GET, 'filter', FILTER_SANITIZE_STRING); - /* prevent remote file inclusion */ $valid_path = ICMS_IMANAGER_FOLDER_PATH . '/temp'; if (!empty($image_path) && strncmp(realpath($image_path), strlen($valid_path)) == 0) { @@ -35,19 +35,18 @@ /* possible filter entries */ $filters = array( - 'IMG_FILTER_NEGATE', - 'IMG_FILTER_GRAYSCALE', - 'IMG_FILTER_BRIGHTNESS', - 'IMG_FILTER_CONTRAST', - 'IMG_FILTER_COLORIZE', - 'IMG_FILTER_EDGEDETECT', - 'IMG_FILTER_EMBOSS', - 'IMG_FILTER_GAUSSIAN_BLUR', - 'IMG_FILTER_SELECTIVE_BLUR', - 'IMG_FILTER_MEAN_REMOVAL', - 'IMG_FILTER_SMOOTH', - 'IMG_FILTER_SEPIA' -); + 'IMG_FILTER_NEGATE', + 'IMG_FILTER_GRAYSCALE', + 'IMG_FILTER_BRIGHTNESS', + 'IMG_FILTER_CONTRAST', + 'IMG_FILTER_COLORIZE', + 'IMG_FILTER_EDGEDETECT', + 'IMG_FILTER_EMBOSS', + 'IMG_FILTER_GAUSSIAN_BLUR', + 'IMG_FILTER_SELECTIVE_BLUR', + 'IMG_FILTER_MEAN_REMOVAL', + 'IMG_FILTER_SMOOTH', + 'IMG_FILTER_SEPIA'); $filter = isset($_GET['filter']) ? filter_var($_GET['filter'], FILTER_SANITIZE_STRING) : null; if (!in_array($filter, $filters)) $filter = null; @@ -55,11 +54,11 @@ if (!isset($image_path) || !isset($image_url)) { echo "alert('" . _ERROR . "');"; } else { - /* this goes here instead of the initial conditions - * because errors occur when previewing the filter effect */ - if (!isset($filter)) exit; - - include_once ICMS_LIBRARIES_PATH . '/wideimage/lib/WideImage.php'; + /* + * this goes here instead of the initial conditions + * because errors occur when previewing the filter effect + */ + if (!isset($filter)) exit(); $args = array(); @@ -74,45 +73,45 @@ } $save = isset($_GET['save']) ? (int) $_GET['save'] : 0; - $del = isset($_GET['delprev']) ? (int) $_GET['delprev'] : 0; + $del = isset($_GET['delprev']) ? (int) $_GET['delprev'] : 0; $img = WideImage::load($image_path); $arr = explode('/', $image_path); - $arr[count($arr)-1] = 'filter_' . $arr[count($arr)-1]; + $arr[count($arr) - 1] = 'filter_' . $arr[count($arr) - 1]; $temp_img_path = implode('/', $arr); $arr = explode('/', $image_url); - $arr[count($arr)-1] = 'filter_' . $arr[count($arr)-1]; + $arr[count($arr) - 1] = 'filter_' . $arr[count($arr) - 1]; $temp_img_url = implode('/', $arr); if ($del) { @unlink($temp_img_path); - exit; + exit(); } if ($filter == 'IMG_FILTER_SEPIA') { $img->applyFilter(IMG_FILTER_GRAYSCALE)->applyFilter(IMG_FILTER_COLORIZE, 90, 60, 30)->saveToFile($temp_img_path); - }else{ + } else { $img->applyFilter(constant($filter), implode(',', $args))->saveToFile($temp_img_path); } if ($save) { if (!@unlink($image_path)) { echo "alert('" . _ERROR . "');"; - exit; + exit(); } if (!@copy($temp_img_path, $image_path)) { echo "alert('" . _ERROR . "');"; - exit; + exit(); } if (!@unlink($temp_img_path)) { echo "alert('" . _ERROR . "');"; - exit; + exit(); } echo 'window.location.reload( true );'; } else { $width = $img->getWidth(); $height = $img->getHeight(); - echo "var w = window.open('".$temp_img_url."','crop_image_preview','width=".($width+20).",height=".($height+20).",resizable=yes');"; + echo "var w = window.open('" . $temp_img_url . "','crop_image_preview','width=" . ($width + 20) . ",height=" . ($height + 20) . ",resizable=yes');"; echo "w.onunload = function (){filter_delpreview();}"; } } diff --git a/htdocs/libraries/image-editor/plugins/filter/preview.php b/htdocs/libraries/image-editor/plugins/filter/preview.php index bd432c549aab..f2e5e54d8112 100644 --- a/htdocs/libraries/image-editor/plugins/filter/preview.php +++ b/htdocs/libraries/image-editor/plugins/filter/preview.php @@ -2,6 +2,7 @@ $xoopsOption['nodebug'] = 1; if (file_exists('../../../../mainfile.php')) include_once '../../../../mainfile.php'; if (!defined('ICMS_ROOT_PATH')) die("ImpressCMS root path not defined"); +use WideImage\WideImage; $file = $_GET['file']; $resize = isset($_GET['resize']) ? (int) $_GET['resize'] : 1; @@ -31,7 +32,7 @@ echo $img->applyFilter(IMG_FILTER_GRAYSCALE)->applyFilter(IMG_FILTER_COLORIZE, 90, 60, 30)->asString('png'); } } else { - if ($resize && ($width > 400 || $height > 300)){ + if ($resize && ($width > 400 || $height > 300)) { echo $img->resize(400, 300)->applyFilter(constant($filter), implode(',', $args))->asString('png'); } else { echo $img->applyFilter(constant($filter), implode(',', $args))->asString('png'); diff --git a/htdocs/libraries/image-editor/plugins/resize/preview.php b/htdocs/libraries/image-editor/plugins/resize/preview.php index 3cc06aa46766..4d75a93a2515 100644 --- a/htdocs/libraries/image-editor/plugins/resize/preview.php +++ b/htdocs/libraries/image-editor/plugins/resize/preview.php @@ -2,12 +2,13 @@ $xoopsOption['nodebug'] = 1; if (file_exists('../../../../mainfile.php')) include_once '../../../../mainfile.php'; if (!defined('ICMS_ROOT_PATH')) die("ImpressCMS root path not defined"); +use WideImage\WideImage; $file = $_GET['file']; $width = isset($_GET['width']) ? (int) $_GET['width'] : null; $height = isset($_GET['height']) ? (int) $_GET['height'] : null; -if (substr($width, 0, strlen($width)-1) == '%' || substr($height, 0, strlen($height)-1) == '%') { +if (substr($width, 0, strlen($width) - 1) == '%' || substr($height, 0, strlen($height) - 1) == '%') { $fit = 'fill'; } else { $fit = 'inside'; diff --git a/htdocs/libraries/image-editor/plugins/resize/resize_image.php b/htdocs/libraries/image-editor/plugins/resize/resize_image.php index 98e7c7a587e8..16071b934409 100644 --- a/htdocs/libraries/image-editor/plugins/resize/resize_image.php +++ b/htdocs/libraries/image-editor/plugins/resize/resize_image.php @@ -11,13 +11,13 @@ */ $xoopsOption['nodebug'] = 1; require_once '../../../../mainfile.php'; +use WideImage\WideImage; /* 3 critical parameters must exist - and must be safe */ $image_path = filter_input(INPUT_GET, 'image_path', FILTER_SANITIZE_STRING); $image_url = filter_input(INPUT_GET, 'image_url', FILTER_SANITIZE_URL); $filter = filter_input(INPUT_GET, 'filter', FILTER_SANITIZE_STRING); - /* prevent remote file inclusion */ $valid_path = ICMS_IMANAGER_FOLDER_PATH . '/temp'; if (!empty($image_path) && strncmp(realpath($image_path), strlen($valid_path)) == 0) { @@ -36,8 +36,6 @@ if (!isset($image_path) || !isset($image_url)) { echo "alert('" . _ERROR . "');"; } else { - include_once ICMS_LIBRARIES_PATH . '/wideimage/lib/WideImage.php'; - $fit = 'inside'; $width = null; $height = null; @@ -61,19 +59,19 @@ } $save = isset($_GET['save']) ? (int) $_GET['save'] : 0; - $del = isset($_GET['delprev']) ? (int) $_GET['delprev'] : 0; + $del = isset($_GET['delprev']) ? (int) $_GET['delprev'] : 0; $img = WideImage::load($image_path); $arr = explode('/', $image_path); - $arr[count($arr)-1] = 'resize_' . $arr[count($arr)-1]; + $arr[count($arr) - 1] = 'resize_' . $arr[count($arr) - 1]; $temp_img_path = implode('/', $arr); $arr = explode('/', $image_url); - $arr[count($arr)-1] = 'resize_' . $arr[count($arr)-1]; + $arr[count($arr) - 1] = 'resize_' . $arr[count($arr) - 1]; $temp_img_url = implode('/', $arr); if ($del) { @unlink($temp_img_path); - exit; + exit(); } $img->resize($width, $height, $fit)->saveToFile($temp_img_path); @@ -81,19 +79,19 @@ if ($save) { if (!@unlink($image_path)) { echo "alert('" . _ERROR . "');"; - exit; + exit(); } if (!@copy($temp_img_path, $image_path)) { echo "alert('" . _ERROR . "');"; - exit; + exit(); } if (!@unlink($temp_img_path)) { echo "alert('" . _ERROR . "');"; - exit; + exit(); } echo 'window.location.reload( true );'; } else { - echo "var w = window.open('".$temp_img_url."','resize_image_preview','width=".($width+20).",height=".($height+20).",resizable=yes');"; + echo "var w = window.open('" . $temp_img_url . "','resize_image_preview','width=" . ($width + 20) . ",height=" . ($height + 20) . ",resizable=yes');"; echo "w.onunload = function (){resize_delpreview();}"; } } diff --git a/htdocs/libraries/wideimage/index.html b/htdocs/libraries/wideimage/index.html deleted file mode 100644 index 990cbd60372e..000000000000 --- a/htdocs/libraries/wideimage/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/Canvas.php b/htdocs/libraries/wideimage/lib/Canvas.php deleted file mode 100755 index 1b9ad5b181e9..000000000000 --- a/htdocs/libraries/wideimage/lib/Canvas.php +++ /dev/null @@ -1,167 +0,0 @@ -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: - * - * $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'); - * - * - * @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: - * - * $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)); - * - */ - 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}."); - } - } diff --git a/htdocs/libraries/wideimage/lib/Coordinate.php b/htdocs/libraries/wideimage/lib/Coordinate.php deleted file mode 100755 index a3f6f63732e0..000000000000 --- a/htdocs/libraries/wideimage/lib/Coordinate.php +++ /dev/null @@ -1,208 +0,0 @@ - '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; - } - } diff --git a/htdocs/libraries/wideimage/lib/Exception.php b/htdocs/libraries/wideimage/lib/Exception.php deleted file mode 100755 index fa9b8da0c583..000000000000 --- a/htdocs/libraries/wideimage/lib/Exception.php +++ /dev/null @@ -1,31 +0,0 @@ -= 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); - } - } diff --git a/htdocs/libraries/wideimage/lib/Font/PS.php b/htdocs/libraries/wideimage/lib/Font/PS.php deleted file mode 100755 index 1e660e4d6751..000000000000 --- a/htdocs/libraries/wideimage/lib/Font/PS.php +++ /dev/null @@ -1,60 +0,0 @@ -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; - } - } diff --git a/htdocs/libraries/wideimage/lib/Font/TTF.php b/htdocs/libraries/wideimage/lib/Font/TTF.php deleted file mode 100755 index 4da97cb05fd9..000000000000 --- a/htdocs/libraries/wideimage/lib/Font/TTF.php +++ /dev/null @@ -1,75 +0,0 @@ -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); - } - } diff --git a/htdocs/libraries/wideimage/lib/Font/index.html b/htdocs/libraries/wideimage/lib/Font/index.html deleted file mode 100644 index 74b6f45c8f33..000000000000 --- a/htdocs/libraries/wideimage/lib/Font/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/Image.php b/htdocs/libraries/wideimage/lib/Image.php deleted file mode 100755 index 3a99280008f0..000000000000 --- a/htdocs/libraries/wideimage/lib/Image.php +++ /dev/null @@ -1,964 +0,0 @@ -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: - * - * // 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'); - * - * - * @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: - * - * WideImage::load('image1.png')->resize(100, 100)->output('gif'); - * - * - * @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): - * - * $smaller = $image->resize('50%'); - * - * $smaller = $image->resize('100', '100', 'inside', 'down'); - * is the same as - * $smaller = $image->resizeDown(100, 100, 'inside'); - * - * - * @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: - * - * $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 - * - * - * @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]. - * - * $image = WideImage::load('someimage.jpg'); // 100x150 - * $white = $image->allocateColor(255, 255, 255); - * $image->resizeCanvas('200%', '100% + 20', 10, 'center+20', $white); - * - * - * 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: - * - * $nice = $ugly->roundCorners(20, $ugly->allocateColor(255, 0, 0), 2); - * - * - * 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: - * - * $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); - * - * - * @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: - * - * $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 - * - * - * This operation supports alignment notation in left/top coordinates. - * Example: - * - * $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 - * - * - * @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: - * - * $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'); - * - * - * @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: - * - * $channels = $img->getChannels('red', 'blue'); - * $channels = $img->getChannels('alpha', 'green'); - * $channels = $img->getChannels(array('green', 'blue')); - * - * - * @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; - } - } diff --git a/htdocs/libraries/wideimage/lib/Mapper/BMP.php b/htdocs/libraries/wideimage/lib/Mapper/BMP.php deleted file mode 100755 index 065f50e5cb12..000000000000 --- a/htdocs/libraries/wideimage/lib/Mapper/BMP.php +++ /dev/null @@ -1,51 +0,0 @@ -history.go(-1); \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/MapperFactory.php b/htdocs/libraries/wideimage/lib/MapperFactory.php deleted file mode 100755 index 966fd7ea895a..000000000000 --- a/htdocs/libraries/wideimage/lib/MapperFactory.php +++ /dev/null @@ -1,126 +0,0 @@ - 'JPEG', - 'image/jpeg' => 'JPEG', - 'image/pjpeg' => 'JPEG', - 'image/gif' => 'GIF', - 'image/png' => 'PNG' - ); - - /** - * Returns a mapper, based on the $uri and $format - * - * @param string $uri File URI - * @param string $format File format (extension or mime-type) or null - * @return WideImage_Mapper - **/ - static function selectMapper($uri, $format = null) - { - $format = self::determineFormat($uri, $format); - - if (array_key_exists($format, self::$mappers)) - return self::$mappers[$format]; - - $mapperClassName = 'WideImage_Mapper_' . $format; - - if (!class_exists($mapperClassName, false)) - { - $mapperFileName = WideImage::path() . 'Mapper/' . $format . '.php'; - if (file_exists($mapperFileName)) - require_once $mapperFileName; - } - - if (class_exists($mapperClassName)) - { - self::$mappers[$format] = new $mapperClassName(); - return self::$mappers[$format]; - } - - throw new WideImage_UnsupportedFormatException("Format '{$format}' is not supported."); - } - - static function registerMapper($mapper_class_name, $mime_type, $extension) - { - self::$customMappers[$mime_type] = $mapper_class_name; - self::$mimeTable[$mime_type] = $extension; - } - - static function getCustomMappers() - { - return self::$customMappers; - } - - static function determineFormat($uri, $format = null) - { - if ($format == null) - $format = self::extractExtension($uri); - - // mime-type match - if (preg_match('~[a-z]*/[a-z-]*~i', $format)) - if (isset(self::$mimeTable[strtolower($format)])) - { - return self::$mimeTable[strtolower($format)]; - } - - // clean the string - $format = strtoupper(preg_replace('/[^a-z0-9_-]/i', '', $format)); - if ($format == 'JPG') - $format = 'JPEG'; - - return $format; - } - - static function mimeType($format) - { - return array_search(strtoupper($format), self::$mimeTable); - } - - static function extractExtension($uri) - { - $p = strrpos($uri, '.'); - if ($p === false) - return ''; - else - return substr($uri, $p + 1); - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/AddNoise.php b/htdocs/libraries/wideimage/lib/Operation/AddNoise.php deleted file mode 100644 index 879919939960..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/AddNoise.php +++ /dev/null @@ -1,153 +0,0 @@ -asTrueColor(), $fun, $amount); - } - - /** - * Returns image with every pixel changed by specififed function - * - * @param WideImage_Image $image - * @param str $function - * @param int $value - * @return WideImage_Image - */ - function filter($image, $function, $value) - { - for ($y = 0; $y < $image->getHeight(); $y++) - { - for ($x = 0; $x< $image->getWidth(); $x++) - { - $rgb = imagecolorat($image->getHandle(), $x, $y); - - $a = ($rgb >> 24) & 0xFF; - $r = ($rgb >> 16) & 0xFF; - $g = ($rgb >> 8) & 0xFF; - $b = $rgb & 0xFF; - - - self::$function($r, $g, $b, $value); - - $color = imagecolorallocatealpha($image->getHandle(), $r, $g, $b, $a); - imagesetpixel($image->getHandle(), $x, $y, $color); - } - } - return $image; - } - /** - * Adds color noise by altering given R,G,B values using specififed amount - * - * @param int $r - * @param int $g - * @param int $b - * @param int $value - * @return void - */ - function colorNoise_fun(&$r, &$g, &$b, $amount) - { - $r = self::byte($r + mt_rand(0, $amount) - ($amount >> 1) ); - $g = self::byte($g + mt_rand(0, $amount) - ($amount >> 1) ); - $b = self::byte($b + mt_rand(0, $amount) - ($amount >> 1) ); - } - /** - * Adds mono noise by altering given R,G,B values using specififed amount - * - * @param int $r - * @param int $g - * @param int $b - * @param int $value - * @return void - */ - function monoNoise_fun(&$r, &$g, &$b, $amount) - { - $rand = mt_rand(0, $amount) - ($amount >> 1); - - $r = self::byte($r + $rand); - $g = self::byte($g + $rand); - $b = self::byte($b + $rand); - } - /** - * Adds salt&pepper noise by altering given R,G,B values using specififed amount - * - * @param int $r - * @param int $g - * @param int $b - * @param int $value - * @return void - */ - function saltPepperNoise_fun(&$r, &$g, &$b, $amount) - { - if (mt_rand(0, 255 - $amount) != 0) return; - - $rand = mt_rand(0, 1); - switch ($rand) - { - case 0 : $r = $g = $b = 0; - break; - case 1 : $r = $g = $b = 255; - break; - } - } - /** - * Returns value within (0,255) - * - * @param int $b - * @return int - */ - function byte($b) - { - if ($b > 255) return 255; - if ($b < 0) return 0; - return (int) $b; - } - - } diff --git a/htdocs/libraries/wideimage/lib/Operation/ApplyConvolution.php b/htdocs/libraries/wideimage/lib/Operation/ApplyConvolution.php deleted file mode 100755 index a26d918ae799..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/ApplyConvolution.php +++ /dev/null @@ -1,48 +0,0 @@ -asTrueColor(); - if (!imageconvolution($new->getHandle(), $matrix, $div, $offset)) - throw new WideImage_GDFunctionResultException("imageconvolution() returned false"); - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/ApplyFilter.php b/htdocs/libraries/wideimage/lib/Operation/ApplyFilter.php deleted file mode 100755 index b513d5dbc107..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/ApplyFilter.php +++ /dev/null @@ -1,67 +0,0 @@ -asTrueColor(); - - if (in_array($filter, self::$one_arg_filters)) - $res = imagefilter($new->getHandle(), $filter, $arg1); - elseif (defined('IMG_FILTER_PIXELATE') && $filter == IMG_FILTER_PIXELATE) - $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2); - elseif ($filter == IMG_FILTER_COLORIZE) - $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2, $arg3, $arg4); - else - $res = imagefilter($new->getHandle(), $filter); - - if (!$res) - throw new WideImage_GDFunctionResultException("imagefilter() returned false"); - - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/ApplyMask.php b/htdocs/libraries/wideimage/lib/Operation/ApplyMask.php deleted file mode 100755 index 949213f0c192..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/ApplyMask.php +++ /dev/null @@ -1,105 +0,0 @@ -getWidth(), $mask->getWidth()); - $top = WideImage_Coordinate::fix($top, $image->getHeight(), $mask->getHeight()); - - $width = $image->getWidth(); - $mask_width = $mask->getWidth(); - - $height = $image->getHeight(); - $mask_height = $mask->getHeight(); - - $result = $image->asTrueColor(); - - $result->alphaBlending(false); - $result->saveAlpha(true); - - $srcTransparentColor = $result->getTransparentColor(); - if ($srcTransparentColor >= 0) - { - # this was here. works without. - #$trgb = $image->getColorRGB($srcTransparentColor); - #$trgb['alpha'] = 127; - #$destTransparentColor = $result->allocateColorAlpha($trgb); - #$result->setTransparentColor($destTransparentColor); - $destTransparentColor = $srcTransparentColor; - } - else - { - $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127); - } - - for ($x = 0; $x < $width; $x++) - for ($y = 0; $y < $height; $y++) - { - $mx = $x - $left; - $my = $y - $top; - if ($mx >= 0 && $mx < $mask_width && $my >= 0 && $my < $mask_height) - { - $srcColor = $image->getColorAt($x, $y); - if ($srcColor == $srcTransparentColor) - $destColor = $destTransparentColor; - else - { - $maskRGB = $mask->getRGBAt($mx, $my); - if ($maskRGB['red'] == 0) - $destColor = $destTransparentColor; - elseif ($srcColor >= 0) - { - $imageRGB = $image->getRGBAt($x, $y); - $level = ($maskRGB['red'] / 255) * (1 - $imageRGB['alpha'] / 127); - $imageRGB['alpha'] = 127 - round($level * 127); - if ($imageRGB['alpha'] == 127) - $destColor = $destTransparentColor; - else - $destColor = $result->allocateColorAlpha($imageRGB); - } - else - $destColor = $destTransparentColor; - } - $result->setColorAt($x, $y, $destColor); - } - } - return $result; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/AsGrayscale.php b/htdocs/libraries/wideimage/lib/Operation/AsGrayscale.php deleted file mode 100755 index 4e64d089ac7e..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/AsGrayscale.php +++ /dev/null @@ -1,49 +0,0 @@ -asTrueColor(); - if (!imagefilter($new->getHandle(), IMG_FILTER_GRAYSCALE)) - throw new WideImage_GDFunctionResultException("imagefilter() returned false"); - - if (!$image->isTrueColor()) - $new = $new->asPalette(); - - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/AsNegative.php b/htdocs/libraries/wideimage/lib/Operation/AsNegative.php deleted file mode 100644 index 85f0667b8c69..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/AsNegative.php +++ /dev/null @@ -1,63 +0,0 @@ -isTrueColor(); - $transparent = $image->isTransparent(); - - if ($palette && $transparent) - $tcrgb = $image->getTransparentColorRGB(); - - $new = $image->asTrueColor(); - if (!imagefilter($new->getHandle(), IMG_FILTER_NEGATE)) - throw new WideImage_GDFunctionResultException("imagefilter() returned false"); - - if ($palette) - { - $new = $new->asPalette(); - if ($transparent) - { - $irgb = array('red' => 255 - $tcrgb['red'], 'green' => 255 - $tcrgb['green'], 'blue' => 255 - $tcrgb['blue'], 'alpha' => 127); - // needs imagecolorexactalpha instead of imagecolorexact, otherwise doesn't work on some transparent GIF images - $new_tci = imagecolorexactalpha($new->getHandle(), $irgb['red'], $irgb['green'], $irgb['blue'], 127); - $new->setTransparentColor($new_tci); - } - } - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/AutoCrop.php b/htdocs/libraries/wideimage/lib/Operation/AutoCrop.php deleted file mode 100755 index 73e7603b07e5..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/AutoCrop.php +++ /dev/null @@ -1,162 +0,0 @@ -getRGBAt(0, 0); - else - { - if ($base_color < 0) - return $img->copy(); - - $rgb_base = $img->getColorRGB($base_color); - } - - $cut_rect = array('left' => 0, 'top' => 0, 'right' => $img->getWidth() - 1, 'bottom' => $img->getHeight() - 1); - - for ($y = 0; $y <= $cut_rect['bottom']; $y++) - { - $count = 0; - for ($x = 0; $x <= $cut_rect['right']; $x++) - { - $rgb = $img->getRGBAt($x, $y); - $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); - if ($diff > $rgb_threshold) - { - $count++; - if ($count >= $pixel_cutoff) - { - $cut_rect['top'] = $y; - break 2; - } - } - } - } - - for ($y = $img->getHeight() - 1; $y >= $cut_rect['top']; $y--) - { - $count = 0; - for ($x = 0; $x <= $cut_rect['right']; $x++) - { - $rgb = $img->getRGBAt($x, $y); - $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); - if ($diff > $rgb_threshold) - { - $count++; - if ($count >= $pixel_cutoff) - { - $cut_rect['bottom'] = $y; - break 2; - } - } - } - } - - for ($x = 0; $x <= $cut_rect['right']; $x++) - { - $count = 0; - for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) - { - $rgb = $img->getRGBAt($x, $y); - $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); - if ($diff > $rgb_threshold) - { - $count++; - if ($count >= $pixel_cutoff) - { - $cut_rect['left'] = $x; - break 2; - } - } - } - } - - for ($x = $cut_rect['right']; $x >= $cut_rect['left']; $x--) - { - $count = 0; - for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) - { - $rgb = $img->getRGBAt($x, $y); - $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); - if ($diff > $rgb_threshold) - { - $count++; - if ($count >= $pixel_cutoff) - { - $cut_rect['right'] = $x; - break 2; - } - } - } - } - - $cut_rect = array( - 'left' => $cut_rect['left'] - $margin, - 'top' => $cut_rect['top'] - $margin, - 'right' => $cut_rect['right'] + $margin, - 'bottom' => $cut_rect['bottom'] + $margin - ); - - if ($cut_rect['left'] < 0) - $cut_rect['left'] = 0; - - if ($cut_rect['top'] < 0) - $cut_rect['top'] = 0; - - if ($cut_rect['right'] >= $img->getWidth()) - $cut_rect['right'] = $img->getWidth() - 1; - - if ($cut_rect['bottom'] >= $img->getHeight()) - $cut_rect['bottom'] = $img->getHeight() - 1; - - return $img->crop($cut_rect['left'], $cut_rect['top'], $cut_rect['right'] - $cut_rect['left'] + 1, $cut_rect['bottom'] - $cut_rect['top'] + 1); - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/CopyChannelsPalette.php b/htdocs/libraries/wideimage/lib/Operation/CopyChannelsPalette.php deleted file mode 100755 index f2ad6b1f6fb0..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/CopyChannelsPalette.php +++ /dev/null @@ -1,90 +0,0 @@ - 0, 'green' => 0, 'blue' => 0); - if (isset($channels['alpha'])) - unset($channels['alpha']); - - $width = $img->getWidth(); - $height = $img->getHeight(); - $copy = WideImage_PaletteImage::create($width, $height); - - if ($img->isTransparent()) - { - $otci = $img->getTransparentColor(); - $TRGB = $img->getColorRGB($otci); - $tci = $copy->allocateColor($TRGB); - } - else - { - $otci = null; - $tci = null; - } - - for ($x = 0; $x < $width; $x++) - for ($y = 0; $y < $height; $y++) - { - $ci = $img->getColorAt($x, $y); - if ($ci === $otci) - { - $copy->setColorAt($x, $y, $tci); - continue; - } - $RGB = $img->getColorRGB($ci); - - $newRGB = $blank; - foreach ($channels as $channel) - $newRGB[$channel] = $RGB[$channel]; - - $color = $copy->getExactColor($newRGB); - if ($color == -1) - $color = $copy->allocateColor($newRGB); - - $copy->setColorAt($x, $y, $color); - } - - if ($img->isTransparent()) - $copy->setTransparentColor($tci); - - return $copy; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/CopyChannelsTrueColor.php b/htdocs/libraries/wideimage/lib/Operation/CopyChannelsTrueColor.php deleted file mode 100755 index 286841791bdd..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/CopyChannelsTrueColor.php +++ /dev/null @@ -1,67 +0,0 @@ - 0, 'green' => 0, 'blue' => 0, 'alpha' => 0); - - $width = $img->getWidth(); - $height = $img->getHeight(); - $copy = WideImage_TrueColorImage::create($width, $height); - - if (count($channels) > 0) - for ($x = 0; $x < $width; $x++) - for ($y = 0; $y < $height; $y++) - { - $RGBA = $img->getRGBAt($x, $y); - $newRGBA = $blank; - foreach ($channels as $channel) - $newRGBA[$channel] = $RGBA[$channel]; - - $color = $copy->getExactColorAlpha($newRGBA); - if ($color == -1) - $color = $copy->allocateColorAlpha($newRGBA); - - $copy->setColorAt($x, $y, $color); - } - - return $copy; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/CorrectGamma.php b/htdocs/libraries/wideimage/lib/Operation/CorrectGamma.php deleted file mode 100755 index 6ab075c1caf7..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/CorrectGamma.php +++ /dev/null @@ -1,48 +0,0 @@ -copy(); - if (!imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma)) - throw new WideImage_GDFunctionResultException("imagegammacorrect() returned false"); - - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/Crop.php b/htdocs/libraries/wideimage/lib/Operation/Crop.php deleted file mode 100755 index ef078e0ea385..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/Crop.php +++ /dev/null @@ -1,86 +0,0 @@ -getWidth(), $width); - $height = WideImage_Coordinate::fix($height, $img->getHeight(), $height); - $left = WideImage_Coordinate::fix($left, $img->getWidth(), $width); - $top = WideImage_Coordinate::fix($top, $img->getHeight(), $height); - if ($left < 0) - { - $width = $left + $width; - $left = 0; - } - - if ($width > $img->getWidth() - $left) - $width = $img->getWidth() - $left; - - if ($top < 0) - { - $height = $top + $height; - $top = 0; - } - - if ($height > $img->getHeight() - $top) - $height = $img->getHeight() - $top; - - if ($width <= 0 || $height <= 0) - throw new WideImage_Exception("Can't crop outside of an image."); - - $new = $img->doCreate($width, $height); - - if ($img->isTransparent() || $img instanceof WideImage_PaletteImage) - { - $new->copyTransparencyFrom($img); - if (!imagecopyresized($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) - throw new WideImage_GDFunctionResultException("imagecopyresized() returned false"); - } - else - { - $new->alphaBlending(false); - $new->saveAlpha(true); - if (!imagecopyresampled($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) - throw new WideImage_GDFunctionResultException("imagecopyresampled() returned false"); - } - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/Flip.php b/htdocs/libraries/wideimage/lib/Operation/Flip.php deleted file mode 100755 index 1c25b68879e5..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/Flip.php +++ /dev/null @@ -1,54 +0,0 @@ -copy(); - - $width = $image->getWidth(); - $height = $image->getHeight(); - - if ($new->isTransparent()) - imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor()); - - for ($y = 0; $y < $height; $y++) - if (!imagecopy($new->getHandle(), $image->getHandle(), 0, $y, 0, $height - $y - 1, $width, 1)) - throw new WideImage_GDFunctionResultException("imagecopy() returned false"); - - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/GetMask.php b/htdocs/libraries/wideimage/lib/Operation/GetMask.php deleted file mode 100755 index bac74628f606..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/GetMask.php +++ /dev/null @@ -1,67 +0,0 @@ -getWidth(); - $height = $image->getHeight(); - - $mask = WideImage_TrueColorImage::create($width, $height); - $mask->setTransparentColor(-1); - $mask->alphaBlending(false); - $mask->saveAlpha(false); - - for ($i = 0; $i <= 255; $i++) - $greyscale[$i] = ImageColorAllocate($mask->getHandle(), $i, $i, $i); - - imagefilledrectangle($mask->getHandle(), 0, 0, $width, $height, $greyscale[255]); - - $transparentColor = $image->getTransparentColor(); - $alphaToGreyRatio = 255 / 127; - for ($x = 0; $x < $width; $x++) - for ($y = 0; $y < $height; $y++) - { - $color = $image->getColorAt($x, $y); - if ($color == $transparentColor) - $rgba['alpha'] = 127; - else - $rgba = $image->getColorRGB($color); - imagesetpixel($mask->getHandle(), $x, $y, $greyscale[255 - round($rgba['alpha'] * $alphaToGreyRatio)]); - } - return $mask; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/Merge.php b/htdocs/libraries/wideimage/lib/Operation/Merge.php deleted file mode 100755 index ee897119b6ee..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/Merge.php +++ /dev/null @@ -1,78 +0,0 @@ -getWidth(), $overlay->getWidth()); - $y = WideImage_Coordinate::fix($top, $base->getHeight(), $overlay->getHeight()); - - $result = $base->asTrueColor(); - $result->alphaBlending(true); - $result->saveAlpha(true); - - if ($pct <= 0) - return $result; - - if ($pct < 100) - { - if (!imagecopymerge( - $result->getHandle(), - $overlay->getHandle(), - $x, $y, 0, 0, - $overlay->getWidth(), - $overlay->getHeight(), - $pct)) - throw new WideImage_GDFunctionResultException("imagecopymerge() returned false"); - } - else - { - if (!imagecopy( - $result->getHandle(), - $overlay->getHandle(), - $x, $y, 0, 0, - $overlay->getWidth(), - $overlay->getHeight())) - throw new WideImage_GDFunctionResultException("imagecopy() returned false"); - } - - return $result; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/Mirror.php b/htdocs/libraries/wideimage/lib/Operation/Mirror.php deleted file mode 100755 index 88cb658e78d7..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/Mirror.php +++ /dev/null @@ -1,55 +0,0 @@ -copy(); - - $width = $image->getWidth(); - $height = $image->getHeight(); - - if ($new->isTransparent()) - imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor()); - - for ($x = 0; $x < $width; $x++) - { - if (!imagecopy($new->getHandle(), $image->getHandle(), $x, 0, $width - $x - 1, 0, 1, $height)) - throw new WideImage_GDFunctionResultException("imagecopy() returned false"); - } - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/Resize.php b/htdocs/libraries/wideimage/lib/Operation/Resize.php deleted file mode 100755 index 7d4182e3e46c..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/Resize.php +++ /dev/null @@ -1,157 +0,0 @@ -getWidth(); - $height = $img->getHeight(); - } - - if ($width !== null) - $width = WideImage_Coordinate::fix($width, $img->getWidth()); - - if ($height !== null) - $height = WideImage_Coordinate::fix($height, $img->getHeight()); - - if ($width === null) - $width = floor($img->getWidth() * $height / $img->getHeight()); - - if ($height === null) - $height = floor($img->getHeight() * $width / $img->getWidth()); - - if ($width === 0 || $height === 0) - return array('width' => 0, 'height' => 0); - - if ($fit == null) - $fit = 'inside'; - - $dim = array(); - if ($fit == 'fill') - { - $dim['width'] = $width; - $dim['height'] = $height; - } - elseif ($fit == 'inside' || $fit == 'outside') - { - $rx = $img->getWidth() / $width; - $ry = $img->getHeight() / $height; - - if ($fit == 'inside') - $ratio = ($rx > $ry) ? $rx : $ry; - else - $ratio = ($rx < $ry) ? $rx : $ry; - - $dim['width'] = round($img->getWidth() / $ratio); - $dim['height'] = round($img->getHeight() / $ratio); - } - else - throw new WideImage_Operation_InvalidFitMethodException("{$fit} is not a valid resize-fit method."); - - return $dim; - } - - /** - * Returns a resized image - * - * @param WideImage_Image $img - * @param smart_coordinate $width - * @param smart_coordinate $height - * @param string $fit - * @param string $scale - * @return WideImage_Image - */ - function execute($img, $width, $height, $fit, $scale) - { - $dim = $this->prepareDimensions($img, $width, $height, $fit); - if (($scale === 'down' && ($dim['width'] >= $img->getWidth() && $dim['height'] >= $img->getHeight())) || - ($scale === 'up' && ($dim['width'] <= $img->getWidth() && $dim['height'] <= $img->getHeight()))) - $dim = array('width' => $img->getWidth(), 'height' => $img->getHeight()); - - if ($dim['width'] <= 0 || $dim['height'] <= 0) - throw new WideImage_Operation_InvalidResizeDimensionException("Both dimensions must be larger than 0."); - - if ($img->isTransparent() || $img instanceof WideImage_PaletteImage) - { - $new = WideImage_PaletteImage::create($dim['width'], $dim['height']); - $new->copyTransparencyFrom($img); - if (!imagecopyresized( - $new->getHandle(), - $img->getHandle(), - 0, 0, 0, 0, - $new->getWidth(), - $new->getHeight(), - $img->getWidth(), - $img->getHeight())) - throw new WideImage_GDFunctionResultException("imagecopyresized() returned false"); - } - else - { - $new = WideImage_TrueColorImage::create($dim['width'], $dim['height']); - $new->alphaBlending(false); - $new->saveAlpha(true); - if (!imagecopyresampled( - $new->getHandle(), - $img->getHandle(), - 0, 0, 0, 0, - $new->getWidth(), - $new->getHeight(), - $img->getWidth(), - $img->getHeight())) - throw new WideImage_GDFunctionResultException("imagecopyresampled() returned false"); - $new->alphaBlending(true); - } - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/ResizeCanvas.php b/htdocs/libraries/wideimage/lib/Operation/ResizeCanvas.php deleted file mode 100644 index 66682cd4c379..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/ResizeCanvas.php +++ /dev/null @@ -1,107 +0,0 @@ -getWidth()); - $new_height = WideImage_Coordinate::fix($height, $img->getHeight()); - - if ($scale == 'down') - { - $new_width = min($new_width, $img->getWidth()); - $new_height = min($new_height, $img->getHeight()); - } - elseif ($scale == 'up') - { - $new_width = max($new_width, $img->getWidth()); - $new_height = max($new_height, $img->getHeight()); - } - - $new = WideImage::createTrueColorImage($new_width, $new_height); - if ($img->isTrueColor()) - { - if ($color === null) - $color = $new->allocateColorAlpha(0, 0, 0, 127); - } - else - { - imagepalettecopy($new->getHandle(), $img->getHandle()); - - if ($img->isTransparent()) - { - $new->copyTransparencyFrom($img); - $tc_rgb = $img->getTransparentColorRGB(); - $t_color = $new->allocateColorAlpha($tc_rgb); - } - - if ($color === null) - { - if ($img->isTransparent()) - $color = $t_color; - else - $color = $new->allocateColorAlpha(255, 0, 127, 127); - - imagecolortransparent($new->getHandle(), $color); - } - } - $new->fill(0, 0, $color); - - - $x = WideImage_Coordinate::fix($left, $new->getWidth(), $img->getWidth()); - $y = WideImage_Coordinate::fix($top, $new->getHeight(), $img->getHeight()); - - // blending for truecolor images - if ($img->isTrueColor()) - $new->alphaBlending($merge); - - // not-blending for palette images - if (!$merge && !$img->isTrueColor() && isset($t_color)) - $new->getCanvas()->filledRectangle($x, $y, $x + $img->getWidth(), $y + $img->getHeight(), $t_color); - - $img->copyTo($new, $x, $y); - return $new; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/Rotate.php b/htdocs/libraries/wideimage/lib/Operation/Rotate.php deleted file mode 100755 index 7692fb451acf..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/Rotate.php +++ /dev/null @@ -1,64 +0,0 @@ -copy(); - - $image = $image->asTrueColor(); - - if ($bgColor === null) - { - $bgColor = $image->getTransparentColor(); - if ($bgColor == -1) - { - $bgColor = $image->allocateColorAlpha(255, 255, 255, 127); - imagecolortransparent($image->getHandle(), $bgColor); - } - } - return new WideImage_TrueColorImage(imagerotate($image->getHandle(), $angle, $bgColor, $ignoreTransparent)); - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/RoundCorners.php b/htdocs/libraries/wideimage/lib/Operation/RoundCorners.php deleted file mode 100644 index 22eb84991b62..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/RoundCorners.php +++ /dev/null @@ -1,114 +0,0 @@ - 16) - $sample_ratio = 16; - else - $sample_ratio = $smoothness; - - $corner = WideImage::createTrueColorImage($radius * $sample_ratio, $radius * $sample_ratio); - if ($color === null) - { - imagepalettecopy($corner->getHandle(), $image->getHandle()); - $bg_color = $corner->allocateColor(0, 0, 0); - - $corner->fill(0, 0, $bg_color); - $fg_color = $corner->allocateColor(255, 255, 255); - $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color); - $corner = $corner->resize($radius, $radius); - - $result = $image->asTrueColor(); - - $tc = $result->getTransparentColor(); - if ($tc == -1) - { - $tc = $result->allocateColorAlpha(255, 255, 255, 127); - imagecolortransparent($result->getHandle(), $tc); - $result->setTransparentColor($tc); - } - - if ($corners & WideImage::SIDE_TOP_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_TOP) - $result = $result->applyMask($corner, -1, -1); - - $corner = $corner->rotate(90); - if ($corners & WideImage::SIDE_TOP_RIGHT || $corners & WideImage::SIDE_TOP || $corners & WideImage::SIDE_RIGHT) - $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100); - - $corner = $corner->rotate(90); - if ($corners & WideImage::SIDE_BOTTOM_RIGHT || $corners & WideImage::SIDE_RIGHT || $corners & WideImage::SIDE_BOTTOM) - $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100); - - $corner = $corner->rotate(90); - if ($corners & WideImage::SIDE_BOTTOM_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_BOTTOM) - $result = $result->applyMask($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100); - - return $result; - } - else - { - $bg_color = $color; - - $corner->fill(0, 0, $bg_color); - $fg_color = $corner->allocateColorAlpha(127, 127, 127, 127); - $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color); - $corner = $corner->resize($radius, $radius); - - $result = $image->copy(); - if ($corners & WideImage::SIDE_TOP_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_TOP) - $result = $result->merge($corner, -1, -1, 100); - - $corner = $corner->rotate(90); - if ($corners & WideImage::SIDE_TOP_RIGHT || $corners & WideImage::SIDE_TOP || $corners & WideImage::SIDE_RIGHT) - $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100); - - $corner = $corner->rotate(90); - if ($corners & WideImage::SIDE_BOTTOM_RIGHT || $corners & WideImage::SIDE_RIGHT || $corners & WideImage::SIDE_BOTTOM) - $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100); - - $corner = $corner->rotate(90); - if ($corners & WideImage::SIDE_BOTTOM_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_BOTTOM) - $result = $result->merge($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100); - - return $result; - } - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/Unsharp.php b/htdocs/libraries/wideimage/lib/Operation/Unsharp.php deleted file mode 100755 index 9ba68825e815..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/Unsharp.php +++ /dev/null @@ -1,135 +0,0 @@ - 500) $amount = 500; - $amount = $amount * 0.016; - if ($radius > 50) $radius = 50; - $radius = $radius * 2; - if ($threshold > 255) $threshold = 255; - - $radius = abs(round($radius)); // Only integers make sense. - if ($radius == 0) { - return $image; - } - - // Gaussian blur matrix - - $matrix = array( - array(1, 2, 1), - array(2, 4, 2), - array(1, 2, 1) - ); - - $blurred = $image->applyConvolution($matrix, 16, 0); - - if($threshold > 0) { - // Calculate the difference between the blurred pixels and the original - // and set the pixels - for ($x = 0; $x < $image->getWidth(); $x++) { - for ($y = 0; $y < $image->getHeight(); $y++) { - $rgbOrig = $image->getRGBAt($x, $y); - $rOrig = $rgbOrig["red"]; - $gOrig = $rgbOrig["green"]; - $bOrig = $rgbOrig["blue"]; - - $rgbBlur = $blurred->getRGBAt($x, $y); - $rBlur = $rgbBlur["red"]; - $gBlur = $rgbBlur["green"]; - $bBlur = $rgbBlur["blue"]; - - // When the masked pixels differ less from the original - // than the threshold specifies, they are set to their original value. - $rNew = (abs($rOrig - $rBlur) >= $threshold) - ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) - : $rOrig; - $gNew = (abs($gOrig - $gBlur) >= $threshold) - ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) - : $gOrig; - $bNew = (abs($bOrig - $bBlur) >= $threshold) - ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) - : $bOrig; - $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); - - if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) { - $image->setRGBAt($x, $y, $rgbNew); - } - } - } - } - else { - $w = $image->getWidth(); - $h = $image->getHeight(); - for ($x = 0; $x < $w; $x++) { - for ($y = 0; $y < $h; $y++) { - $rgbOrig = $image->getRGBAt($x, $y); - $rOrig = $rgbOrig["red"]; - $gOrig = $rgbOrig["green"]; - $bOrig = $rgbOrig["blue"]; - - $rgbBlur = $blurred->getRGBAt($x, $y); - $rBlur = $rgbBlur["red"]; - $gBlur = $rgbBlur["green"]; - $bBlur = $rgbBlur["blue"]; - - $rNew = ($amount * ($rOrig - $rBlur)) + $rOrig; - if($rNew>255){$rNew=255;} - elseif($rNew<0){$rNew=0;} - $gNew = ($amount * ($gOrig - $gBlur)) + $gOrig; - if($gNew>255){$gNew=255;} - elseif($gNew<0){$gNew=0;} - $bNew = ($amount * ($bOrig - $bBlur)) + $bOrig; - if($bNew>255){$bNew=255;} - elseif($bNew<0){$bNew=0;} - $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); - - $image->setRGBAt($x, $y, $rgbNew); - } - } - } - - return $image; - } - } diff --git a/htdocs/libraries/wideimage/lib/Operation/index.html b/htdocs/libraries/wideimage/lib/Operation/index.html deleted file mode 100644 index 74b6f45c8f33..000000000000 --- a/htdocs/libraries/wideimage/lib/Operation/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/OperationFactory.php b/htdocs/libraries/wideimage/lib/OperationFactory.php deleted file mode 100755 index cc1183af0887..000000000000 --- a/htdocs/libraries/wideimage/lib/OperationFactory.php +++ /dev/null @@ -1,57 +0,0 @@ -copy(); - } - - /** - * Returns a copy of the image - * - * @param $trueColor True if the new image should be truecolor - * @return WideImage_Image - */ - protected function copyAsNew($trueColor = false) - { - $width = $this->getWidth(); - $height = $this->getHeight(); - - if ($trueColor) - $new = WideImage_TrueColorImage::create($width, $height); - else - $new = WideImage_PaletteImage::create($width, $height); - - // copy transparency of source to target - if ($this->isTransparent()) - { - $rgb = $this->getTransparentColorRGB(); - if (is_array($rgb)) - { - $tci = $new->allocateColor($rgb['red'], $rgb['green'], $rgb['blue']); - $new->fill(0, 0, $tci); - $new->setTransparentColor($tci); - } - } - - imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height); - return $new; - } - - /** - * (non-PHPdoc) - * @see WideImage_Image#asTrueColor() - */ - function asTrueColor() - { - $width = $this->getWidth(); - $height = $this->getHeight(); - $new = WideImage::createTrueColorImage($width, $height); - if ($this->isTransparent()) - $new->copyTransparencyFrom($this); - if (!imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height)) - throw new WideImage_GDFunctionResultException("imagecopy() returned false"); - return $new; - } - - /** - * (non-PHPdoc) - * @see WideImage_Image#getChannels() - */ - function getChannels() - { - $args = func_get_args(); - if (count($args) == 1 && is_array($args[0])) - $args = $args[0]; - return WideImage_OperationFactory::get('CopyChannelsPalette')->execute($this, $args); - } - - /** - * (non-PHPdoc) - * @see WideImage_Image#copyNoAlpha() - */ - function copyNoAlpha() - { - return WideImage_Image::loadFromString($this->asString('png')); - } - } diff --git a/htdocs/libraries/wideimage/lib/README b/htdocs/libraries/wideimage/lib/README deleted file mode 100644 index 7b265312db26..000000000000 --- a/htdocs/libraries/wideimage/lib/README +++ /dev/null @@ -1,21 +0,0 @@ -WideImage, a PHP image manipulation library -Copyright 2007-2011 Gasper Kozak - -For documentation, please visit http://wideimage.sourceforge.net/ - - - 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 diff --git a/htdocs/libraries/wideimage/lib/TrueColorImage.php b/htdocs/libraries/wideimage/lib/TrueColorImage.php deleted file mode 100755 index 28ca5a001490..000000000000 --- a/htdocs/libraries/wideimage/lib/TrueColorImage.php +++ /dev/null @@ -1,218 +0,0 @@ -alphaBlending(false); - $this->saveAlpha(true); - } - - /** - * Factory method that creates a true-color image object - * - * @param int $width - * @param int $height - * @return WideImage_TrueColorImage - */ - static function create($width, $height) - { - if ($width * $height <= 0 || $width < 0) - throw new WideImage_InvalidImageDimensionException("Can't create an image with dimensions [$width, $height]."); - - return new WideImage_TrueColorImage(imagecreatetruecolor($width, $height)); - } - - function doCreate($width, $height) - { - return self::create($width, $height); - } - - function isTrueColor() - { - return true; - } - - /** - * Sets alpha blending mode via imagealphablending() - * - * @param bool $mode - * @return bool - */ - function alphaBlending($mode) - { - return imagealphablending($this->handle, $mode); - } - - /** - * Toggle if alpha channel should be saved with the image via imagesavealpha() - * - * @param bool $on - * @return bool - */ - function saveAlpha($on) - { - return imagesavealpha($this->handle, $on); - } - - /** - * Allocates a color and returns its index - * - * This method accepts either each component as an integer value, - * or an associative array that holds the color's components in keys - * 'red', 'green', 'blue', 'alpha'. - * - * @param mixed $R - * @param int $G - * @param int $B - * @param int $A - * @return int - */ - function allocateColorAlpha($R, $G = null, $B = null, $A = null) - { - if (is_array($R)) - return imageColorAllocateAlpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']); - else - return imageColorAllocateAlpha($this->handle, $R, $G, $B, $A); - } - - /** - * @see WideImage_Image#asPalette($nColors, $dither, $matchPalette) - */ - function asPalette($nColors = 255, $dither = null, $matchPalette = true) - { - $nColors = intval($nColors); - if ($nColors < 1) - $nColors = 1; - elseif ($nColors > 255) - $nColors = 255; - - if ($dither === null) - $dither = $this->isTransparent(); - - $temp = $this->copy(); - imagetruecolortopalette($temp->handle, $dither, $nColors); - if ($matchPalette == true && function_exists('imagecolormatch')) - imagecolormatch($this->handle, $temp->handle); - - // The code below isn't working properly; it corrupts transparency on some palette->tc->palette conversions. - // Why is this code here? - /* - if ($this->isTransparent()) - { - $trgb = $this->getTransparentColorRGB(); - $tci = $temp->getClosestColor($trgb); - $temp->setTransparentColor($tci); - } - /**/ - - $temp->releaseHandle(); - return new WideImage_PaletteImage($temp->handle); - } - - /** - * Returns the index of the color that best match the given color components - * - * This method accepts either each component as an integer value, - * or an associative array that holds the color's components in keys - * 'red', 'green', 'blue', 'alpha'. - * - * @param mixed $R Red component value or an associative array - * @param int $G Green component - * @param int $B Blue component - * @param int $A Alpha component - * @return int The color index - */ - function getClosestColorAlpha($R, $G = null, $B = null, $A = null) - { - if (is_array($R)) - return imagecolorclosestalpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']); - else - return imagecolorclosestalpha($this->handle, $R, $G, $B, $A); - } - - /** - * Returns the index of the color that exactly match the given color components - * - * This method accepts either each component as an integer value, - * or an associative array that holds the color's components in keys - * 'red', 'green', 'blue', 'alpha'. - * - * @param mixed $R Red component value or an associative array - * @param int $G Green component - * @param int $B Blue component - * @param int $A Alpha component - * @return int The color index - */ - function getExactColorAlpha($R, $G = null, $B = null, $A = null) - { - if (is_array($R)) - return imagecolorexactalpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']); - else - return imagecolorexactalpha($this->handle, $R, $G, $B, $A); - } - - /** - * @see WideImage_Image#getChannels() - */ - function getChannels() - { - $args = func_get_args(); - if (count($args) == 1 && is_array($args[0])) - $args = $args[0]; - return WideImage_OperationFactory::get('CopyChannelsTrueColor')->execute($this, $args); - } - - /** - * (non-PHPdoc) - * @see WideImage_Image#copyNoAlpha() - */ - function copyNoAlpha() - { - $prev = $this->saveAlpha(false); - $result = WideImage_Image::loadFromString($this->asString('png')); - $this->saveAlpha($prev); - //$result->releaseHandle(); - return $result; - } - - /** - * (non-PHPdoc) - * @see WideImage_Image#asTrueColor() - */ - function asTrueColor() - { - return $this->copy(); - } - } diff --git a/htdocs/libraries/wideimage/lib/VERSION b/htdocs/libraries/wideimage/lib/VERSION deleted file mode 100644 index d344316bbe4e..000000000000 --- a/htdocs/libraries/wideimage/lib/VERSION +++ /dev/null @@ -1,2 +0,0 @@ -Version: 11.02.19 -Build date: 2011-02-19 diff --git a/htdocs/libraries/wideimage/lib/WideImage.php b/htdocs/libraries/wideimage/lib/WideImage.php deleted file mode 100755 index 290468bfb401..000000000000 --- a/htdocs/libraries/wideimage/lib/WideImage.php +++ /dev/null @@ -1,377 +0,0 @@ - - * WideImage::registerCustomMapper('WideImage_Mapper_TGA', 'image/tga', 'tga'); - * - * - * @param string $mapper_class_name - * @param string $mime_type - * @param string $extension - */ - static function registerCustomMapper($mapper_class_name, $mime_type, $extension) - { - WideImage_MapperFactory::registerMapper($mapper_class_name, $mime_type, strtoupper($extension)); - } - - /** - * Loads an image from a file, URL, HTML input file field, binary string, or a valid image handle. - * The image format is auto-detected. - * - * Currently supported formats: PNG, GIF, JPG, BMP, TGA, GD, GD2. - * - * This function analyzes the input and decides whether to use WideImage::loadFromHandle(), - * WideImage::loadFromFile(), WideImage::loadFromUpload() or WideImage::loadFromString(), - * all of which you can also call directly to spare WideImage some guessing. - * - * Arrays are supported for upload fields; it returns an array of loaded images. - * To load only a single image from an array field, use WideImage::loadFromUpload('img', $i), - * where $i is the index of the image you want to load. - * - * - * $img = WideImage::load('http://url/image.png'); // image URL - * $img = WideImage::load('/path/to/image.png'); // local file path - * $img = WideImage::load('img'); // upload field name - * $img = WideImage::load(imagecreatetruecolor(10, 10)); // a GD resource - * $img = WideImage::load($image_data); // binary string containing image data - * - * - * @param mixed $source File name, url, HTML file input field name, binary string, or a GD image resource - * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance - */ - static function load($source) - { - $predictedSourceType = ''; - - if ($source == '') - $predictedSourceType = 'String'; - - // Creating image via a valid resource - if (!$predictedSourceType && self::isValidImageHandle($source)) - $predictedSourceType = 'Handle'; - - // Check for binary string - if (!$predictedSourceType) - { - // search first $binLength bytes (at a maximum) for ord<32 characters (binary image data) - $binLength = 64; - $sourceLength = strlen($source); - $maxlen = ($sourceLength > $binLength) ? $binLength : $sourceLength; - for ($i = 0; $i < $maxlen; $i++) - if (ord($source[$i]) < 32) - { - $predictedSourceType = 'String'; - break; - } - } - - // Uploaded image (array uploads not supported) - if (isset($_FILES[$source]) && isset($_FILES[$source]['tmp_name'])) - $predictedSourceType = 'Upload'; - - // Otherwise, must be a file or an URL - if (!$predictedSourceType) - $predictedSourceType = 'File'; - - return call_user_func(array('WideImage', 'loadFrom' . $predictedSourceType), $source); - } - - /** - * Create and load an image from a file or URL. The image format is auto-detected. - * - * @param string $uri File or url - * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance - */ - static function loadFromFile($uri) - { - $data = file_get_contents($uri); - $handle = @imagecreatefromstring($data); - if (!self::isValidImageHandle($handle)) - { - try - { - // try to find a mapper first - $mapper = WideImage_MapperFactory::selectMapper($uri); - if ($mapper) - $handle = $mapper->load($uri); - } - catch (WideImage_UnsupportedFormatException $e) - { - // mapper not found - } - - // try all custom mappers - if (!self::isValidImageHandle($handle)) - { - $custom_mappers = WideImage_MapperFactory::getCustomMappers(); - foreach ($custom_mappers as $mime_type => $mapper_class) - { - $mapper = WideImage_MapperFactory::selectMapper(null, $mime_type); - $handle = $mapper->loadFromString($data); - if (self::isValidImageHandle($handle)) - break; - } - } - } - - if (!self::isValidImageHandle($handle)) - throw new WideImage_InvalidImageSourceException("File '{$uri}' appears to be an invalid image source."); - - return self::loadFromHandle($handle); - } - - /** - * Create and load an image from a string. Format is auto-detected. - * - * @param string $string Binary data, i.e. from BLOB field in the database - * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance - */ - static function loadFromString($string) - { - if (strlen($string) < 128) - throw new WideImage_InvalidImageSourceException("String doesn't contain image data."); - - $handle = @imagecreatefromstring($string); - if (!self::isValidImageHandle($handle)) - { - $custom_mappers = WideImage_MapperFactory::getCustomMappers(); - foreach ($custom_mappers as $mime_type => $mapper_class) - { - $mapper = WideImage_MapperFactory::selectMapper(null, $mime_type); - $handle = $mapper->loadFromString($string); - if (self::isValidImageHandle($handle)) - break; - } - } - - if (!self::isValidImageHandle($handle)) - throw new WideImage_InvalidImageSourceException("String doesn't contain valid image data."); - - return self::loadFromHandle($handle); - } - - /** - * Create and load an image from an image handle. - * - * Note: the resulting image object takes ownership of the passed - * handle. When the newly-created image object is destroyed, the handle is - * destroyed too, so it's not a valid image handle anymore. In order to - * preserve the handle for use after object destruction, you have to call - * WideImage_Image::releaseHandle() on the created image instance prior to its - * destruction. - * - * - * $handle = imagecreatefrompng('file.png'); - * $image = WideImage::loadFromHandle($handle); - * - * - * @param resource $handle A valid GD image resource - * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance - */ - static function loadFromHandle($handle) - { - if (!self::isValidImageHandle($handle)) - throw new WideImage_InvalidImageSourceException("Handle is not a valid GD image resource."); - - if (imageistruecolor($handle)) - return new WideImage_TrueColorImage($handle); - else - return new WideImage_PaletteImage($handle); - } - - /** - * This method loads a file from the $_FILES array. The image format is auto-detected. - * - * You only have to pass the field name as the parameter. For array fields, this function will - * return an array of image objects, unless you specify the $index parameter, which will - * load the desired image. - * - * @param $field_name Name of the key in $_FILES array - * @param int $index The index of the file to load (if the input field is an array) - * @return WideImage_Image The loaded image - */ - static function loadFromUpload($field_name, $index = null) - { - if (!array_key_exists($field_name, $_FILES)) - throw new WideImage_InvalidImageSourceException("Upload field '{$field_name}' doesn't exist."); - - if (is_array($_FILES[$field_name]['tmp_name'])) - { - if (isset($_FILES[$field_name]['tmp_name'][$index])) - $filename = $_FILES[$field_name]['tmp_name'][$index]; - else - { - $result = array(); - foreach ($_FILES[$field_name]['tmp_name'] as $idx => $tmp_name) - $result[$idx] = self::loadFromFile($tmp_name); - return $result; - } - } - else - $filename = $_FILES[$field_name]['tmp_name']; - - if (!file_exists($filename)) - throw new WideImage_InvalidImageSourceException("Uploaded file doesn't exist."); - return self::loadFromFile($filename); - } - - /** - * Factory method for creating a palette image - * - * @param int $width - * @param int $height - * @return WideImage_PaletteImage - */ - static function createPaletteImage($width, $height) - { - return WideImage_PaletteImage::create($width, $height); - } - - /** - * Factory method for creating a true-color image - * - * @param int $width - * @param int $height - * @return WideImage_TrueColorImage - */ - static function createTrueColorImage($width, $height) - { - return WideImage_TrueColorImage::create($width, $height); - } - - /** - * Check whether the given handle is a valid GD resource - * - * @param mixed $handle The variable to check - * @return bool - */ - static function isValidImageHandle($handle) - { - return (is_resource($handle) && get_resource_type($handle) == 'gd'); - } - - /** - * Throws exception if the handle isn't a valid GD resource - * - * @param mixed $handle The variable to check - */ - static function assertValidImageHandle($handle) - { - if (!self::isValidImageHandle($handle)) - throw new WideImage_InvalidImageHandleException("{$handle} is not a valid image handle."); - } - } - - WideImage::checkGD(); - - WideImage::registerCustomMapper('WideImage_Mapper_BMP', 'image/bmp', 'bmp'); - WideImage::registerCustomMapper('WideImage_Mapper_TGA', 'image/tga', 'tga'); - \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/gpl.txt b/htdocs/libraries/wideimage/lib/gpl.txt deleted file mode 100644 index 82fa1daad468..000000000000 --- a/htdocs/libraries/wideimage/lib/gpl.txt +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/htdocs/libraries/wideimage/lib/index.html b/htdocs/libraries/wideimage/lib/index.html deleted file mode 100644 index 990cbd60372e..000000000000 --- a/htdocs/libraries/wideimage/lib/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/lgpl.txt b/htdocs/libraries/wideimage/lib/lgpl.txt deleted file mode 100644 index 5ab7695ab8ca..000000000000 --- a/htdocs/libraries/wideimage/lib/lgpl.txt +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/htdocs/libraries/wideimage/lib/vendor/JPEXS/bmp.php b/htdocs/libraries/wideimage/lib/vendor/JPEXS/bmp.php deleted file mode 100755 index 4fd506c46c93..000000000000 --- a/htdocs/libraries/wideimage/lib/vendor/JPEXS/bmp.php +++ /dev/null @@ -1,537 +0,0 @@ -0)and($ColorCount<=2)) {$ColorCount=2; $BitCount=1;}; - if(($ColorCount>2)and($ColorCount<=16)) { $ColorCount=16; $BitCount=4;}; - if(($ColorCount>16)and($ColorCount<=256)) { $ColorCount=0; $BitCount=8;}; - - $Width=imagesx($img); - $Height=imagesy($img); - - $Zbytek=(4-($Width/(8/$BitCount))%4)%4; - - if($BitCount<24) $palsize=pow(2,$BitCount)*4; - - $size=(floor($Width/(8/$BitCount))+$Zbytek)*$Height+54; - $size+=$palsize; - $offset=54+$palsize; - - // Bitmap File Header - $ret = 'BM'; // header (2b) - $ret .= jpexs_int_to_dword($size); // size of file (4b) - $ret .= jpexs_int_to_dword(0); // reserved (4b) - $ret .= jpexs_int_to_dword($offset); // byte location in the file which is first byte of IMAGE (4b) - // Bitmap Info Header - $ret .= jpexs_int_to_dword(40); // Size of BITMAPINFOHEADER (4b) - $ret .= jpexs_int_to_dword($Width); // width of bitmap (4b) - $ret .= jpexs_int_to_dword($Height); // height of bitmap (4b) - $ret .= jpexs_int_to_word(1); // biPlanes = 1 (2b) - $ret .= jpexs_int_to_word($BitCount); // biBitCount = {1 (mono) or 4 (16 clr ) or 8 (256 clr) or 24 (16 Mil)} (2b) - $ret .= jpexs_int_to_dword($useRLE); // RLE COMPRESSION (4b) - $ret .= jpexs_int_to_dword(0); // width x height (4b) - $ret .= jpexs_int_to_dword(0); // biXPelsPerMeter (4b) - $ret .= jpexs_int_to_dword(0); // biYPelsPerMeter (4b) - $ret .= jpexs_int_to_dword(0); // Number of palettes used (4b) - $ret .= jpexs_int_to_dword(0); // Number of important colour (4b) - // image data - - $retd = ""; - - $CC=$ColorCount; - $sl1=strlen($ret); - if($CC==0) $CC=256; - if($BitCount<24) - { - $ColorTotal=imagecolorstotal($img); - if($IsTransparent) $ColorTotal--; - - for($p=0;$p<$ColorTotal;$p++) - { - $color=imagecolorsforindex($img,$p); - $ret.=jpexs_inttobyte($color["blue"]); - $ret.=jpexs_inttobyte($color["green"]); - $ret.=jpexs_inttobyte($color["red"]); - $ret.=jpexs_inttobyte(0); //RESERVED - }; - - $CT=$ColorTotal; - for($p=$ColorTotal;$p<$CC;$p++) - { - $ret.=jpexs_inttobyte(0); - $ret.=jpexs_inttobyte(0); - $ret.=jpexs_inttobyte(0); - $ret.=jpexs_inttobyte(0); //RESERVED - }; - }; - - - if($BitCount<=8) - { - - for($y=$Height-1;$y>=0;$y--) - { - $bWrite=""; - for($x=0;$x<$Width;$x++) - { - $color=imagecolorat($img,$x,$y); - $bWrite.=jpexs_decbinx($color,$BitCount); - if(strlen($bWrite)==8) - { - $retd.=jpexs_inttobyte(bindec($bWrite)); - $bWrite=""; - }; - }; - - if((strlen($bWrite)<8)and(strlen($bWrite)!=0)) - { - $sl=strlen($bWrite); - for($t=0;$t<8-$sl;$t++) - $sl.="0"; - $retd.=jpexs_inttobyte(bindec($bWrite)); - }; - for($z=0;$z<$Zbytek;$z++) - $retd.=jpexs_inttobyte(0); - }; - }; - - if(($useRLE)and($BitCount==8)) - { - for($t=0;$t=0;$y--) - { - for($x=0;$x<$Width;$x++) - { - $color=imagecolorsforindex($img,ImageColorAt($img,$x,$y)); - $ret.=chr($color["blue"]).chr($color["green"]).chr($color["red"]); - } - $ret.=$Dopl; - }; - - }; - - if($file!="") - { - $r=($f=fopen($file,"w")); - $r=$r and fwrite($f,$ret); - $r=$r and fclose($f); - return $r; - } - else - { - echo $ret; - }; -}; - - -/** - * Reads image from a BMP file and converts it to image resource - * @global int $jpexs_CurrentBit Internal variable - * @param string $file File to read BMP image from - * @return resource Image resource or false on error - * - * Note: - * Reading RLE compressed bitmaps is EXPERIMENTAL - * Reading palette based bitmaps with less than 8bit palette is EXPERIMENTAL - */ -function imagecreatefrombmp($file) -{ - global $jpexs_CurrentBit; - - $f=fopen($file,"r"); - $Header=fread($f,2); - - if($Header=="BM") - { - $Size=jpexs_freaddword($f); - $Reserved1=jpexs_freadword($f); - $Reserved2=jpexs_freadword($f); - $FirstByteOfImage=jpexs_freaddword($f); - - $SizeBITMAPINFOHEADER=jpexs_freaddword($f); - $Width=jpexs_freaddword($f); - $Height=jpexs_freaddword($f); - $biPlanes=jpexs_freadword($f); - $biBitCount=jpexs_freadword($f); - $RLECompression=jpexs_freaddword($f); - $WidthxHeight=jpexs_freaddword($f); - $biXPelsPerMeter=jpexs_freaddword($f); - $biYPelsPerMeter=jpexs_freaddword($f); - $NumberOfPalettesUsed=jpexs_freaddword($f); - $NumberOfImportantColors=jpexs_freaddword($f); - - if($biBitCount<24) - { - $img=imagecreate($Width,$Height); - $Colors=pow(2,$biBitCount); - for($p=0;$p<$Colors;$p++) - { - $B=jpexs_freadbyte($f); - $G=jpexs_freadbyte($f); - $R=jpexs_freadbyte($f); - $Reserved=jpexs_freadbyte($f); - $Palette[]=imagecolorallocate($img,$R,$G,$B); - }; - - - - - if($RLECompression==0) - { - $Zbytek=(4-ceil(($Width/(8/$biBitCount)))%4)%4; - - for($y=$Height-1;$y>=0;$y--) - { - $jpexs_CurrentBit=0; - for($x=0;$x<$Width;$x++) - { - $C=jpexs_freadbits($f,$biBitCount); - imagesetpixel($img,$x,$y,$Palette[$C]); - }; - if($jpexs_CurrentBit!=0) {jpexs_freadbyte($f);}; - for($g=0;$g<$Zbytek;$g++) - jpexs_freadbyte($f); - }; - - }; - }; - - - if($RLECompression==1) //$BI_RLE8 - { - $y=$Height; - - $pocetb=0; - - while(true) - { - $y--; - $prefix=jpexs_freadbyte($f); - $suffix=jpexs_freadbyte($f); - $pocetb+=2; - - $echoit=false; - - if($echoit)echo "Prefix: $prefix Suffix: $suffix
"; - if(($prefix==0)and($suffix==1)) break; - if(feof($f)) break; - - while(!(($prefix==0)and($suffix==0))) - { - if($prefix==0) - { - $pocet=$suffix; - $Data.=fread($f,$pocet); - $pocetb+=$pocet; - if($pocetb%2==1) {jpexs_freadbyte($f); $pocetb++;}; - }; - if($prefix>0) - { - $pocet=$prefix; - for($r=0;$r<$pocet;$r++) - $Data.=chr($suffix); - }; - $prefix=jpexs_freadbyte($f); - $suffix=jpexs_freadbyte($f); - $pocetb+=2; - if($echoit) echo "Prefix: $prefix Suffix: $suffix
"; - }; - - for($x=0;$x";*/ - while(true) - { - //break; - $y--; - $prefix=jpexs_freadbyte($f); - $suffix=jpexs_freadbyte($f); - $pocetb+=2; - - $echoit=false; - - if($echoit)echo "Prefix: $prefix Suffix: $suffix
"; - if(($prefix==0)and($suffix==1)) break; - if(feof($f)) break; - - while(!(($prefix==0)and($suffix==0))) - { - if($prefix==0) - { - $pocet=$suffix; - - $jpexs_CurrentBit=0; - for($h=0;$h<$pocet;$h++) - $Data.=chr(jpexs_freadbits($f,4)); - if($jpexs_CurrentBit!=0) jpexs_freadbits($f,4); - $pocetb+=ceil(($pocet/2)); - if($pocetb%2==1) {jpexs_freadbyte($f); $pocetb++;}; - }; - if($prefix>0) - { - $pocet=$prefix; - $i=0; - for($r=0;$r<$pocet;$r++) - { - if($i%2==0) - { - $Data.=chr($suffix%16); - } - else - { - $Data.=chr(floor($suffix/16)); - }; - $i++; - }; - }; - $prefix=jpexs_freadbyte($f); - $suffix=jpexs_freadbyte($f); - $pocetb+=2; - if($echoit) echo "Prefix: $prefix Suffix: $suffix
"; - }; - - for($x=0;$x=0;$y--) - { - for($x=0;$x<$Width;$x++) - { - $B=jpexs_freadbyte($f); - $G=jpexs_freadbyte($f); - $R=jpexs_freadbyte($f); - $color=imagecolorexact($img,$R,$G,$B); - if($color==-1) $color=imagecolorallocate($img,$R,$G,$B); - imagesetpixel($img,$x,$y,$color); - } - for($z=0;$z<$Zbytek;$z++) - jpexs_freadbyte($f); - }; - }; - return $img; - - } - else{ - return false; - } - - - fclose($f); - - -}; - - - - - -/* - * Internal functions: - *------------------------- - * - * jpexs_freadbyte($file) - reads 1 byte from $file - * jpexs_freadword($file) - reads 2 bytes (1 word) from $file - * jpexs_freaddword($file) - reads 4 bytes (1 dword) from $file - * jpexs_freadlngint($file) - same as freaddword($file) - * jpexs_decbin8($d) - returns binary string of d zero filled to 8 - * jpexs_retBits($byte,$start,$len) - returns bits $start->$start+$len from $byte - * jpexs_freadbits($file,$count) - reads next $count bits from $file - * jpexs_int_to_dword($n) - returns 4 byte representation of $n - * jpexs_int_to_word($n) - returns 2 byte representation of $n - */ - -function jpexs_freadbyte($f) -{ - return ord(fread($f,1)); -}; - -function jpexs_freadword($f) -{ - $b1=jpexs_freadbyte($f); - $b2=jpexs_freadbyte($f); - return $b2*256+$b1; -}; - - -function jpexs_freadlngint($f) -{ - return jpexs_freaddword($f); -}; - -function jpexs_freaddword($f) -{ - $b1=jpexs_freadword($f); - $b2=jpexs_freadword($f); - return $b2*65536+$b1; -}; - - - -function jpexs_retBits($byte,$start,$len) -{ - $bin=jpexs_decbin8($byte); - $r=bindec(substr($bin,$start,$len)); - return $r; - -}; - - - -$jpexs_CurrentBit=0; -function jpexs_freadbits($f,$count) -{ - global $jpexs_CurrentBit,$SMode; - $Byte=jpexs_freadbyte($f); - $LastCBit=$jpexs_CurrentBit; - $jpexs_CurrentBit+=$count; - if($jpexs_CurrentBit==8) - { - $jpexs_CurrentBit=0; - } - else - { - fseek($f,ftell($f)-1); - }; - return jpexs_retBits($Byte,$LastCBit,$count); -}; - - - -function jpexs_int_to_dword($n) -{ - return chr($n & 255).chr(($n >> 8) & 255).chr(($n >> 16) & 255).chr(($n >> 24) & 255); -} -function jpexs_int_to_word($n) -{ - return chr($n & 255).chr(($n >> 8) & 255); -} - - -function jpexs_decbin8($d) -{ - return jpexs_decbinx($d,8); -}; - -function jpexs_decbinx($d,$n) -{ - $bin=decbin($d); - $sbin=strlen($bin); - for($j=0;$j<$n-$sbin;$j++) - $bin="0$bin"; - return $bin; -}; - -function jpexs_inttobyte($n) -{ - return chr($n); -}; - -?> \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/vendor/JPEXS/ico.php b/htdocs/libraries/wideimage/lib/vendor/JPEXS/ico.php deleted file mode 100755 index 1f9bd044a318..000000000000 --- a/htdocs/libraries/wideimage/lib/vendor/JPEXS/ico.php +++ /dev/null @@ -1,965 +0,0 @@ -=$Ikona[$ColMax]["NumberOfColors"])) -if(($icoSize==$Ikona[$p]["Width"])or($icoSize==ICO_MAX_SIZE)) - { - $ColMax=$p; - }; - -if(($SizeMax==-1)or($Ikona[$p]["Width"]>=$Ikona[$SizeMax]["Width"])) -if(($icoColorCount==$Ikona[$p]["NumberOfColors"])or($icoColorCount==ICO_MAX_COLOR)) - { - $SizeMax=$p; - }; - - -if($Ikona[$p]["NumberOfColors"]==$icoColorCount) -if($Ikona[$p]["Width"]==$icoSize) - { - - $IconID=$p; - }; -}; - - if($icoColorCount==ICO_MAX_COLOR) $IconID=$ColMax; - if($icoSize==ICO_MAX_SIZE) $IconID=$SizeMax; - -$ColName=$icoColorCount; - -if($icoSize==ICO_MAX_SIZE) $icoSize="Max"; -if($ColName==ICO_TRUE_COLOR) $ColName="True"; -if($ColName==ICO_XP_COLOR) $ColName="XP"; -if($ColName==ICO_MAX_COLOR) $ColName="Max"; -if($IconID==-1) die("Icon with $ColName colors and $icoSize x $icoSize size doesn't exist in this file!"); - - -jpexs_readIcon($filename,$IconID,$Ikona); - - $biBitCount=$Ikona[$IconID]["Info"]["BitsPerPixel"]; - - - if($Ikona[$IconID]["Info"]["BitsPerPixel"]==0) - { - $Ikona[$IconID]["Info"]["BitsPerPixel"]=24; - }; - - $biBitCount=$Ikona[$IconID]["Info"]["BitsPerPixel"]; - if($biBitCount==0) $biBitCount=1; - - -$Ikona[$IconID]["BitCount"]=$Ikona[$IconID]["Info"]["BitsPerPixel"]; - - - -if($Ikona[$IconID]["BitCount"]>=24) -{ -$img=imagecreatetruecolor($Ikona[$IconID]["Width"],$Ikona[$IconID]["Height"]); -if($Ikona[$IconID]["BitCount"]==32): - $backcolor=imagecolorallocate($img,$alphaBgR,$alphaBgG,$alphaBgB); - imagefilledrectangle($img,0,0,$Ikona[$IconID]["Width"]-1,$Ikona[$IconID]["Height"]-1,$backcolor); -endif; -for($y=0;$y<$Ikona[$IconID]["Height"];$y++) -for($x=0;$x<$Ikona[$IconID]["Width"];$x++) - { - $R=$Ikona[$IconID]["Data"][$x][$y]["r"]; - $G=$Ikona[$IconID]["Data"][$x][$y]["g"]; - $B=$Ikona[$IconID]["Data"][$x][$y]["b"]; - if($Ikona[$IconID]["BitCount"]==32) - { - $Alpha=127-round($Ikona[$IconID]["Data"][$x][$y]["alpha"]*127/255); - if($Ikona[$IconID]["Maska"][$x][$y]==1) $Alpha=127; - $color=imagecolorexactalpha($img,$R,$G,$B,$Alpha); - if($color==-1) $color=imagecolorallocatealpha($img,$R,$G,$B,$Alpha); - } - else - { - $color=imagecolorexact($img,$R,$G,$B); - if($color==-1) $color=imagecolorallocate($img,$R,$G,$B); - }; - - imagesetpixel($img,$x,$y,$color); - - }; - -} -else -{ -$img=imagecreate($Ikona[$IconID]["Width"],$Ikona[$IconID]["Height"]); -for($p=0;$p=24)or(imagecolorstotal($img)>=256)) - { - $img2=imagecreatetruecolor(imagesx($img),imagesy($img)); - imagecopy($img2,$img,0,0,0,0,imagesx($img),imagesy($img)); - imagedestroy($img); - $img=$img2; - imagetruecolortopalette($img,true,255); - - }; - $Pruhledna=imagecolorallocate($img,0,0,0); - for($y=0;$y<$Ikona[$IconID]["Height"];$y++) - for($x=0;$x<$Ikona[$IconID]["Width"];$x++) - if($Ikona[$IconID]["Maska"][$x][$y]==1) - { - imagesetpixel($img,$x,$y,$Pruhledna); - }; - imagecolortransparent($img,$Pruhledna); - }; - -return $img; - - -}; - - - - -function jpexs_readIcon($filename,$id,&$Ikona) -{ -global $jpexs_currentBit; - -$f=fopen($filename,"rb"); - -fseek($f,6+$id*16); - $Width=jpexs_freadbyte($f); - $Height=jpexs_freadbyte($f); -fseek($f,6+$id*16+12); -$OffSet=jpexs_freaddword($f); -fseek($f,$OffSet); - -$p=$id; - - $Ikona[$p]["Info"]["HeaderSize"]=jpexs_freadlngint($f); - $Ikona[$p]["Info"]["ImageWidth"]=jpexs_freadlngint($f); - $Ikona[$p]["Info"]["ImageHeight"]=jpexs_freadlngint($f); - $Ikona[$p]["Info"]["NumberOfImagePlanes"]=jpexs_freadword($f); - $Ikona[$p]["Info"]["BitsPerPixel"]=jpexs_freadword($f); - $Ikona[$p]["Info"]["CompressionMethod"]=jpexs_freadlngint($f); - $Ikona[$p]["Info"]["SizeOfBitmap"]=jpexs_freadlngint($f); - $Ikona[$p]["Info"]["HorzResolution"]=jpexs_freadlngint($f); - $Ikona[$p]["Info"]["VertResolution"]=jpexs_freadlngint($f); - $Ikona[$p]["Info"]["NumColorUsed"]=jpexs_freadlngint($f); - $Ikona[$p]["Info"]["NumSignificantColors"]=jpexs_freadlngint($f); - - - $biBitCount=$Ikona[$p]["Info"]["BitsPerPixel"]; - - if($Ikona[$p]["Info"]["BitsPerPixel"]<=8) - { - - $barev=pow(2,$biBitCount); - - for($b=0;$b<$barev;$b++) - { - $Ikona[$p]["Paleta"][$b]["b"]=jpexs_freadbyte($f); - $Ikona[$p]["Paleta"][$b]["g"]=jpexs_freadbyte($f); - $Ikona[$p]["Paleta"][$b]["r"]=jpexs_freadbyte($f); - jpexs_freadbyte($f); - }; - -$Zbytek=(4-ceil(($Width/(8/$biBitCount)))%4)%4; - - -for($y=$Height-1;$y>=0;$y--) - { - $jpexs_currentBit=0; - for($x=0;$x<$Width;$x++) - { - $C=jpexs_freadbits($f,$biBitCount); - $Ikona[$p]["Data"][$x][$y]=$C; - }; - - if($jpexs_currentBit!=0) {jpexs_freadbyte($f);}; - for($g=0;$g<$Zbytek;$g++) - jpexs_freadbyte($f); - }; - -} -elseif($biBitCount==24) -{ - $Zbytek=$Width%4; - - for($y=$Height-1;$y>=0;$y--) - { - for($x=0;$x<$Width;$x++) - { - $B=jpexs_freadbyte($f); - $G=jpexs_freadbyte($f); - $R=jpexs_freadbyte($f); - $Ikona[$p]["Data"][$x][$y]["r"]=$R; - $Ikona[$p]["Data"][$x][$y]["g"]=$G; - $Ikona[$p]["Data"][$x][$y]["b"]=$B; - } - for($z=0;$z<$Zbytek;$z++) - jpexs_freadbyte($f); - }; -} -elseif($biBitCount==32) -{ - $Zbytek=$Width%4; - - for($y=$Height-1;$y>=0;$y--) - { - for($x=0;$x<$Width;$x++) - { - $B=jpexs_freadbyte($f); - $G=jpexs_freadbyte($f); - $R=jpexs_freadbyte($f); - $Alpha=jpexs_freadbyte($f); - $Ikona[$p]["Data"][$x][$y]["r"]=$R; - $Ikona[$p]["Data"][$x][$y]["g"]=$G; - $Ikona[$p]["Data"][$x][$y]["b"]=$B; - $Ikona[$p]["Data"][$x][$y]["alpha"]=$Alpha; - } - for($z=0;$z<$Zbytek;$z++) - jpexs_freadbyte($f); - }; -}; - - -//Maska -$Zbytek=(4-ceil(($Width/(8)))%4)%4; -for($y=$Height-1;$y>=0;$y--) - { - $jpexs_currentBit=0; - for($x=0;$x<$Width;$x++) - { - $C=jpexs_freadbits($f,1); - $Ikona[$p]["Maska"][$x][$y]=$C; - }; - if($jpexs_currentBit!=0) {jpexs_freadbyte($f);}; - for($g=0;$g<$Zbytek;$g++) - jpexs_freadbyte($f); - }; -//-------------- - -fclose($f); - -}; - -function jpexs_GetIconsInfo($filename) -{ -global $jpexs_currentBit; - -$f=fopen($filename,"rb"); - -$Reserved=jpexs_freadword($f); -$Type=jpexs_freadword($f); -$Count=jpexs_freadword($f); -for($p=0;$p<$Count;$p++) - { - $Ikona[$p]["Width"]=jpexs_freadbyte($f); - $Ikona[$p]["Height"]=jpexs_freadbyte($f); - $Ikona[$p]["ColorCount"]=jpexs_freadword($f); - if($Ikona[$p]["ColorCount"]==0) $Ikona[$p]["ColorCount"]=256; - $Ikona[$p]["Planes"]=jpexs_freadword($f); - $Ikona[$p]["BitCount"]=jpexs_freadword($f); - $Ikona[$p]["BytesInRes"]=jpexs_freaddword($f); - $Ikona[$p]["ImageOffset"]=jpexs_freaddword($f); - }; - -if(!feof($f)): - for($p=0;$p<$Count;$p++) - { - fseek($f,$Ikona[$p]["ImageOffset"]+14); - $Ikona[$p]["Info"]["BitsPerPixel"]=jpexs_freadword($f); - }; -endif; -fclose($f); -return $Ikona; -}; - - - - -/** - * Reads image from a icon in exe file - * @param string $filename Target exefile - * @param int $icoIndex Index of the icon in exefile - * @param int $icoColorCount Icon color count (For multiple icons ico file) - 2,16,256, ICO_TRUE_COLOR, ICO_XP_COLOR or ICO_MAX_COLOR - * @param int $icoSize Icon width (For multiple icons ico file) or ICO_MAX_SIZE - * @param int $alphaBgR Background color R value for alpha-channel images (Default is White) - * @param int $alphaBgG Background color G value for alpha-channel images (Default is White) - * @param int $alphaBgB Background color B value for alpha-channel images (Default is White) - * @return resource Image resource or false on error - */ -function imageCreateFromExeIco($filename,$icoIndex,$icoColorCount=16,$icoSize=16,$alphaBgR=255,$alphaBgG=255,$alphaBgB=255) -{ - $ok=saveExeIcon($filename,"icotemp.dat",$icoIndex); - if(!$ok): - $im=false; - else: - $im=imageCreateFromIco("icotemp.dat",$icoColorCount,$icoSize,$alphaBgR,$alphaBgG,$alphaBgB); - unlink("icotemp.dat"); - endif; - return $im; -}; - - -/** - * Saves icon(s) from the exe file - * @global int $jpexs_StartOfRsrc Internal reserved variable - * @global int $jpexs_ImageBase Internal reserved variable - * @global int $jpexs_ResVirtualAddress Internal reserved variable - * @param string $filename Target exefile - * @param string $icoFileNameOrPath Filename to save ico or path (Default "") Path if you want more than 1 icon. If "", the filename is "$icoIndex.ico" - * @param int|array $iconIndex Index(es) of the icon in exefile (Default -1) If -1, all icons are saved, Can be an array of indexes. - * @return boolean True on successful save - */ -function saveExeIcon($filename,$icoFileNameOrPath="",$iconIndex=-1) /*-1 for all,or can be array*/ -{ - global $jpexs_f,$jpexs_StartOfRsrc,$jpexs_ImageBase,$jpexs_ResVirtualAddress; - $jpexs_f=fopen($filename,"r"); - $MZ=fread($jpexs_f,2); - if($MZ!="MZ") NotValidExe(); - fseek($jpexs_f,60); - $OffsetToNewHeader=jpexs_freaddword($jpexs_f); - fseek($jpexs_f,$OffsetToNewHeader); - $PE=fread($jpexs_f,2); - if($PE!="PE") NotValidExe(); - fread($jpexs_f,4); - $NumberOfSections=jpexs_freadword($jpexs_f); - fseek($jpexs_f,ftell($jpexs_f)+12); - $SizeOfOptionalHeader=jpexs_freadword($jpexs_f); - $PosMagic=ftell($jpexs_f)+2; - fseek($jpexs_f,$PosMagic+$SizeOfOptionalHeader); - - for($p=0;$p<$NumberOfSections;$p++): - $SectionName[$p]=trim(fread($jpexs_f,8)); - $VirtualSize[$p]=jpexs_freaddword($jpexs_f); - $VirtualAddress[$p]=jpexs_freaddword($jpexs_f); - $PhysicalSize[$p]=jpexs_freaddword($jpexs_f); - $PhysicalOffset[$p]=jpexs_freaddword($jpexs_f); - fread($jpexs_f,16); - if($SectionName[$p]==".rsrc"): - $jpexs_ResVirtualAddress=$VirtualAddress[$p]; - fseek($jpexs_f,$PhysicalOffset[$p]); - $jpexs_StartOfRsrc=$PhysicalOffset[$p]; - jpexs_readResDirectoryEntry($R,$PhysicalOffset[$p]); - $IconCount=null; - $Ikona=null; - while (list ($key, $val) = each ($R["Subdir"])): - if($key==14): - $r=0; - while (list ($key2, $val2) = each ($R["Subdir"][$key]["Subdir"])): - while (list ($key3, $val3) = each ($R["Subdir"][$key]["Subdir"][$key2]["Subdir"])): - fseek($jpexs_f,$val3["DataOffset"]); - $Reserved=jpexs_freadword($jpexs_f); - $Type=jpexs_freadword($jpexs_f); - $ic=jpexs_freadword($jpexs_f); - $IconCount[]=$ic; - for($s=0;$s<$ic;$s++) - { - $Ikona[$r][$s]["Width"]=jpexs_freadbyte($jpexs_f); - $Ikona[$r][$s]["Height"]=jpexs_freadbyte($jpexs_f); - $Ikona[$r][$s]["ColorCount"]=jpexs_freadword($jpexs_f); - $Ikona[$r][$s]["Planes"]=jpexs_freadword($jpexs_f); - $Ikona[$r][$s]["BitCount"]=jpexs_freadword($jpexs_f); - $Ikona[$r][$s]["BytesInRes"]=jpexs_freaddword($jpexs_f); - $Ikona[$r][$s]["IconId"]=jpexs_freadword($jpexs_f); - }; - fseek($jpexs_f,$val3["DataOffset"]); - $r++; - endwhile; - endwhile; - endif; - endwhile; - - reset ($R["Subdir"]); - - while (list ($key, $val) = each ($R["Subdir"])): - if($key==3): - while (list ($key2, $val2) = each ($R["Subdir"][$key]["Subdir"])): - for($r=0;$r=0x80000000): - //String Name - $ResNameOffset=$ResName-0x80000000; - fseek($jpexs_f,$jpexs_StartOfRsrc+$ResNameOffset); - $StringLength=jpexs_freadword($jpexs_f); - $Identificator=(fread($jpexs_f,$StringLength*2)); - fseek($jpexs_f,$lastPos2); - else: - //Integer Id - $Identificator=$ResName; - endif; - - $ResOffsetToData=jpexs_freaddword($jpexs_f); - if($ResOffsetToData>=0x80000000): - $SubResOffset=$ResOffsetToData-0x80000000; - jpexs_readResDirectoryEntry($Res["$Identificator"],$jpexs_StartOfRsrc+$SubResOffset); - else: - $RawDataOffset=$ResOffsetToData; - $lastPos2=ftell($jpexs_f); - fseek($jpexs_f,$jpexs_StartOfRsrc+$RawDataOffset); - //IMAGE_RESOURCE_DATA_ENTRY - $OffsetToData=jpexs_freaddword($jpexs_f); - $Res["$Identificator"]["DataOffset"]=$jpexs_StartOfRsrc-$jpexs_ResVirtualAddress+$OffsetToData; - $Res["$Identificator"]["DataSize"]=jpexs_freaddword($jpexs_f); - $CodePage=jpexs_freaddword($jpexs_f); - $Reserved=jpexs_freaddword($jpexs_f); - fseek($jpexs_f,$lastPos2); - endif; - endfor; -fseek($jpexs_f,$lastPos); -$parentRes["Subdir"]=$Res; -}; - -/** - * Creates ico file from image resource(s) - * @param resource|array $images Target Image resource (Can be array of image resources) - * @param string $filename Target ico file to save icon to, If ommited or "", image is written to snadard output - use header("Content-type: image/x-icon"); */ -function imageIco($images,$filename="") -{ - -if(is_array($images)) -{ -$ImageCount=count($images); -$Image=$images; -} -else -{ -$Image[0]=$images; -$ImageCount=1; -}; - - -$WriteToFile=false; - -if($filename!="") -{ -$WriteToFile=true; -}; - - -$ret=""; - -$ret.=jpexs_inttoword(0); //PASSWORD -$ret.=jpexs_inttoword(1); //SOURCE -$ret.=jpexs_inttoword($ImageCount); //ICONCOUNT - - -for($q=0;$q<$ImageCount;$q++) -{ -$img=$Image[$q]; - -$Width=imagesx($img); -$Height=imagesy($img); - -$ColorCount=imagecolorstotal($img); - -$Transparent=imagecolortransparent($img); -$IsTransparent=$Transparent!=-1; - - -if($IsTransparent) $ColorCount--; - -if($ColorCount==0) {$ColorCount=0; $BitCount=24;}; -if(($ColorCount>0)and($ColorCount<=2)) {$ColorCount=2; $BitCount=1;}; -if(($ColorCount>2)and($ColorCount<=16)) { $ColorCount=16; $BitCount=4;}; -if(($ColorCount>16)and($ColorCount<=256)) { $ColorCount=0; $BitCount=8;}; - - - - - -//ICONINFO: -$ret.=jpexs_inttobyte($Width);// -$ret.=jpexs_inttobyte($Height);// -$ret.=jpexs_inttobyte($ColorCount);// -$ret.=jpexs_inttobyte(0);//RESERVED - -$Planes=0; -if($BitCount>=8) $Planes=1; - -$ret.=jpexs_inttoword($f,$Planes);//PLANES -if($BitCount>=8) $WBitCount=$BitCount; -if($BitCount==4) $WBitCount=0; -if($BitCount==1) $WBitCount=0; -$ret.=jpexs_inttoword($WBitCount);//BITS - -$Zbytek=(4-($Width/(8/$BitCount))%4)%4; -$ZbytekMask=(4-($Width/8)%4)%4; - -$PalSize=0; - -$Size=40+($Width/(8/$BitCount)+$Zbytek)*$Height+(($Width/8+$ZbytekMask) * $Height); -if($BitCount<24) - $Size+=pow(2,$BitCount)*4; -$IconId=1; -$ret.=jpexs_inttodword($Size); //SIZE -$OffSet=6+16*$ImageCount+$FullSize; -$ret.=jpexs_inttodword(6+16*$ImageCount+$FullSize);//OFFSET -$FullSize+=$Size; -//------------- - -}; - - -for($q=0;$q<$ImageCount;$q++) -{ -$img=$Image[$q]; -$Width=imagesx($img); -$Height=imagesy($img); -$ColorCount=imagecolorstotal($img); - -$Transparent=imagecolortransparent($img); -$IsTransparent=$Transparent!=-1; - -if($IsTransparent) $ColorCount--; -if($ColorCount==0) {$ColorCount=0; $BitCount=24;}; -if(($ColorCount>0)and($ColorCount<=2)) {$ColorCount=2; $BitCount=1;}; -if(($ColorCount>2)and($ColorCount<=16)) { $ColorCount=16; $BitCount=4;}; -if(($ColorCount>16)and($ColorCount<=256)) { $ColorCount=0; $BitCount=8;}; - - - -//ICONS -$ret.=jpexs_inttodword(40);//HEADSIZE -$ret.=jpexs_inttodword($Width);// -$ret.=jpexs_inttodword(2*$Height);// -$ret.=jpexs_inttoword(1); //PLANES -$ret.=jpexs_inttoword($BitCount); // -$ret.=jpexs_inttodword(0);//Compress method - - -$ZbytekMask=($Width/8)%4; - -$Zbytek=($Width/(8/$BitCount))%4; -$Size=($Width/(8/$BitCount)+$Zbytek)*$Height+(($Width/8+$ZbytekMask) * $Height); - -$ret.=jpexs_inttodword($Size);//SIZE - -$ret.=jpexs_inttodword(0);//HPIXEL_M -$ret.=jpexs_inttodword(0);//V_PIXEL_M -$ret.=jpexs_inttodword($ColorCount); //UCOLORS -$ret.=jpexs_inttodword(0); //DCOLORS -//--------------- - - -$CC=$ColorCount; -if($CC==0) $CC=256; - -if($BitCount<24) -{ - $ColorTotal=imagecolorstotal($img); - if($IsTransparent) $ColorTotal--; - - for($p=0;$p<$ColorTotal;$p++) - { - $color=imagecolorsforindex($img,$p); - $ret.=jpexs_inttobyte($color["blue"]); - $ret.=jpexs_inttobyte($color["green"]); - $ret.=jpexs_inttobyte($color["red"]); - $ret.=jpexs_inttobyte(0); //RESERVED - }; - - $CT=$ColorTotal; - for($p=$ColorTotal;$p<$CC;$p++) - { - $ret.=jpexs_inttobyte(0); - $ret.=jpexs_inttobyte(0); - $ret.=jpexs_inttobyte(0); - $ret.=jpexs_inttobyte(0); //RESERVED - }; -}; - - - - - - -if($BitCount<=8) -{ - - for($y=$Height-1;$y>=0;$y--) - { - $bWrite=""; - for($x=0;$x<$Width;$x++) - { - $color=imagecolorat($img,$x,$y); - if($color==$Transparent) - $color=imagecolorexact($img,0,0,0); - if($color==-1) $color=0; - if($color>pow(2,$BitCount)-1) $color=0; - - $bWrite.=jpexs_decbinx($color,$BitCount); - if(strlen($bWrite)==8) - { - $ret.=jpexs_inttobyte(bindec($bWrite)); - $bWrite=""; - }; - }; - - if((strlen($bWrite)<8)and(strlen($bWrite)!=0)) - { - $sl=strlen($bWrite); - for($t=0;$t<8-$sl;$t++) - $sl.="0"; - $ret.=jpexs_inttobyte(bindec($bWrite)); - }; - for($z=0;$z<$Zbytek;$z++) - $ret.=jpexs_inttobyte(0); - }; -}; - - - -if($BitCount>=24) -{ - for($y=$Height-1;$y>=0;$y--) - { - for($x=0;$x<$Width;$x++) - { - $color=imagecolorsforindex($img,imagecolorat($img,$x,$y)); - $ret.=jpexs_inttobyte($color["blue"]); - $ret.=jpexs_inttobyte($color["green"]); - $ret.=jpexs_inttobyte($color["red"]); - if($BitCount==32) - $ret.=jpexs_inttobyte(0);//Alpha for ICO_XP_COLORS - }; - for($z=0;$z<$Zbytek;$z++) - $ret.=jpexs_inttobyte(0); - }; -}; - - -//MASK - - for($y=$Height-1;$y>=0;$y--) - { - $byteCount=0; - $bOut=""; - for($x=0;$x<$Width;$x++) - { - if(($Transparent!=-1)and(imagecolorat($img,$x,$y)==$Transparent)) - { - $bOut.="1"; - } - else - { - $bOut.="0"; - }; - }; - for($p=0;$p$start+$len from $byte -* jpexs_freadbits($file,$count) - reads next $count bits from $file -*/ - - -function jpexs_decbin8($d) -{ -return jpexs_decbinx($d,8); -}; - -function jpexs_decbinx($d,$n) -{ -$bin=decbin($d); -$sbin=strlen($bin); -for($j=0;$j<$n-$sbin;$j++) - $bin="0$bin"; -return $bin; -}; - -function jpexs_retBits($byte,$start,$len) -{ -$bin=jpexs_decbin8($byte); -$r=bindec(substr($bin,$start,$len)); -return $r; - -}; - - - -$jpexs_currentBit=0; -function jpexs_freadbits($f,$count) -{ - global $jpexs_currentBit,$jpexs_SMode; - $Byte=jpexs_freadbyte($f); - $LastCBit=$jpexs_currentBit; - $jpexs_currentBit+=$count; - if($jpexs_currentBit==8) - { - $jpexs_currentBit=0; - } - else - { - fseek($f,ftell($f)-1); - }; - return jpexs_retBits($Byte,$LastCBit,$count); -}; - - -function jpexs_freadbyte($f) -{ - return ord(fread($f,1)); -}; - -function jpexs_freadword($f) -{ - $b1=jpexs_freadbyte($f); - $b2=jpexs_freadbyte($f); - return $b2*256+$b1; -}; - - -function jpexs_freadlngint($f) -{ -return jpexs_freaddword($f); -}; - -function jpexs_freaddword($f) -{ - $b1=jpexs_freadword($f); - $b2=jpexs_freadword($f); - return $b2*65536+$b1; -}; - -function jpexs_inttobyte($n) -{ -return chr($n); -}; - -function jpexs_inttodword($n) -{ -return chr($n & 255).chr(($n >> 8) & 255).chr(($n >> 16) & 255).chr(($n >> 24) & 255); -}; - -function jpexs_inttoword($n) - { - return chr($n & 255).chr(($n >> 8) & 255); - }; - -?> \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/vendor/JPEXS/index.html b/htdocs/libraries/wideimage/lib/vendor/JPEXS/index.html deleted file mode 100644 index 74b6f45c8f33..000000000000 --- a/htdocs/libraries/wideimage/lib/vendor/JPEXS/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/vendor/de77/BMP.php b/htdocs/libraries/wideimage/lib/vendor/de77/BMP.php deleted file mode 100644 index 2f5521144c4b..000000000000 --- a/htdocs/libraries/wideimage/lib/vendor/de77/BMP.php +++ /dev/null @@ -1,264 +0,0 @@ -=0; $y--) - { - for ($x=0; $x<$wid; $x++) - { - $rgb = imagecolorat($img, $x, $y); - fwrite($f, self::byte3($rgb)); - } - fwrite($f, $wid_pad); - } - fclose($f); - } - else - { - foreach ($header AS $h) - { - echo $h; - } - - //save pixels - for ($y=$hei-1; $y>=0; $y--) - { - for ($x=0; $x<$wid; $x++) - { - $rgb = imagecolorat($img, $x, $y); - echo self::byte3($rgb); - } - echo $wid_pad; - } - } - return true; - } - - public static function imagecreatefromstring($data) - { - //read header - $pos = 0; - $header = substr($data, 0, 54); - $pos = 54; - - if (strlen($header) < 54) - return false; - - $header = unpack( 'c2identifier/Vfile_size/Vreserved/Vbitmap_data/Vheader_size/' . - 'Vwidth/Vheight/vplanes/vbits_per_pixel/Vcompression/Vdata_size/'. - 'Vh_resolution/Vv_resolution/Vcolors/Vimportant_colors', $header); - - if ($header['identifier1'] != 66 or $header['identifier2'] != 77) - { - return false; - //die('Not a valid bmp file'); - } - - if (!in_array($header['bits_per_pixel'], array(24, 32, 8, 4, 1))) - { - return false; - //die('Only 1, 4, 8, 24 and 32 bit BMP images are supported'); - } - - $bps = $header['bits_per_pixel']; //bits per pixel - $wid2 = ceil(($bps/8 * $header['width']) / 4) * 4; - $colors = pow(2, $bps); - - $wid = $header['width']; - $hei = $header['height']; - - $img = imagecreatetruecolor($header['width'], $header['height']); - - //read palette - if ($bps < 9) - { - for ($i=0; $i<$colors; $i++) - { - $palette[] = self::undword(substr($data, $pos, 4)); - $pos += 4; - } - } - else - { - if ($bps == 32) - { - imagealphablending($img, false); - imagesavealpha($img, true); - } - $palette = array(); - } - - //read pixels - for ($y=$hei-1; $y>=0; $y--) - { - $row = substr($data, $pos, $wid2); - $pos += $wid2; - $pixels = self::str_split2($row, $bps, $palette); - for ($x=0; $x<$wid; $x++) - { - self::makepixel($img, $x, $y, $pixels[$x], $bps); - } - } - - return $img; - } - - public static function imagecreatefrombmp($filename) - { - return self::imagecreatefromstring(file_get_contents($filename)); - } - - private static function str_split2($row, $bps, $palette) - { - switch ($bps) - { - case 32: - case 24: return str_split($row, $bps/8); - case 8: $out = array(); - $count = strlen($row); - for ($i=0; $i<$count; $i++) - { - $out[] = $palette[ ord($row[$i]) ]; - } - return $out; - case 4: $out = array(); - $count = strlen($row); - for ($i=0; $i<$count; $i++) - { - $roww = ord($row[$i]); - $out[] = $palette[ ($roww & 240) >> 4 ]; - $out[] = $palette[ ($roww & 15) ]; - } - return $out; - case 1: $out = array(); - $count = strlen($row); - for ($i=0; $i<$count; $i++) - { - $roww = ord($row[$i]); - $out[] = $palette[ ($roww & 128) >> 7 ]; - $out[] = $palette[ ($roww & 64) >> 6 ]; - $out[] = $palette[ ($roww & 32) >> 5 ]; - $out[] = $palette[ ($roww & 16) >> 4 ]; - $out[] = $palette[ ($roww & 8) >> 3 ]; - $out[] = $palette[ ($roww & 4) >> 2 ]; - $out[] = $palette[ ($roww & 2) >> 1 ]; - $out[] = $palette[ ($roww & 1) ]; - } - return $out; - } - } - - private static function makepixel($img, $x, $y, $str, $bps) - { - switch ($bps) - { - case 32 : $a = ord($str[0]); - $b = ord($str[1]); - $c = ord($str[2]); - $d = 256 - ord($str[3]); //TODO: gives imperfect results - $pixel = $d*256*256*256 + $c*256*256 + $b*256 + $a; - imagesetpixel($img, $x, $y, $pixel); - break; - case 24 : $a = ord($str[0]); - $b = ord($str[1]); - $c = ord($str[2]); - $pixel = $c*256*256 + $b*256 + $a; - imagesetpixel($img, $x, $y, $pixel); - break; - case 8 : - case 4 : - case 1 : imagesetpixel($img, $x, $y, $str); - break; - } - } - - private static function byte3($n) - { - return chr($n & 255) . chr(($n >> 8) & 255) . chr(($n >> 16) & 255); - } - - private static function undword($n) - { - $r = unpack("V", $n); - return $r[1]; - } - - private static function dword($n) - { - return pack("V", $n); - } - - private static function word($n) - { - return pack("v", $n); - } -} diff --git a/htdocs/libraries/wideimage/lib/vendor/de77/TGA.php b/htdocs/libraries/wideimage/lib/vendor/de77/TGA.php deleted file mode 100644 index 584f3c97c066..000000000000 --- a/htdocs/libraries/wideimage/lib/vendor/de77/TGA.php +++ /dev/null @@ -1,206 +0,0 @@ -= $datalen) - { - break; - } - - $i++; - - if ($type == 0) //raw - { - for ($j=0; $j<3*$value; $j++) - { - $out .= $data[$j+$i]; - $k++; - } - $i += $value*3; - } - else //rle - { - for ($j=0; $j<$value; $j++) - { - $out .= $data[$i] . $data[$i+1] . $data[$i+2]; - $k++; - } - $i += 3; - } - } - return $out; - } - - static function dec_bits($byte, &$type, &$value) - { - $type = ($byte & 0x80) >> 7; - $value = 1 + ($byte & 0x7F); - } - - static function imagecreatefromstring($bin_data) - { - $bin_pos = 0; - $header = substr($bin_data, $bin_pos, 18); - $bin_pos += 18; - $header = unpack( "cimage_id_len/ccolor_map_type/cimage_type/vcolor_map_origin/vcolor_map_len/" . - "ccolor_map_entry_size/vx_origin/vy_origin/vwidth/vheight/" . - "cpixel_size/cdescriptor", $header); - - switch ($header['image_type']) - { - case 2: //no palette, uncompressed - case 10: //no palette, rle - break; - default: return false; //die('Unsupported TGA format'); - } - - if ($header['pixel_size'] != 24) - { - return false; - //die('Unsupported TGA color depth'); - } - - $bytes = $header['pixel_size'] / 8; - - if ($header['image_id_len'] > 0) - { - $header['image_id'] = substr($bin_data, $bin_pos, $header['image_id_len']); - $bin_pos += $header['image_id_len']; - } - else - { - $header['image_id'] = ''; - } - - $im = imagecreatetruecolor($header['width'], $header['height']); - - $size = $header['width'] * $header['height'] * 3; - - //-- check whether this is NEW TGA or not - $pos = $bin_pos; - $bin_pos = strlen($bin_data) - 26; - $newtga = substr($bin_data, $bin_pos, 26); - if (substr($newtga, 8, 16) != 'TRUEVISION-XFILE') - { - $newtga = false; - } - - $bin_pos = strlen($bin_data); - $datasize = $bin_pos - $pos; - if ($newtga) - { - $datasize -= 26; - } - - $bin_pos = $pos; - - //-- end of check - $data = substr($bin_data, $bin_pos, $datasize); - $bin_pos += $datasize; - if ($header['image_type'] == 10) - { - $data = self::rle_decode($data, $size); - } - if (self::bit5($header['descriptor']) == 1) - { - $reverse = true; - } - else - { - $reverse = false; - } - - $pixels = str_split($data, 3); - $i = 0; - - //read pixels - if ($reverse) - { - for ($y=0; $y<$header['height']; $y++) - { - for ($x=0; $x<$header['width']; $x++) - { - imagesetpixel($im, $x, $y, self::dwordize($pixels[$i])); - $i++; - } - } - } - else - { - for ($y=$header['height']-1; $y>=0; $y--) - { - for ($x=0; $x<$header['width']; $x++) - { - imagesetpixel($im, $x, $y, self::dwordize($pixels[$i])); - $i++; - } - } - } - - return $im; - } - - static function imagecreatefromtga($filename) - { - return self::imagecreatefromstring(file_get_contents($filename)); - } - - static function dwordize($str) - { - $a = ord($str[0]); - $b = ord($str[1]); - $c = ord($str[2]); - return $c*256*256 + $b*256 + $a; - } - - static function bit5($x) - { - return ($x & 32) >> 5; - } -} \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/vendor/de77/index.html b/htdocs/libraries/wideimage/lib/vendor/de77/index.html deleted file mode 100644 index 74b6f45c8f33..000000000000 --- a/htdocs/libraries/wideimage/lib/vendor/de77/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/htdocs/libraries/wideimage/lib/vendor/index.html b/htdocs/libraries/wideimage/lib/vendor/index.html deleted file mode 100644 index 74b6f45c8f33..000000000000 --- a/htdocs/libraries/wideimage/lib/vendor/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/htdocs/modules/system/admin/images/main.php b/htdocs/modules/system/admin/images/main.php index 5fb077091586..556493592dd3 100644 --- a/htdocs/modules/system/admin/images/main.php +++ b/htdocs/modules/system/admin/images/main.php @@ -1,32 +1,32 @@ // -// ------------------------------------------------------------------------ // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// You may not change or alter any portion of this comment or credits // -// of supporting developers from this source code or any supporting // -// source code which is considered copyrighted (c) material of the // -// original comment or credit authors. // -// // -// This program 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 General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// ------------------------------------------------------------------------ // -// Author: Kazumi Ono (AKA onokazu) // +// ------------------------------------------------------------------------ // +// XOOPS - PHP Content Management System // +// Copyright (c) 2000 XOOPS.org // +// // +// ------------------------------------------------------------------------ // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// You may not change or alter any portion of this comment or credits // +// of supporting developers from this source code or any supporting // +// source code which is considered copyrighted (c) material of the // +// original comment or credit authors. // +// // +// This program 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 General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// ------------------------------------------------------------------------ // +// Author: Kazumi Ono (AKA onokazu) // // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ // -// Project: The XOOPS Project // +// Project: The XOOPS Project // // ------------------------------------------------------------------------- // /** @@ -34,14 +34,14 @@ * * System tool that allow manage images to use in the site * - * @category ICMS - * @package Administration - * @subpackage Images - * @copyright The ImpressCMS Project http://www.impresscms.org/ - * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL) - * @since 1.2 - * @author Rodrigo Pereira Lima (AKA TheRplima) - * @version SVN: $Id: main.php 12460 2014-06-25 03:35:37Z skenow $ + * @category ICMS + * @package Administration + * @subpackage Images + * @copyright The ImpressCMS Project http://www.impresscms.org/ + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL) + * @since 1.2 + * @author Rodrigo Pereira Lima (AKA TheRplima) + * @version SVN: $Id: main.php 12460 2014-06-25 03:35:37Z skenow $ */ /* check user permissions before proceeding */ @@ -49,30 +49,25 @@ exit(_NOPERM); } +use WideImage\WideImage as WideImage; + /* set filter types, if not strings */ -$filter_get = array( - 'limit' => 'int', - 'start' => 'int', - 'imgcat_id' => 'int', - 'image_id' => 'int', - 'uid' => 'int', -); +$filter_get = array('limit' => 'int', 'start' => 'int', 'imgcat_id' => 'int', 'image_id' => 'int', 'uid' => 'int'); $filter_post = array( - 'limit' => 'int', - 'start' => 'int', - 'imgcat_id' => 'int', - 'image_id' => 'int', - 'uid' => 'int', - 'imgcat_pid' => 'int', - 'imgcat_maxsize' => 'int', - 'imgcat_maxwidth' => 'int', - 'imgcat_maxheight' => 'int', - 'imgcat_display' => 'int', - 'imgcat_weight' => 'int', - 'readgroup' => 'int', - 'writegroup' => 'int', -); + 'limit' => 'int', + 'start' => 'int', + 'imgcat_id' => 'int', + 'image_id' => 'int', + 'uid' => 'int', + 'imgcat_pid' => 'int', + 'imgcat_maxsize' => 'int', + 'imgcat_maxwidth' => 'int', + 'imgcat_maxheight' => 'int', + 'imgcat_display' => 'int', + 'imgcat_weight' => 'int', + 'readgroup' => 'int', + 'writegroup' => 'int'); /* set default values for variables */ $start = $imgcat_id = $image_id = $uid = 0; @@ -84,7 +79,7 @@ /* filter the user input */ if (!empty($_GET)) { // in places where strict mode is not used for checkVarArray, make sure filter_ vars are not overwritten - if (isset($_GET['filter_post'])) unset ($_GET['filter_post']); + if (isset($_GET['filter_post'])) unset($_GET['filter_post']); $clean_GET = icms_core_DataFilter::checkVarArray($_GET, $filter_get, FALSE); extract($clean_GET); } @@ -145,9 +140,9 @@ case 'delfile': icms_cp_header(); $image_handler = icms::handler('icms_image'); - $image =& $image_handler->get($image_id); + $image = &$image_handler->get($image_id); $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($image->getVar('imgcat_id')); + $imagecategory = &$imgcat_handler->get($image->getVar('imgcat_id')); $src = '
'; echo '
' . $src . '
'; icms_core_Message::confirm(array('op' => 'delfileok', 'image_id' => $image_id, 'imgcat_id' => $imgcat_id, 'fct' => 'images'), 'admin.php', _MD_RUDELIMG); @@ -166,7 +161,6 @@ $msg = isset($_GET['msg']) ? urldecode($_GET['msg']) : NULL; redir($imgcat_id, filter_var($msg, FILTER_SANITIZE_ENCODED)); break; - } /** @@ -181,7 +175,7 @@ function imanager_index($imgcat_id = NULL) { $groups = array(ICMS_GROUP_ANONYMOUS); $admin = FALSE; } else { - $groups =& icms::$user->getGroups(); + $groups = &icms::$user->getGroups(); $admin = (!icms::$user->isAdmin(1)) ? FALSE : TRUE; } @@ -204,7 +198,7 @@ function imanager_index($imgcat_id = NULL) { } $id = (NULL !== $imgcat_id ? $imgcat_id : 0); $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $id)); - $imagecategorys =& $imgcat_handler->getObjects($criteriaRead); + $imagecategorys = &$imgcat_handler->getObjects($criteriaRead); $criteriaWrite = new icms_db_criteria_Compo(); if (is_array($groups) && !empty($groups)) { $criteriaWrite->add($criteriaTray); @@ -212,7 +206,7 @@ function imanager_index($imgcat_id = NULL) { $criteriaWrite->add(new icms_db_criteria_Item('gperm_modid', 1)); } $criteriaWrite->add(new icms_db_criteria_Item('imgcat_pid', $id)); - $imagecategorysWrite =& $imgcat_handler->getObjects($criteriaWrite); + $imagecategorysWrite = &$imgcat_handler->getObjects($criteriaWrite); $icmsAdminTpl->assign('lang_imanager_title', _IMGMANAGER); $icmsAdminTpl->assign('lang_imanager_catid', _MD_IMAGECATID); @@ -250,7 +244,7 @@ function imanager_index($imgcat_id = NULL) { $count = $msize = $subs = $nwrite = array(); $hasnwrite = array(); $icmsAdminTpl->assign('catcount', $catcount = count($imagecategorys)); - for ($i = 0; $i < $catcount; $i++) { + for ($i = 0; $i < $catcount; $i++ ) { $nwrite[$i] = is_writable($imgcat_handler->getCategFolder($imagecategorys[$i])); if (!$nwrite[$i]) { $hasnwrite[] = $imagecategorys[$i]->getVar('imgcat_name'); @@ -269,11 +263,11 @@ function imanager_index($imgcat_id = NULL) { } $id = (NULL !== $imgcat_id ? $imgcat_id : 0); $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $imagecategorys[$i]->getVar('imgcat_id'))); - $subs[$i] = count($imgcat_handler->getObjects($criteriaRead)); + $subs[$i] = count($imgcat_handler->getObjects($criteriaRead)); } $hasnwrite = implode(', ', $hasnwrite); $scount = array(); - foreach ($subs as $k=>$v) { + foreach ($subs as $k => $v) { $criteriaRead = new icms_db_criteria_Compo(); if (is_array($groups) && !empty($groups)) { $criteriaTray = new icms_db_criteria_Compo(); @@ -288,7 +282,7 @@ function imanager_index($imgcat_id = NULL) { $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $imagecategorys[$k]->getVar('imgcat_id'))); $ssubs = $imgcat_handler->getObjects($criteriaRead); $sc = 0; - foreach ($ssubs as $id=>$va) { + foreach ($ssubs as $id => $va) { $sc += $image_handler->getCount(new icms_db_criteria_Item('imgcat_id', $va->getVar('imgcat_id'))); } $scount[$k] = $sc; @@ -346,7 +340,7 @@ function imanager_index($imgcat_id = NULL) { $fname = new icms_form_elements_Text(_MD_IMGCATFOLDERNAME, 'imgcat_foldername', 50, 255, ''); $fname->setDescription('' . _MD_IMGCATFOLDERNAME_DESC . '
' . _MD_STRTYOPENG . '
'); $js = 'var fname = document.getElementById("imgcat_foldername");'; - $js .= 'if (fname.disabled == false && fname.value == "") {alert("' . sprintf(_FORM_ENTER, _MD_IMGCATFOLDERNAME ) . '"); return false;}'; + $js .= 'if (fname.disabled == false && fname.value == "") {alert("' . sprintf(_FORM_ENTER, _MD_IMGCATFOLDERNAME) . '"); return false;}'; $fname->customValidationCode[] = $js; $form->addElement($fname, TRUE); $form->addElement(new icms_form_elements_Hidden('op', 'addcat')); @@ -365,8 +359,8 @@ function imanager_index($imgcat_id = NULL) { /** * Logic and rendering for listing images within a category * - * @param int $imgcat_id Unique ID of the image category to list - * @param int $start Starting location for long lists + * @param int $imgcat_id Unique ID of the image category to list + * @param int $start Starting location for long lists */ function imanager_listimg($imgcat_id, $start = 0) { global $icmsAdminTpl, $query, $limit; @@ -375,7 +369,7 @@ function imanager_listimg($imgcat_id, $start = 0) { $groups = array(ICMS_GROUP_ANONYMOUS); $admin = FALSE; } else { - $groups =& icms::$user->getGroups(); + $groups = &icms::$user->getGroups(); $admin = (!icms::$user->isAdmin(1)) ? FALSE : TRUE; } @@ -385,9 +379,9 @@ function imanager_listimg($imgcat_id, $start = 0) { redirect_header('admin.php?fct=images', 1, ''); } $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($imgcat_id); + $imagecategory = &$imgcat_handler->get($imgcat_id); $categ_path = $imgcat_handler->getCategFolder($imagecategory); - $categ_url = $imgcat_handler->getCategFolder($imagecategory, 1, 'url'); + $categ_url = $imgcat_handler->getCategFolder($imagecategory, 1, 'url'); if (!is_object($imagecategory)) { redirect_header('admin.php?fct=images', 1, ''); } @@ -434,7 +428,7 @@ function imanager_listimg($imgcat_id, $start = 0) { } $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $imagecategory->getVar('imgcat_id'))); $subcats = $imgcat_handler->getObjects($criteriaRead); - $subs = count($subcats); + $subs = count($subcats); $icmsAdminTpl->assign('cat_subs', $subs); $image_handler = icms::handler('icms_image'); @@ -453,7 +447,7 @@ function imanager_listimg($imgcat_id, $start = 0) { $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $imagecategory->getVar('imgcat_id'))); $ssubs = $imgcat_handler->getObjects($criteriaRead); $sc = 0; - foreach ($ssubs as $id=>$va) { + foreach ($ssubs as $id => $va) { $sc += $image_handler->getCount(new icms_db_criteria_Item('imgcat_id', $va->getVar('imgcat_id'))); } $scount = $sc; @@ -489,7 +483,7 @@ function imanager_listimg($imgcat_id, $start = 0) { $criteria->setOrder('DESC'); $criteria->setSort('image_weight'); $criteria->setLimit($limit); - $images =& $image_handler->getObjects($criteria, TRUE, TRUE); + $images = &$image_handler->getObjects($criteria, TRUE, TRUE); $icmsAdminTpl->assign('imgcount', $imgcount); @@ -526,7 +520,7 @@ function imanager_listimg($imgcat_id, $start = 0) { } $arrimg[$i]['src'] = $src . '?' . time(); $src_lightbox = ICMS_MODULES_URL . "/system/admin/images/preview.php?file=" . $images[$i]->getVar('image_name'); - $preview_url = '' . _PREVIEW . ''; + $preview_url = '' . _PREVIEW . ''; $arrimg[$i]['preview_link'] = $preview_url; $extra_perm = array("image/jpeg", "image/jpeg", "image/png", "image/gif"); @@ -588,7 +582,7 @@ function imanager_addcat() { $imgcat_foldername = preg_replace('/[?".<>\|\s]/', '_', $imgcat_foldername); $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->create(); + $imagecategory = &$imgcat_handler->create(); $imagecategory->setVar('imgcat_pid', $imgcat_pid); $imagecategory->setVar('imgcat_name', $imgcat_name); $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize); @@ -610,8 +604,7 @@ function imanager_addcat() { if (!icms_core_Filesystem::mkdir($categ_path)) { redirect_header('admin.php?fct=images', 1, _MD_FAILADDCAT); } else { - if ($fh = @fopen($categ_path . '/index.html', 'w')) - fwrite($fh, ''); + if ($fh = @fopen($categ_path . '/index.html', 'w')) fwrite($fh, ''); @fclose($fh); } } @@ -632,7 +625,7 @@ function imanager_addcat() { } foreach ($readgroup as $rgroup) { - $imagecategoryperm =& $imagecategoryperm_handler->create(); + $imagecategoryperm = &$imagecategoryperm_handler->create(); $imagecategoryperm->setVar('gperm_groupid', $rgroup); $imagecategoryperm->setVar('gperm_itemid', $newid); $imagecategoryperm->setVar('gperm_name', 'imgcat_read'); @@ -650,7 +643,7 @@ function imanager_addcat() { } foreach ($writegroup as $wgroup) { - $imagecategoryperm =& $imagecategoryperm_handler->create(); + $imagecategoryperm = &$imagecategoryperm_handler->create(); $imagecategoryperm->setVar('gperm_groupid', $wgroup); $imagecategoryperm->setVar('gperm_itemid', $newid); $imagecategoryperm->setVar('gperm_name', 'imgcat_write'); @@ -663,14 +656,15 @@ function imanager_addcat() { /** * Logic and rendering for editing an image category - * @param int $imgcat_id Unique ID of the image category to edit + * + * @param int $imgcat_id Unique ID of the image category to edit */ function imanager_editcat($imgcat_id) { if ($imgcat_id <= 0) { redirect_header('admin.php?fct=images', 1); } $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($imgcat_id); + $imagecategory = &$imgcat_handler->get($imgcat_id); if (!is_object($imagecategory)) { redirect_header('admin.php?fct=images', 1); } @@ -706,7 +700,7 @@ function imanager_updatecat() { } $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($imgcat_id); + $imagecategory = &$imgcat_handler->get($imgcat_id); if (!is_object($imagecategory)) { redirect_header('admin.php?fct=images', 1); } @@ -734,7 +728,7 @@ function imanager_updatecat() { array_push($readgroup, ICMS_GROUP_ADMIN); } foreach ($readgroup as $rgroup) { - $imagecategoryperm =& $imagecategoryperm_handler->create(); + $imagecategoryperm = &$imagecategoryperm_handler->create(); $imagecategoryperm->setVar('gperm_groupid', $rgroup); $imagecategoryperm->setVar('gperm_itemid', $imgcat_id); $imagecategoryperm->setVar('gperm_name', 'imgcat_read'); @@ -749,7 +743,7 @@ function imanager_updatecat() { array_push($writegroup, ICMS_GROUP_ADMIN); } foreach ($writegroup as $wgroup) { - $imagecategoryperm =& $imagecategoryperm_handler->create(); + $imagecategoryperm = &$imagecategoryperm_handler->create(); $imagecategoryperm->setVar('gperm_groupid', $wgroup); $imagecategoryperm->setVar('gperm_itemid', $imgcat_id); $imagecategoryperm->setVar('gperm_name', 'imgcat_write'); @@ -762,7 +756,8 @@ function imanager_updatecat() { /** * Logic and rendering for deleting an image category - * @param int $imgcat_id Unique ID for the image category to be deleted + * + * @param int $imgcat_id Unique ID for the image category to be deleted */ function imanager_delcatok($imgcat_id) { if (!icms::$security->check()) { @@ -774,7 +769,7 @@ function imanager_delcatok($imgcat_id) { redirect_header('admin.php?fct=images', 1, '1'); } $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($imgcat_id); + $imagecategory = &$imgcat_handler->get($imgcat_id); if (!is_object($imagecategory)) { redirect_header('admin.php?fct=images', 1, '2'); @@ -786,7 +781,7 @@ function imanager_delcatok($imgcat_id) { } $image_handler = icms::handler('icms_image'); - $images =& $image_handler->getObjects(new icms_db_criteria_Item('imgcat_id', $imgcat_id), TRUE, FALSE); + $images = &$image_handler->getObjects(new icms_db_criteria_Item('imgcat_id', $imgcat_id), TRUE, FALSE); $errors = array(); @@ -840,11 +835,11 @@ function imanager_reordercateg() { $err = 0; if ($count > 0) { $imgcat_handler = icms::handler('icms_image_category'); - foreach ($_POST['imgcat_weight'] as $k=>$v) { + foreach ($_POST['imgcat_weight'] as $k => $v) { $cat = $imgcat_handler->get((int) $k); $cat->setVar('imgcat_weight', (int) $v); if (!$imgcat_handler->insert($cat)) { - $err++; + $err++ ; } } if ($err) { @@ -868,7 +863,7 @@ function imanager_addfile() { global $imgcat_id, $image_display, $image_weight, $image_nicename; $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get((int) $imgcat_id); + $imagecategory = &$imgcat_handler->get((int) $imgcat_id); if (!is_object($imagecategory)) { redirect_header('admin.php?fct=images', 1); } @@ -883,13 +878,13 @@ function imanager_addfile() { $uploader->setPrefix('img'); $err = array(); $ucount = count($_POST['xoops_upload_file']); - for ($i = 0; $i < $ucount; $i++) { + for ($i = 0; $i < $ucount; $i++ ) { if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) { if (!$uploader->upload()) { $err[] = $uploader->getErrors(); } else { $image_handler = icms::handler('icms_image'); - $image =& $image_handler->create(); + $image = &$image_handler->create(); $image->setVar('image_name', $uploader->getSavedFileName()); $image->setVar('image_nicename', $image_nicename); $image->setVar('image_mimetype', $uploader->getMediaType()); @@ -943,8 +938,8 @@ function imanager_updateimage() { if ($count > 0) { $image_handler = icms::handler('icms_image'); $error = array(); - for ($i = 0; $i < $count; $i++) { - $image =& $image_handler->get($image_id[$i]); + for ($i = 0; $i < $count; $i++ ) { + $image = &$image_handler->get($image_id[$i]); if (!is_object($image)) { $error[] = sprintf(_FAILGETIMG, $image_id[$i]); continue; @@ -965,10 +960,10 @@ function imanager_updateimage() { } if ($changedCat) { $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get((int) $imgcat_id[$i]); + $imagecategory = &$imgcat_handler->get((int) $imgcat_id[$i]); $dest_categ_path = $imgcat_handler->getCategFolder($imagecategory); if ($imagecategory->getVar('imgcat_storetype') != 'db') { - $oldimgcategory =& $imgcat_handler->get((int) $oldcat); + $oldimgcategory = &$imgcat_handler->get((int) $oldcat); $src_categ_path = $imgcat_handler->getCategFolder($oldimgcategory); $src = $src_categ_path . '/' . $image->getVar('image_name'); $dest = $dest_categ_path . '/' . $image->getVar('image_name'); @@ -998,8 +993,9 @@ function imanager_updateimage() { /** * Logic and rendering for deleting an image - * @param int $image_id Unique ID for the image to be deleted - * @param int $redir Optional. If set, the image category to display after deleting the image + * + * @param int $image_id Unique ID for the image to be deleted + * @param int $redir Optional. If set, the image category to display after deleting the image */ function imanager_delfileok($image_id, $redir = NULL) { if (!icms::$security->check()) { @@ -1010,12 +1006,12 @@ function imanager_delfileok($image_id, $redir = NULL) { redirect_header('admin.php?fct=images', 1); } $image_handler = icms::handler('icms_image'); - $image =& $image_handler->get($image_id); + $image = &$image_handler->get($image_id); if (!is_object($image)) { redirect_header('admin.php?fct=images', 1); } $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get((int) $image->getVar('imgcat_id')); + $imagecategory = &$imgcat_handler->get((int) $image->getVar('imgcat_id')); $categ_path = $imgcat_handler->getCategFolder($imagecategory); if (!$image_handler->delete($image)) { icms_cp_header(); @@ -1034,7 +1030,8 @@ function imanager_delfileok($image_id, $redir = NULL) { /** * Function and script to display the add image form - * @param int $imgcat_id Unique ID for the image category for the new image + * + * @param int $imgcat_id Unique ID for the image category for the new image */ function showAddImgForm($imgcat_id) { $imgcat_handler = icms::handler('icms_image_category'); @@ -1071,20 +1068,20 @@ function imanager_clone() { global $imgcat_id, $image_nicename, $image_display, $image_weight, $image_id; $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($imgcat_id); + $imagecategory = &$imgcat_handler->get($imgcat_id); if (!is_object($imagecategory)) { redirect_header('admin.php?fct=images', 1); } $categ_path = $imgcat_handler->getCategFolder($imagecategory); $image_handler = icms::handler('icms_image'); - $image =& $image_handler->get($image_id); - if (($ext = strrpos($image->getVar('image_name'), '.' )) !== FALSE) { - $ext = strtolower(substr($image->getVar('image_name'), $ext + 1 )); + $image = &$image_handler->get($image_id); + if (($ext = strrpos($image->getVar('image_name'), '.')) !== FALSE) { + $ext = strtolower(substr($image->getVar('image_name'), $ext + 1)); } $imgname = 'img' . icms_random_str(12) . '.' . $ext; - $newimg =& $image_handler->create(); + $newimg = &$image_handler->create(); $newimg->setVar('image_name', $imgname); $newimg->setVar('image_nicename', $image_nicename); $newimg->setVar('image_mimetype', $image->getVar('image_mimetype')); @@ -1129,7 +1126,7 @@ function imanager_clone() { * @param str $style * @return str */ -function adminNav($id = NULL, $separador = "/", $list = FALSE, $style="style='font-weight:bold'") { +function adminNav($id = NULL, $separador = "/", $list = FALSE, $style = "style='font-weight:bold'") { $admin_url = ICMS_MODULES_URL . "/system/admin.php?fct=images"; if ($id === FALSE) { return FALSE; @@ -1137,7 +1134,7 @@ function adminNav($id = NULL, $separador = "/", $list = FALSE, $style="style='fo if ($id > 0) { $id = (int) $id; $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($id); + $imagecategory = &$imgcat_handler->get($id); if ($imagecategory->getVar('imgcat_id') > 0) { if ($list) { $ret = $imagecategory->getVar('imgcat_name'); @@ -1147,7 +1144,7 @@ function adminNav($id = NULL, $separador = "/", $list = FALSE, $style="style='fo if ($imagecategory->getVar('imgcat_pid') == 0) { return "" . _MD_IMGMAIN . " $separador " . $ret; } elseif ($imagecategory->getVar('imgcat_pid') > 0) { - $ret = adminNav($imagecategory->getVar('imgcat_pid'), $separador) . " $separador ". $ret; + $ret = adminNav($imagecategory->getVar('imgcat_pid'), $separador) . " $separador " . $ret; } } } else { @@ -1159,8 +1156,9 @@ function adminNav($id = NULL, $separador = "/", $list = FALSE, $style="style='fo /** * Alias for the redirect_header function - * @param int $imgcat_id Unique ID for the image category to display after the redirect - * @param str $msg Message to display in the redirect page/message box + * + * @param int $imgcat_id Unique ID for the image category to display after the redirect + * @param str $msg Message to display in the redirect page/message box */ function redir($imgcat_id, $msg = NULL) { redirect_header('admin.php?fct=images&op=listimg&imgcat_id=' . (int) $imgcat_id, 2, $msg); From f87002759fe881ea38bf2f7664cb9ca7ee063216 Mon Sep 17 00:00:00 2001 From: Steve Kenow Date: Wed, 14 Jun 2023 22:16:43 -0500 Subject: [PATCH 3/9] Changes needed in WideImage loading for the image editor --- .../modules/system/admin/images/browser.php | 154 +++++++++-------- .../modules/system/admin/images/preview.php | 161 +++++++++--------- 2 files changed, 157 insertions(+), 158 deletions(-) diff --git a/htdocs/modules/system/admin/images/browser.php b/htdocs/modules/system/admin/images/browser.php index 08122290531f..8655851ab03b 100644 --- a/htdocs/modules/system/admin/images/browser.php +++ b/htdocs/modules/system/admin/images/browser.php @@ -4,27 +4,28 @@ * * Used to create an instance of the image manager in a popup window to use with the dhmtl textarea object * - * @copyright The ImpressCMS Project http://www.impresscms.org/ - * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL) - * @package System - * @subpackage Images - * @since 1.2 - * @author Rodrigo Pereira Lima (aka TheRplima) - * @version SVN: $Id: browser.php 11963 2012-08-26 02:57:04Z skenow $ + * @copyright The ImpressCMS Project http://www.impresscms.org/ + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL) + * @package System + * @subpackage Images + * @since 1.2 + * @author Rodrigo Pereira Lima (aka TheRplima) + * @version SVN: $Id: browser.php 11963 2012-08-26 02:57:04Z skenow $ */ - include_once "../../../../mainfile.php"; if (!icms::$user) { redirect_header(ICMS_URL . '/', 6, _NOPERM); } +use WideImage\WideImage; + $icmsTpl = new icms_view_Tpl(); /* * GET variables - * (str) op: list (default), listimg, addcat, - * addfile, save, delfile, delfileok, cloneimg - * save_edit_ok + * (str) op: list (default), listimg, addcat, + * addfile, save, delfile, delfileok, cloneimg + * save_edit_ok * (int) limit * (int) start * (int) imgcat_id @@ -50,14 +51,9 @@ $imgcat_pid = $imgcat_maxsize = $imgcat_maxwidth = $imgcat_maxheight = 0; $imgcat_display = $imgcat_weight = 0; $type = 'ibrow'; -//$target = null; +// $target = null; -$filter_get = array( - 'limit' => 'int', - 'start' => 'int', - 'imgcat_id' => 'int', - 'image_id' => 'int', -); +$filter_get = array('limit' => 'int', 'start' => 'int', 'imgcat_id' => 'int', 'image_id' => 'int'); $filter_post = array( 'limit' => 'int', @@ -71,13 +67,12 @@ 'imgcat_display' => 'int', 'imgcat_weight' => 'int', 'readgroup' => 'int', - 'writegroup' => 'int', -); + 'writegroup' => 'int'); /* filter the user input */ if (!empty($_GET)) { // in places where strict mode is not used for checkVarArray, make sure filter_ vars are not overwritten - if (isset($_GET['filter_post'])) unset ($_GET['filter_post']); + if (isset($_GET['filter_post'])) unset($_GET['filter_post']); $clean_GET = icms_core_DataFilter::checkVarArray($_GET, $filter_get, FALSE); extract($clean_GET); } @@ -113,9 +108,9 @@ case 'delfile': icmsPopupHeader(); $image_handler = icms::handler('icms_image'); - $image =& $image_handler->get($image_id); + $image = &$image_handler->get($image_id); $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($image->getVar('imgcat_id')); + $imagecategory = &$imgcat_handler->get($image->getVar('imgcat_id')); $src = '
'; echo '
' . $src . '
'; icms_core_Message::confirm(array('op' => 'delfileok', 'image_id' => $image_id, 'imgcat_id' => $imgcat_id, 'target' => $target, 'type' => $type), 'browser.php', _MD_RUDELIMG); @@ -145,7 +140,8 @@ /** * index for the image manager - * @return string the fetched and constructed template + * + * @return string the fetched and constructed template */ function imanager_index($imgcat_id = NULL) { global $icmsTpl, $icmsConfig, $target, $type, $limit; @@ -154,7 +150,7 @@ function imanager_index($imgcat_id = NULL) { $groups = array(ICMS_GROUP_ANONYMOUS); $admin = FALSE; } else { - $groups =& icms::$user->getGroups(); + $groups = &icms::$user->getGroups(); $admin = (!icms::$user->isAdmin(1)) ? FALSE : TRUE; } @@ -183,7 +179,7 @@ function imanager_index($imgcat_id = NULL) { $criteriaRead->add(new icms_db_criteria_Item('imgcat_display', 1)); $id = (!is_null($imgcat_id) ? $imgcat_id : 0); $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $id)); - $imagecategorys =& $imgcat_handler->getObjects($criteriaRead); + $imagecategorys = &$imgcat_handler->getObjects($criteriaRead); $criteriaWrite = new icms_db_criteria_Compo(); if (is_array($groups) && !empty($groups)) { $criteriaWrite->add($criteriaTray); @@ -192,7 +188,7 @@ function imanager_index($imgcat_id = NULL) { } $criteriaWrite->add(new icms_db_criteria_Item('imgcat_display', 1)); $criteriaWrite->add(new icms_db_criteria_Item('imgcat_pid', $id)); - $imagecategorysWrite =& $imgcat_handler->getObjects($criteriaWrite); + $imagecategorysWrite = &$imgcat_handler->getObjects($criteriaWrite); $icmsTpl->assign('lang_imanager_title', _IMGMANAGER); $icmsTpl->assign('lang_imanager_catid', _MD_IMAGECATID); @@ -231,7 +227,7 @@ function imanager_index($imgcat_id = NULL) { $image_handler = icms::handler('icms_image'); $count = $msize = $subs = array(); $icmsTpl->assign('catcount', $catcount = count($imagecategorys)); - for ($i = 0; $i < $catcount; $i++) { + for ($i = 0; $i < $catcount; $i++ ) { $msize[$i] = icms_convert_size($imagecategorys[$i]->getVar('imgcat_maxsize')); $count[$i] = $image_handler->getCount(new icms_db_criteria_Item('imgcat_id', $imagecategorys[$i]->getVar('imgcat_id'))); $criteriaRead = new icms_db_criteria_Compo(); @@ -246,10 +242,10 @@ function imanager_index($imgcat_id = NULL) { } $id = (!is_null($imgcat_id) ? $imgcat_id : 0); $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $imagecategorys[$i]->getVar('imgcat_id'))); - $subs[$i] = count($imgcat_handler->getObjects($criteriaRead)); + $subs[$i] = count($imgcat_handler->getObjects($criteriaRead)); } $scount = array(); - foreach ($subs as $k=>$v) { + foreach ($subs as $k => $v) { $criteriaRead = new icms_db_criteria_Compo(); if (is_array($groups) && !empty($groups)) { $criteriaTray = new icms_db_criteria_Compo(); @@ -264,7 +260,7 @@ function imanager_index($imgcat_id = NULL) { $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $imagecategorys[$k]->getVar('imgcat_id'))); $ssubs = $imgcat_handler->getObjects($criteriaRead); $sc = 0; - foreach ($ssubs as $id=>$va) { + foreach ($ssubs as $id => $va) { $sc += $image_handler->getCount(new icms_db_criteria_Item('imgcat_id', $va->getVar('imgcat_id'))); } $scount[$k] = $sc; @@ -287,7 +283,7 @@ function imanager_index($imgcat_id = NULL) { $form->addElement(new icms_form_elements_Hidden('op', 'addfile')); $form->addElement(new icms_form_elements_Hidden('target', $target)); $form->addElement(new icms_form_elements_Hidden('type', $type)); - $tray = new icms_form_elements_Tray('' , ''); + $tray = new icms_form_elements_Tray('', ''); $tray->addElement(new icms_form_elements_Button('', 'img_button', _SUBMIT, 'submit')); $btn = new icms_form_elements_Button('', 'reset', _CANCEL, 'button'); $btn->setExtra('onclick="document.getElementById(\'addimgform\').style.display = \'none\'; return FALSE;"'); @@ -321,7 +317,7 @@ function imanager_index($imgcat_id = NULL) { $form->addElement(new icms_form_elements_Hidden('op', 'addcat')); $form->addElement(new icms_form_elements_Hidden('target', $target)); $form->addElement(new icms_form_elements_Hidden('type', $type)); - $tray1 = new icms_form_elements_Tray('' , ''); + $tray1 = new icms_form_elements_Tray('', ''); $tray1->addElement(new icms_form_elements_Button('', 'imgcat_button', _SUBMIT, 'submit')); $btn = new icms_form_elements_Button('', 'reset', _CANCEL, 'button'); $btn->setExtra('onclick="document.getElementById(\'addcatform\').style.display = \'none\'; return false;"'); @@ -334,9 +330,10 @@ function imanager_index($imgcat_id = NULL) { /** * The listing of the images for the image manager - * @param int $imgcat_id The imageCatID to get the listing for - * @param int $start The start offset to get the listing for - * @return string the fetched and construced template + * + * @param int $imgcat_id The imageCatID to get the listing for + * @param int $start The start offset to get the listing for + * @return string the fetched and construced template */ function imanager_listimg($imgcat_id, $start = 0) { global $icmsTpl, $target, $type, $query, $limit; @@ -345,7 +342,7 @@ function imanager_listimg($imgcat_id, $start = 0) { $groups = array(ICMS_GROUP_ANONYMOUS); $admin = FALSE; } else { - $groups =& icms::$user->getGroups(); + $groups = &icms::$user->getGroups(); $admin = (!icms::$user->isAdmin(1)) ? FALSE : TRUE; } @@ -355,9 +352,9 @@ function imanager_listimg($imgcat_id, $start = 0) { redirect_header('browser.php?op=list&target=' . $target . '&type=' . $type, 1, ''); } $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($imgcat_id); + $imagecategory = &$imgcat_handler->get($imgcat_id); $categ_path = $imgcat_handler->getCategFolder($imagecategory); - $categ_url = $imgcat_handler->getCategFolder($imagecategory, 1, 'url'); + $categ_url = $imgcat_handler->getCategFolder($imagecategory, 1, 'url'); if (!is_object($imagecategory)) { redirect_header('browser.php?op=list&target=' . $target . '&type=' . $type, 1); } @@ -403,7 +400,7 @@ function imanager_listimg($imgcat_id, $start = 0) { } $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $imagecategory->getVar('imgcat_id'))); $subcats = $imgcat_handler->getObjects($criteriaRead); - $subs = count($subcats); + $subs = count($subcats); $icmsTpl->assign('cat_subs', $subs); $image_handler = icms::handler('icms_image'); @@ -422,7 +419,7 @@ function imanager_listimg($imgcat_id, $start = 0) { $criteriaRead->add(new icms_db_criteria_Item('imgcat_pid', $imagecategory->getVar('imgcat_id'))); $ssubs = $imgcat_handler->getObjects($criteriaRead); $sc = 0; - foreach ($ssubs as $id=>$va) { + foreach ($ssubs as $id => $va) { $sc += $image_handler->getCount(new icms_db_criteria_Item('imgcat_id', $va->getVar('imgcat_id'))); } $scount = $sc; @@ -460,7 +457,7 @@ function imanager_listimg($imgcat_id, $start = 0) { $criteria->setOrder('DESC'); $criteria->setSort('image_weight'); $criteria->setLimit($limit); - $images =& $image_handler->getObjects($criteria, TRUE, TRUE); + $images = &$image_handler->getObjects($criteria, TRUE, TRUE); $icmsTpl->assign('imgcount', $imgcount); @@ -504,7 +501,7 @@ function imanager_listimg($imgcat_id, $start = 0) { $arrimg[$i]['src'] = $src . '?' . time(); $arrimg[$i]['url_src'] = str_replace(ICMS_URL, '', $src); $src_lightbox = ICMS_MODULES_URL . "/system/admin/images/preview.php?file=" . $images[$i]->getVar('image_name'); - $preview_url = '' . _PREVIEW . ''; + $preview_url = '' . _PREVIEW . ''; $arrimg[$i]['preview_link'] = $preview_url; $extra_perm = array("image/jpeg", "image/jpeg", "image/png", "image/gif"); @@ -551,7 +548,8 @@ function imanager_listimg($imgcat_id, $start = 0) { } /** - * This Method starts the parsing of the specified RDF File. The File can be a local or a remote File. + * This Method starts the parsing of the specified RDF File. + * The File can be a local or a remote File. * * @access * @author @@ -571,7 +569,7 @@ function imanager_addcat() { } $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->create(); + $imagecategory = &$imgcat_handler->create(); $imagecategory->setVar('imgcat_pid', $imgcat_pid); $imagecategory->setVar('imgcat_name', $imgcat_name); $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize); @@ -608,7 +606,7 @@ function imanager_addcat() { } foreach ($readgroup as $rgroup) { - $imagecategoryperm =& $imagecategoryperm_handler->create(); + $imagecategoryperm = &$imagecategoryperm_handler->create(); $imagecategoryperm->setVar('gperm_groupid', $rgroup); $imagecategoryperm->setVar('gperm_itemid', $newid); $imagecategoryperm->setVar('gperm_name', 'imgcat_read'); @@ -626,7 +624,7 @@ function imanager_addcat() { } foreach ($writegroup as $wgroup) { - $imagecategoryperm =& $imagecategoryperm_handler->create(); + $imagecategoryperm = &$imagecategoryperm_handler->create(); $imagecategoryperm->setVar('gperm_groupid', $wgroup); $imagecategoryperm->setVar('gperm_itemid', $newid); $imagecategoryperm->setVar('gperm_name', 'imgcat_write'); @@ -645,12 +643,12 @@ function imanager_addfile() { /* because we are using a function, the GET/POST variables are not in scope */ global $imgcat_id, $image_display, $image_weight, $image_nicename; - if (!icms::$security->check()) { + if (!icms::$security->check()) { redirect_header('browser.php?op=list&target=' . $target . '&type=' . $type, 3, implode('
', icms::$security->getErrors())); } $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($imgcat_id); + $imagecategory = &$imgcat_handler->get($imgcat_id); if (!is_object($imagecategory)) { redirect_header('browser.php?op=list&target=' . $target . '&type=' . $type, 1); } @@ -665,13 +663,13 @@ function imanager_addfile() { $uploader->setPrefix('img'); $err = array(); $ucount = count($_POST['xoops_upload_file']); - for ($i = 0; $i < $ucount; $i++) { + for ($i = 0; $i < $ucount; $i++ ) { if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) { if (!$uploader->upload()) { $err[] = $uploader->getErrors(); } else { $image_handler = icms::handler('icms_image'); - $image =& $image_handler->create(); + $image = &$image_handler->create(); $image->setVar('image_name', $uploader->getSavedFileName()); $image->setVar('image_nicename', $image_nicename); $image->setVar('image_mimetype', $uploader->getMediaType()); @@ -725,8 +723,8 @@ function imanager_updateimage() { if ($count > 0) { $image_handler = icms::handler('icms_image'); $error = array(); - for ($i = 0; $i < $count; $i++) { - $image =& $image_handler->get($image_id[$i]); + for ($i = 0; $i < $count; $i++ ) { + $image = &$image_handler->get($image_id[$i]); if (!is_object($image)) { $error[] = sprintf(_FAILGETIMG, $image_id[$i]); continue; @@ -747,10 +745,10 @@ function imanager_updateimage() { } if ($changedCat) { $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($imgcat_id[$i]); + $imagecategory = &$imgcat_handler->get($imgcat_id[$i]); $dest_categ_path = $imgcat_handler->getCategFolder($imagecategory); if ($imagecategory->getVar('imgcat_storetype') != 'db') { - $oldimgcategory =& $imgcat_handler->get($oldcat); + $oldimgcategory = &$imgcat_handler->get($oldcat); $src_categ_path = $imgcat_handler->getCategFolder($oldimgcategory); $src = $src_categ_path . '/' . $image->getVar('image_name'); $dest = $dest_categ_path . '/' . $image->getVar('image_name'); @@ -788,12 +786,12 @@ function imanager_delfileok($image_id, $redir = NULL) { redirect_header('browser.php?op=list&target=' . $target . '&type=' . $type, 1); } $image_handler = icms::handler('icms_image'); - $image =& $image_handler->get($image_id); + $image = &$image_handler->get($image_id); if (!is_object($image)) { redirect_header('browser.php?op=list&target=' . $target . '&type=' . $type, 1); } $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($image->getVar('imgcat_id')); + $imagecategory = &$imgcat_handler->get($image->getVar('imgcat_id')); $categ_path = $imgcat_handler->getCategFolder($imagecategory); if (!$image_handler->delete($image)) { icmsPopupHeader(); @@ -824,20 +822,20 @@ function imanager_clone() { global $imgcat_id, $image_nicename, $image_display, $image_weight, $image_id; $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($imgcat_id); + $imagecategory = &$imgcat_handler->get($imgcat_id); if (!is_object($imagecategory)) { redirect_header('browser.php?op=list&target=' . $target . '&type=' . $type, 1); } $categ_path = $imgcat_handler->getCategFolder($imagecategory); $image_handler = icms::handler('icms_image'); - $image =& $image_handler->get($image_id); + $image = &$image_handler->get($image_id); if (($ext = strrpos($image->getVar('image_name'), '.')) !== FALSE) { $ext = strtolower(substr($image->getVar('image_name'), $ext + 1)); } $imgname = 'img' . icms_random_str(12) . '.' . $ext; - $newimg =& $image_handler->create(); + $newimg = &$image_handler->create(); $newimg->setVar('image_name', $imgname); $newimg->setVar('image_nicename', $image_nicename); $newimg->setVar('image_mimetype', $image->getVar('image_mimetype')); @@ -878,20 +876,20 @@ function imanager_clone() { */ function icmsPopupHeader() { global $icmsConfig; - if (! headers_sent ()) { - header ('Content-Type:text/html; charset=' . _CHARSET); - header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); - header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT"); - header ('Cache-Control: no-store, no-cache, must-revalidate'); - header ("Cache-Control: post-check=0, pre-check=0", FALSE); - header ("Pragma: no-cache"); + if (!headers_sent()) { + header('Content-Type:text/html; charset=' . _CHARSET); + header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + header('Cache-Control: no-store, no-cache, must-revalidate'); + header("Cache-Control: post-check=0, pre-check=0", FALSE); + header("Pragma: no-cache"); } echo ""; echo ' - ' . htmlspecialchars ($icmsConfig ['sitename'], ENT_QUOTES) . ' - ' . _IMGMANAGER . ' + ' . htmlspecialchars($icmsConfig['sitename'], ENT_QUOTES) . ' - ' . _IMGMANAGER . ' ' . ' '; @@ -903,7 +901,7 @@ function icmsPopupHeader() { echo ''; } - #Adding necessary scripts + # Adding necessary scripts icms::$preload->triggerEvent('adminHeader'); icms::$preload->triggerEvent('adminBeforeFooter'); @@ -924,7 +922,7 @@ function icmsPopupFooter() { /** * Adding an image for the Image manager * - * @return string The constructed HTML form for the adding of an image + * @return string The constructed HTML form for the adding of an image */ function showAddImgForm($imgcat_id) { global $target, $type; @@ -942,7 +940,7 @@ function showAddImgForm($imgcat_id) { $form->addElement(new icms_form_elements_Hidden('op', 'addfile')); $form->addElement(new icms_form_elements_Hidden('target', $target)); $form->addElement(new icms_form_elements_Hidden('type', $type)); - $tray = new icms_form_elements_Tray('' , ''); + $tray = new icms_form_elements_Tray('', ''); $tray->addElement(new icms_form_elements_Button('', 'img_button', _SUBMIT, 'submit')); $btn = new icms_form_elements_Button('', 'reset', _CANCEL, 'button'); $btn->setExtra('onclick="document.getElementById(\'addimgform\').style.display = \'none\'; return FALSE;"'); @@ -954,9 +952,9 @@ function showAddImgForm($imgcat_id) { /** * Shows the admin navigation * - * @return string $ret the generated HTML for the admin navigation + * @return string $ret the generated HTML for the admin navigation */ -function adminNav($id = NULL, $separador = "/", $list = FALSE, $style="style='font-weight:bold'") { +function adminNav($id = NULL, $separador = "/", $list = FALSE, $style = "style='font-weight:bold'") { global $target, $type; $admin_url = 'browser.php?target=' . $target . '&type=' . $type; @@ -966,7 +964,7 @@ function adminNav($id = NULL, $separador = "/", $list = FALSE, $style="style='fo if ($id > 0) { $id = (int) $id; $imgcat_handler = icms::handler('icms_image_category'); - $imagecategory =& $imgcat_handler->get($id); + $imagecategory = &$imgcat_handler->get($id); if ($imagecategory->getVar('imgcat_id') > 0) { if ($list) { $ret = $imagecategory->getVar('imgcat_name'); @@ -975,8 +973,8 @@ function adminNav($id = NULL, $separador = "/", $list = FALSE, $style="style='fo } if ($imagecategory->getVar('imgcat_pid') == 0) { return "" . _MD_IMGMAIN . " $separador " . $ret; - }elseif ($imagecategory->getVar('imgcat_pid') > 0) { - $ret = adminNav($imagecategory->getVar('imgcat_pid'), $separador) . " $separador ". $ret; + } elseif ($imagecategory->getVar('imgcat_pid') > 0) { + $ret = adminNav($imagecategory->getVar('imgcat_pid'), $separador) . " $separador " . $ret; } } } else { @@ -989,8 +987,8 @@ function adminNav($id = NULL, $separador = "/", $list = FALSE, $style="style='fo /** * Redirect to the imagelisting showing a certain image catID and showing a certain message * - * @param string $imgcat_id - * @param string $msg + * @param string $imgcat_id + * @param string $msg */ function redir($imgcat_id, $msg = NULL) { global $target, $type; diff --git a/htdocs/modules/system/admin/images/preview.php b/htdocs/modules/system/admin/images/preview.php index 82feb53fb247..41292da12d54 100644 --- a/htdocs/modules/system/admin/images/preview.php +++ b/htdocs/modules/system/admin/images/preview.php @@ -1,80 +1,81 @@ -getObjects(new icms_db_criteria_Item('image_name', $file), FALSE, TRUE); -$imagecategory =& $imgcat_handler->get($image[0]->getVar('imgcat_id')); - -$categ_path = $imgcat_handler->getCategFolder($imagecategory); -$categ_url = $imgcat_handler->getCategFolder($imagecategory, 1, 'url'); - -if ($imagecategory->getVar('imgcat_storetype') == 'db') { - $img = WideImage::loadFromString($image[0]->getVar('image_body')); -} else { - $path = (substr($categ_path,-1) != '/') ? $categ_path . '/' : $categ_path; - $img = WideImage::load($path . $file); -} -$width = $img->getWidth(); -$height = $img->getHeight(); - -header('Content-type: image/png'); -if (NULL !== $filter) { - if ($filter == 'IMG_FILTER_SEPIA') { - if ($resize && ($width > 400 || $height > 300)) { - echo $img->resize(400, 300)->applyFilter(IMG_FILTER_GRAYSCALE)->applyFilter(IMG_FILTER_COLORIZE, 90, 60, 30)->asString('png'); - } else { - echo $img->applyFilter(IMG_FILTER_GRAYSCALE)->applyFilter(IMG_FILTER_COLORIZE, 90, 60, 30)->asString('png'); - } - } else { - if ($resize && ($width > 400 || $height > 300)) { - echo $img->resize(400, 300)->applyFilter(constant($filter), implode(',', $args))->asString('png'); - } else { - echo $img->applyFilter(constant($filter), implode(',', $args))->asString('png'); - } - } -} else { - if ($resize && ($width > 400 || $height > 300)) { - echo $img->resize(400, 300)->asString('png'); - } else { - echo $img->asString('png'); - } -} - +getObjects(new icms_db_criteria_Item('image_name', $file), FALSE, TRUE); +$imagecategory = &$imgcat_handler->get($image[0]->getVar('imgcat_id')); + +$categ_path = $imgcat_handler->getCategFolder($imagecategory); +$categ_url = $imgcat_handler->getCategFolder($imagecategory, 1, 'url'); + +if ($imagecategory->getVar('imgcat_storetype') == 'db') { + $img = WideImage::loadFromString($image[0]->getVar('image_body')); +} else { + $path = (substr($categ_path, -1) != '/') ? $categ_path . '/' : $categ_path; + $img = WideImage::load($path . $file); +} +$width = $img->getWidth(); +$height = $img->getHeight(); + +header('Content-type: image/png'); +if (NULL !== $filter) { + if ($filter == 'IMG_FILTER_SEPIA') { + if ($resize && ($width > 400 || $height > 300)) { + echo $img->resize(400, 300)->applyFilter(IMG_FILTER_GRAYSCALE)->applyFilter(IMG_FILTER_COLORIZE, 90, 60, 30)->asString('png'); + } else { + echo $img->applyFilter(IMG_FILTER_GRAYSCALE)->applyFilter(IMG_FILTER_COLORIZE, 90, 60, 30)->asString('png'); + } + } else { + if ($resize && ($width > 400 || $height > 300)) { + echo $img->resize(400, 300)->applyFilter(constant($filter), implode(',', $args))->asString('png'); + } else { + echo $img->applyFilter(constant($filter), implode(',', $args))->asString('png'); + } + } +} else { + if ($resize && ($width > 400 || $height > 300)) { + echo $img->resize(400, 300)->asString('png'); + } else { + echo $img->asString('png'); + } +} + From 1705137fbb542845caa21414e0138e937149e19e Mon Sep 17 00:00:00 2001 From: Steve Kenow Date: Wed, 14 Jun 2023 22:26:19 -0500 Subject: [PATCH 4/9] Actually adding the new WideImage library and updating smarty plugin --- htdocs/libraries/WideImage/Canvas.php | 161 +++ htdocs/libraries/WideImage/Coordinate.php | 198 ++++ .../WideImage/Exception/Exception.php | 32 + .../Exception/GDFunctionResultException.php | 10 + .../InvalidCanvasMethodException.php | 8 + .../Exception/InvalidCoordinateException.php | 8 + .../Exception/InvalidFontFileException.php | 8 + .../InvalidImageDimensionException.php | 10 + .../Exception/InvalidImageHandleException.php | 8 + .../Exception/InvalidImageSourceException.php | 8 + .../WideImage/Exception/NoFontException.php | 8 + .../UnknownErrorWhileMappingException.php | 10 + .../UnknownImageOperationException.php | 8 + .../Exception/UnsupportedFormatException.php | 10 + htdocs/libraries/WideImage/Font/GDF.php | 51 + htdocs/libraries/WideImage/Font/PS.php | 64 ++ htdocs/libraries/WideImage/Font/TTF.php | 79 ++ htdocs/libraries/WideImage/Image.php | 979 ++++++++++++++++++ htdocs/libraries/WideImage/LICENSE | 16 + htdocs/libraries/WideImage/Mapper/BMP.php | 53 + htdocs/libraries/WideImage/Mapper/GD.php | 46 + htdocs/libraries/WideImage/Mapper/GD2.php | 42 + htdocs/libraries/WideImage/Mapper/GIF.php | 52 + htdocs/libraries/WideImage/Mapper/JPEG.php | 42 + htdocs/libraries/WideImage/Mapper/PNG.php | 42 + htdocs/libraries/WideImage/Mapper/TGA.php | 50 + htdocs/libraries/WideImage/Mapper/WEBP.php | 43 + htdocs/libraries/WideImage/MapperFactory.php | 136 +++ .../WideImage/Operation/AddNoise.php | 167 +++ .../WideImage/Operation/ApplyConvolution.php | 54 + .../WideImage/Operation/ApplyFilter.php | 72 ++ .../WideImage/Operation/ApplyMask.php | 105 ++ .../WideImage/Operation/AsGrayscale.php | 55 + .../WideImage/Operation/AsNegative.php | 70 ++ .../WideImage/Operation/AutoCrop.php | 166 +++ .../Operation/CopyChannelsPalette.php | 98 ++ .../Operation/CopyChannelsTrueColor.php | 74 ++ .../WideImage/Operation/CorrectGamma.php | 52 + htdocs/libraries/WideImage/Operation/Crop.php | 96 ++ .../Exception/InvalidFitMethodException.php | 10 + .../InvalidResizeDimensionException.php | 10 + htdocs/libraries/WideImage/Operation/Flip.php | 60 ++ .../libraries/WideImage/Operation/GetMask.php | 76 ++ .../libraries/WideImage/Operation/Merge.php | 82 ++ .../libraries/WideImage/Operation/Mirror.php | 60 ++ .../libraries/WideImage/Operation/Resize.php | 166 +++ .../WideImage/Operation/ResizeCanvas.php | 109 ++ .../libraries/WideImage/Operation/Rotate.php | 71 ++ .../WideImage/Operation/RoundCorners.php | 124 +++ .../libraries/WideImage/Operation/Unsharp.php | 154 +++ .../libraries/WideImage/OperationFactory.php | 56 + htdocs/libraries/WideImage/PaletteImage.php | 150 +++ htdocs/libraries/WideImage/TrueColorImage.php | 293 ++++++ htdocs/libraries/WideImage/VERSION | 2 + htdocs/libraries/WideImage/WideImage.php | 372 +++++++ htdocs/libraries/WideImage/gpl.txt | 339 ++++++ htdocs/libraries/WideImage/index.html | 1 + htdocs/libraries/WideImage/lgpl.txt | 504 +++++++++ htdocs/libraries/WideImage/lib/Canvas.php | 167 +++ htdocs/libraries/WideImage/lib/Coordinate.php | 208 ++++ htdocs/libraries/WideImage/lib/Exception.php | 31 + htdocs/libraries/WideImage/lib/Font/GDF.php | 48 + htdocs/libraries/WideImage/lib/Font/PS.php | 60 ++ htdocs/libraries/WideImage/lib/Font/TTF.php | 75 ++ .../libraries/WideImage/lib/Font/index.html | 1 + htdocs/libraries/WideImage/lib/Image.php | 964 +++++++++++++++++ htdocs/libraries/WideImage/lib/Mapper/BMP.php | 51 + htdocs/libraries/WideImage/lib/Mapper/GD.php | 44 + htdocs/libraries/WideImage/lib/Mapper/GD2.php | 41 + htdocs/libraries/WideImage/lib/Mapper/GIF.php | 50 + .../libraries/WideImage/lib/Mapper/JPEG.php | 41 + htdocs/libraries/WideImage/lib/Mapper/PNG.php | 41 + htdocs/libraries/WideImage/lib/Mapper/TGA.php | 48 + .../libraries/WideImage/lib/Mapper/index.html | 1 + .../libraries/WideImage/lib/MapperFactory.php | 126 +++ .../WideImage/lib/Operation/AddNoise.php | 153 +++ .../lib/Operation/ApplyConvolution.php | 48 + .../WideImage/lib/Operation/ApplyFilter.php | 67 ++ .../WideImage/lib/Operation/ApplyMask.php | 105 ++ .../WideImage/lib/Operation/AsGrayscale.php | 49 + .../WideImage/lib/Operation/AsNegative.php | 63 ++ .../WideImage/lib/Operation/AutoCrop.php | 162 +++ .../lib/Operation/CopyChannelsPalette.php | 90 ++ .../lib/Operation/CopyChannelsTrueColor.php | 67 ++ .../WideImage/lib/Operation/CorrectGamma.php | 48 + .../WideImage/lib/Operation/Crop.php | 86 ++ .../WideImage/lib/Operation/Flip.php | 54 + .../WideImage/lib/Operation/GetMask.php | 67 ++ .../WideImage/lib/Operation/Merge.php | 78 ++ .../WideImage/lib/Operation/Mirror.php | 55 + .../WideImage/lib/Operation/Resize.php | 157 +++ .../WideImage/lib/Operation/ResizeCanvas.php | 107 ++ .../WideImage/lib/Operation/Rotate.php | 64 ++ .../WideImage/lib/Operation/RoundCorners.php | 114 ++ .../WideImage/lib/Operation/Unsharp.php | 135 +++ .../WideImage/lib/Operation/index.html | 1 + .../WideImage/lib/OperationFactory.php | 57 + .../libraries/WideImage/lib/PaletteImage.php | 136 +++ htdocs/libraries/WideImage/lib/README | 21 + .../WideImage/lib/TrueColorImage.php | 218 ++++ htdocs/libraries/WideImage/lib/VERSION | 2 + htdocs/libraries/WideImage/lib/WideImage.php | 377 +++++++ htdocs/libraries/WideImage/lib/gpl.txt | 339 ++++++ htdocs/libraries/WideImage/lib/index.html | 1 + htdocs/libraries/WideImage/lib/lgpl.txt | 504 +++++++++ .../WideImage/lib/vendor/JPEXS/bmp.php | 537 ++++++++++ .../WideImage/lib/vendor/JPEXS/ico.php | 965 +++++++++++++++++ .../WideImage/lib/vendor/JPEXS/index.html | 1 + .../WideImage/lib/vendor/de77/BMP.php | 264 +++++ .../WideImage/lib/vendor/de77/TGA.php | 206 ++++ .../WideImage/lib/vendor/de77/index.html | 1 + .../libraries/WideImage/lib/vendor/index.html | 1 + htdocs/libraries/WideImage/pax_global_header | 1 + .../libraries/WideImage/vendor/de77/BMP.php | 270 +++++ .../libraries/WideImage/vendor/de77/TGA.php | 193 ++++ .../icms_plugins/function.resized_image.php | 231 ++--- 116 files changed, 13804 insertions(+), 118 deletions(-) create mode 100644 htdocs/libraries/WideImage/Canvas.php create mode 100644 htdocs/libraries/WideImage/Coordinate.php create mode 100644 htdocs/libraries/WideImage/Exception/Exception.php create mode 100644 htdocs/libraries/WideImage/Exception/GDFunctionResultException.php create mode 100644 htdocs/libraries/WideImage/Exception/InvalidCanvasMethodException.php create mode 100644 htdocs/libraries/WideImage/Exception/InvalidCoordinateException.php create mode 100644 htdocs/libraries/WideImage/Exception/InvalidFontFileException.php create mode 100644 htdocs/libraries/WideImage/Exception/InvalidImageDimensionException.php create mode 100644 htdocs/libraries/WideImage/Exception/InvalidImageHandleException.php create mode 100644 htdocs/libraries/WideImage/Exception/InvalidImageSourceException.php create mode 100644 htdocs/libraries/WideImage/Exception/NoFontException.php create mode 100644 htdocs/libraries/WideImage/Exception/UnknownErrorWhileMappingException.php create mode 100644 htdocs/libraries/WideImage/Exception/UnknownImageOperationException.php create mode 100644 htdocs/libraries/WideImage/Exception/UnsupportedFormatException.php create mode 100644 htdocs/libraries/WideImage/Font/GDF.php create mode 100644 htdocs/libraries/WideImage/Font/PS.php create mode 100644 htdocs/libraries/WideImage/Font/TTF.php create mode 100644 htdocs/libraries/WideImage/Image.php create mode 100644 htdocs/libraries/WideImage/LICENSE create mode 100644 htdocs/libraries/WideImage/Mapper/BMP.php create mode 100644 htdocs/libraries/WideImage/Mapper/GD.php create mode 100644 htdocs/libraries/WideImage/Mapper/GD2.php create mode 100644 htdocs/libraries/WideImage/Mapper/GIF.php create mode 100644 htdocs/libraries/WideImage/Mapper/JPEG.php create mode 100644 htdocs/libraries/WideImage/Mapper/PNG.php create mode 100644 htdocs/libraries/WideImage/Mapper/TGA.php create mode 100644 htdocs/libraries/WideImage/Mapper/WEBP.php create mode 100644 htdocs/libraries/WideImage/MapperFactory.php create mode 100644 htdocs/libraries/WideImage/Operation/AddNoise.php create mode 100644 htdocs/libraries/WideImage/Operation/ApplyConvolution.php create mode 100644 htdocs/libraries/WideImage/Operation/ApplyFilter.php create mode 100644 htdocs/libraries/WideImage/Operation/ApplyMask.php create mode 100644 htdocs/libraries/WideImage/Operation/AsGrayscale.php create mode 100644 htdocs/libraries/WideImage/Operation/AsNegative.php create mode 100644 htdocs/libraries/WideImage/Operation/AutoCrop.php create mode 100644 htdocs/libraries/WideImage/Operation/CopyChannelsPalette.php create mode 100644 htdocs/libraries/WideImage/Operation/CopyChannelsTrueColor.php create mode 100644 htdocs/libraries/WideImage/Operation/CorrectGamma.php create mode 100644 htdocs/libraries/WideImage/Operation/Crop.php create mode 100644 htdocs/libraries/WideImage/Operation/Exception/InvalidFitMethodException.php create mode 100644 htdocs/libraries/WideImage/Operation/Exception/InvalidResizeDimensionException.php create mode 100644 htdocs/libraries/WideImage/Operation/Flip.php create mode 100644 htdocs/libraries/WideImage/Operation/GetMask.php create mode 100644 htdocs/libraries/WideImage/Operation/Merge.php create mode 100644 htdocs/libraries/WideImage/Operation/Mirror.php create mode 100644 htdocs/libraries/WideImage/Operation/Resize.php create mode 100644 htdocs/libraries/WideImage/Operation/ResizeCanvas.php create mode 100644 htdocs/libraries/WideImage/Operation/Rotate.php create mode 100644 htdocs/libraries/WideImage/Operation/RoundCorners.php create mode 100644 htdocs/libraries/WideImage/Operation/Unsharp.php create mode 100644 htdocs/libraries/WideImage/OperationFactory.php create mode 100644 htdocs/libraries/WideImage/PaletteImage.php create mode 100644 htdocs/libraries/WideImage/TrueColorImage.php create mode 100644 htdocs/libraries/WideImage/VERSION create mode 100644 htdocs/libraries/WideImage/WideImage.php create mode 100644 htdocs/libraries/WideImage/gpl.txt create mode 100644 htdocs/libraries/WideImage/index.html create mode 100644 htdocs/libraries/WideImage/lgpl.txt create mode 100755 htdocs/libraries/WideImage/lib/Canvas.php create mode 100755 htdocs/libraries/WideImage/lib/Coordinate.php create mode 100755 htdocs/libraries/WideImage/lib/Exception.php create mode 100755 htdocs/libraries/WideImage/lib/Font/GDF.php create mode 100755 htdocs/libraries/WideImage/lib/Font/PS.php create mode 100755 htdocs/libraries/WideImage/lib/Font/TTF.php create mode 100644 htdocs/libraries/WideImage/lib/Font/index.html create mode 100755 htdocs/libraries/WideImage/lib/Image.php create mode 100755 htdocs/libraries/WideImage/lib/Mapper/BMP.php create mode 100755 htdocs/libraries/WideImage/lib/Mapper/GD.php create mode 100755 htdocs/libraries/WideImage/lib/Mapper/GD2.php create mode 100755 htdocs/libraries/WideImage/lib/Mapper/GIF.php create mode 100755 htdocs/libraries/WideImage/lib/Mapper/JPEG.php create mode 100755 htdocs/libraries/WideImage/lib/Mapper/PNG.php create mode 100644 htdocs/libraries/WideImage/lib/Mapper/TGA.php create mode 100644 htdocs/libraries/WideImage/lib/Mapper/index.html create mode 100755 htdocs/libraries/WideImage/lib/MapperFactory.php create mode 100644 htdocs/libraries/WideImage/lib/Operation/AddNoise.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/ApplyConvolution.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/ApplyFilter.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/ApplyMask.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/AsGrayscale.php create mode 100644 htdocs/libraries/WideImage/lib/Operation/AsNegative.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/AutoCrop.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/CopyChannelsPalette.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/CopyChannelsTrueColor.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/CorrectGamma.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/Crop.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/Flip.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/GetMask.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/Merge.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/Mirror.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/Resize.php create mode 100644 htdocs/libraries/WideImage/lib/Operation/ResizeCanvas.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/Rotate.php create mode 100644 htdocs/libraries/WideImage/lib/Operation/RoundCorners.php create mode 100755 htdocs/libraries/WideImage/lib/Operation/Unsharp.php create mode 100644 htdocs/libraries/WideImage/lib/Operation/index.html create mode 100755 htdocs/libraries/WideImage/lib/OperationFactory.php create mode 100755 htdocs/libraries/WideImage/lib/PaletteImage.php create mode 100644 htdocs/libraries/WideImage/lib/README create mode 100755 htdocs/libraries/WideImage/lib/TrueColorImage.php create mode 100644 htdocs/libraries/WideImage/lib/VERSION create mode 100755 htdocs/libraries/WideImage/lib/WideImage.php create mode 100644 htdocs/libraries/WideImage/lib/gpl.txt create mode 100644 htdocs/libraries/WideImage/lib/index.html create mode 100644 htdocs/libraries/WideImage/lib/lgpl.txt create mode 100755 htdocs/libraries/WideImage/lib/vendor/JPEXS/bmp.php create mode 100755 htdocs/libraries/WideImage/lib/vendor/JPEXS/ico.php create mode 100644 htdocs/libraries/WideImage/lib/vendor/JPEXS/index.html create mode 100644 htdocs/libraries/WideImage/lib/vendor/de77/BMP.php create mode 100644 htdocs/libraries/WideImage/lib/vendor/de77/TGA.php create mode 100644 htdocs/libraries/WideImage/lib/vendor/de77/index.html create mode 100644 htdocs/libraries/WideImage/lib/vendor/index.html create mode 100644 htdocs/libraries/WideImage/pax_global_header create mode 100755 htdocs/libraries/WideImage/vendor/de77/BMP.php create mode 100644 htdocs/libraries/WideImage/vendor/de77/TGA.php diff --git a/htdocs/libraries/WideImage/Canvas.php b/htdocs/libraries/WideImage/Canvas.php new file mode 100644 index 000000000000..33baf421098d --- /dev/null +++ b/htdocs/libraries/WideImage/Canvas.php @@ -0,0 +1,161 @@ +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() + */ + public 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 + */ + public 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 Font\TTF($file, $size, $color); + } elseif ($ext == 'ps') { + $font = new Font\PS($file, $size, $color, $bgcolor); + } elseif ($ext == 'gdf') { + $font = new Font\GDF($file, $color); + } else { + throw new 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: + * + * $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'); + * + * + * @param int $x Left + * @param int $y Top + * @param string $text Text to write + * @param int $angle The angle, defaults to 0 + */ + public function writeText($x, $y, $text, $angle = 0) + { + if ($this->font === null) { + throw new 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: + * + * $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)); + * + */ + function __call($method, $params) + { + if (function_exists('image' . $method)) { + array_unshift($params, $this->handle); + call_user_func_array('image' . $method, $params); + } else { + throw new InvalidCanvasMethodException("Function doesn't exist: image{$method}."); + } + } +} diff --git a/htdocs/libraries/WideImage/Coordinate.php b/htdocs/libraries/WideImage/Coordinate.php new file mode 100644 index 000000000000..8390c5113746 --- /dev/null +++ b/htdocs/libraries/WideImage/Coordinate.php @@ -0,0 +1,198 @@ + '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 + */ + public 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 + */ + public 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 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 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; + } +} diff --git a/htdocs/libraries/WideImage/Exception/Exception.php b/htdocs/libraries/WideImage/Exception/Exception.php new file mode 100644 index 000000000000..77b71ce4432b --- /dev/null +++ b/htdocs/libraries/WideImage/Exception/Exception.php @@ -0,0 +1,32 @@ += 1 && $face <= 5) { + $this->font = $face; + } else { + $this->font = imageloadfont($face); + } + + $this->color = $color; + } + + public function writeText($image, $x, $y, $text) + { + imagestring($image->getHandle(), $this->font, $x, $y, $text, $this->color); + } +} diff --git a/htdocs/libraries/WideImage/Font/PS.php b/htdocs/libraries/WideImage/Font/PS.php new file mode 100644 index 000000000000..461523982978 --- /dev/null +++ b/htdocs/libraries/WideImage/Font/PS.php @@ -0,0 +1,64 @@ +handle = imagepsloadfont($file); + $this->size = $size; + $this->color = $color; + + if ($bgcolor === null) { + $this->bgcolor = $color; + } else { + $this->color = $color; + } + } + + public 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); + } + + public function __destruct() + { + imagepsfreefont($this->handle); + $this->handle = null; + } +} diff --git a/htdocs/libraries/WideImage/Font/TTF.php b/htdocs/libraries/WideImage/Font/TTF.php new file mode 100644 index 000000000000..34c97bbfa231 --- /dev/null +++ b/htdocs/libraries/WideImage/Font/TTF.php @@ -0,0 +1,79 @@ +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 + */ + public 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 = Coordinate::fix($x, $image->getWidth(), $obox['width']); + $y = 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); + } +} diff --git a/htdocs/libraries/WideImage/Image.php b/htdocs/libraries/WideImage/Image.php new file mode 100644 index 000000000000..49999c6053ea --- /dev/null +++ b/htdocs/libraries/WideImage/Image.php @@ -0,0 +1,979 @@ +handle = $handle; + } + + /** + * Cleanup + * + * Destroys the handle via \WideImage\Image::destroy() when called by the GC. + */ + public 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. + */ + public function destroy() + { + if ($this->isValid() && !$this->handleReleased) { + imagedestroy($this->handle); + } + + $this->handle = null; + } + + /** + * Returns the GD image resource + * + * @return resource GD image resource + */ + public function getHandle() + { + return $this->handle; + } + + /** + * @return bool True, if the image object holds a valid GD image, false otherwise + */ + public function isValid() + { + return WideImage::isValidImageHandle($this->handle); + } + + /** + * Releases the handle + */ + public 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: + * + * // 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'); + * + * + * @param string $uri File location + */ + public function saveToFile($uri) + { + $mapper = 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 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 + */ + public function asString($format) + { + ob_start(); + $args = func_get_args(); + $args[0] = null; + array_unshift($args, $this->getHandle()); + + $mapper = MapperFactory::selectMapper(null, $format); + $res = call_user_func_array(array($mapper, 'save'), $args); + + if (!$res) { + throw new 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: + * + * WideImage::load('image1.png')->resize(100, 100)->output('gif'); + * + * + * @param string $format Image format + */ + public 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', MapperFactory::mimeType($format)); + echo $data; + } + + /** + * @return int Image width + */ + public function getWidth() + { + return imagesx($this->handle); + } + + /** + * @return int Image height + */ + public 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 + */ + public function allocateColor($R, $G = null, $B = null) + { + if (is_array($R)) { + return imageColorAllocate($this->handle, $R['red'], $R['green'], $R['blue']); + } + + return imageColorAllocate($this->handle, $R, $G, $B); + } + + /** + * @return bool True if the image is transparent, false otherwise + */ + public function isTransparent() + { + return $this->getTransparentColor() >= 0; + } + + /** + * @return int Transparent color index + */ + public 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 + */ + public 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 + */ + public function getTransparentColorRGB() + { + $total = imagecolorstotal($this->handle); + $tc = $this->getTransparentColor(); + + if ($tc >= $total && $total > 0) { + return null; + } + + return $this->getColorRGB($tc); + } + + /** + * Returns a RGBA array for pixel at $x, $y + * + * @param int $x + * @param int $y + * @return array RGB array + */ + public 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 + */ + public 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 + */ + public 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 + */ + public 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 + */ + public 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 + */ + public function getClosestColor($R, $G = null, $B = null) + { + if (is_array($R)) { + return imagecolorclosest($this->handle, $R['red'], $R['green'], $R['blue']); + } + + 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 + */ + public function getExactColor($R, $G = null, $B = null) + { + if (is_array($R)) { + return imagecolorexact($this->handle, $R['red'], $R['green'], $R['blue']); + } + + 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 + */ + public 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 + */ + public 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 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 + **/ + public 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%, ...) + * - null: if one dimension is null, it's calculated proportionally from the other. + * + * $fit parameter can be set to one of these three values: + * - 'inside': resize proportionally and fit the resulting image tightly in the $width x $height box + * - 'outside': resize proportionally and fit the resulting image tighly outside the box + * - 'fill': resize the image to fill the $width x $height box exactly + * + * $scale parameter can be: + * - 'down': only resize the image if it's larger than the $width x $height box + * - 'up': only resize the image if it's smaller than the $width x $height box + * - 'any': resize the image + * + * Example (resize to half-size): + * + * $smaller = $image->resize('50%'); + * + * $smaller = $image->resize('100', '100', 'inside', 'down'); + * is the same as + * $smaller = $image->resizeDown(100, 100, 'inside'); + * + * + * @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 + */ + public 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 + */ + public 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 + */ + public 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 + */ + public 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: + * + * $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 + * + * + * @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 + */ + public 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]. + * + * $image = WideImage::load('someimage.jpg'); // 100x150 + * $white = $image->allocateColor(255, 255, 255); + * $image->resizeCanvas('200%', '100% + 20', 10, 'center+20', $white); + * + * + * 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 + */ + public 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: + * + * $nice = $ugly->roundCorners(20, $ugly->allocateColor(255, 0, 0), 2); + * + * + * 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: + * + * $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); + * + * + * @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 + */ + public 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 + **/ + public 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 + */ + public 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 + */ + public 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: + * + * $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 + * + * + * This operation supports alignment notation in left/top coordinates. + * Example: + * + * $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 + * + * + * @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 + **/ + public 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 + */ + public 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 + */ + public function asNegative() + { + return $this->getOperation('AsNegative')->execute($this); + } + + /** + * Returns a grayscale copy of the image + * + * @return \WideImage\Image grayscale copy + **/ + public function asGrayscale() + { + return $this->getOperation('AsGrayscale')->execute($this); + } + + /** + * Returns a mirrored copy of the image + * + * @return \WideImage\Image Mirrored copy + **/ + public 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 + **/ + public 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 + **/ + public 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 + **/ + public 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 + **/ + public 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 + */ + public 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 + */ + public function __toString() + { + if ($this->isTransparent()) { + return $this->asString('gif'); + } + + return $this->asString('png'); + } + + /** + * Returns a copy of the image object + * + * @return \WideImage\Image The copy + **/ + public 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 + **/ + public function copyTo($dest, $left = 0, $top = 0) + { + if (!imagecopy($dest->getHandle(), $this->handle, $left, $top, 0, 0, $this->getWidth(), $this->getHeight())) { + throw new GDFunctionResultException("imagecopy() returned false"); + } + } + + /** + * Returns the canvas object + * + * The Canvas object can be used to draw text and shapes on the image + * + * Examples: + * + * $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'); + * + * + * @return \WideImage\Canvas The Canvas object + **/ + function getCanvas() + { + if ($this->canvas == null) { + $this->canvas = new Canvas($this); + } + + return $this->canvas; + } + + /** + * Returns true if the image is true-color, false otherwise + * + * @return bool + **/ + abstract public function isTrueColor(); + + /** + * Returns a true-color copy of the image + * + * @return \WideImage\TrueColorImage + **/ + abstract public 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 public function asPalette($nColors = 255, $dither = null, $matchPalette = true); + + /** + * Retrieve an image with selected channels + * + * Examples: + * + * $channels = $img->getChannels('red', 'blue'); + * $channels = $img->getChannels('alpha', 'green'); + * $channels = $img->getChannels(array('green', 'blue')); + * + * + * @return \WideImage\Image + **/ + abstract public function getChannels(); + + /** + * Returns an image without an alpha channel + * + * @return \WideImage\Image + **/ + abstract public function copyNoAlpha(); + + /** + * Returns an array of serializable protected variables. Called automatically upon serialize(). + * + * @return array + */ + public function __sleep() + { + $this->sdata = $this->asString('png'); + + return array('sdata', 'handleReleased'); + } + + /** + * Restores an image from serialization. Called automatically upon unserialize(). + */ + public function __wakeup() + { + $temp_image = WideImage::loadFromString($this->sdata); + $temp_image->releaseHandle(); + $this->handle = $temp_image->handle; + $temp_image = null; + $this->sdata = null; + } +} diff --git a/htdocs/libraries/WideImage/LICENSE b/htdocs/libraries/WideImage/LICENSE new file mode 100644 index 000000000000..0da1ec13a528 --- /dev/null +++ b/htdocs/libraries/WideImage/LICENSE @@ -0,0 +1,16 @@ +WideImage, a PHP image manipulation library +Copyright 2007-2016 Gasper Kozak + +This program 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 program 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 program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/htdocs/libraries/WideImage/Mapper/BMP.php b/htdocs/libraries/WideImage/Mapper/BMP.php new file mode 100644 index 000000000000..58afbed96042 --- /dev/null +++ b/htdocs/libraries/WideImage/Mapper/BMP.php @@ -0,0 +1,53 @@ + 'JPEG', + 'image/jpeg' => 'JPEG', + 'image/pjpeg' => 'JPEG', + 'image/gif' => 'GIF', + 'image/png' => 'PNG', + 'image/webp' => 'WEBP' + ); + + /** + * Returns a mapper, based on the $uri and $format + * + * @param string $uri File URI + * @param string $format File format (extension or mime-type) or null + * @return mixed + **/ + public static function selectMapper($uri, $format = null) + { + $format = self::determineFormat($uri, $format); + + if (empty($format)) { + return false; + } + + if (array_key_exists($format, self::$mappers)) { + return self::$mappers[$format]; + } + + $mapperClassName = '\\WideImage\\Mapper\\' . $format; + + // why not use autoloading? + // if (!class_exists($mapperClassName, false)) { + if (!class_exists($mapperClassName)) { + throw new UnsupportedFormatException("Format '{$format}' is not supported."); + } + + if (class_exists($mapperClassName)) { + self::$mappers[$format] = new $mapperClassName(); + return self::$mappers[$format]; + } + } + + public static function registerMapper($mapper_class_name, $mime_type, $extension) + { + self::$customMappers[$mime_type] = $mapper_class_name; + self::$mimeTable[$mime_type] = $extension; + } + + public static function getCustomMappers() + { + return self::$customMappers; + } + + public static function determineFormat($uri, $format = null) + { + if ($format == null) { + $format = self::extractExtension($uri); + } + + // mime-type match + if (preg_match('~[a-z]*/[a-z-]*~i', $format)) { + if (isset(self::$mimeTable[strtolower($format)])) { + return self::$mimeTable[strtolower($format)]; + } + } + + // clean the string + $format = strtoupper(preg_replace('/[^a-z0-9_-]/i', '', $format)); + if ($format == 'JPG') { + $format = 'JPEG'; + } + + return $format; + } + + public static function mimeType($format) + { + $format = strtoupper($format); + + if ($format == 'JPG') { + $format = 'JPEG'; + } + + return array_search($format, self::$mimeTable); + } + + public static function extractExtension($uri) + { + $p = strrpos($uri, '.'); + + if ($p === false) { + return ''; + } + + return substr($uri, $p + 1); + } +} diff --git a/htdocs/libraries/WideImage/Operation/AddNoise.php b/htdocs/libraries/WideImage/Operation/AddNoise.php new file mode 100644 index 000000000000..bacf2c2f90fc --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/AddNoise.php @@ -0,0 +1,167 @@ +asTrueColor(), $fun, $amount); + } + + /** + * Returns image with every pixel changed by specififed function + * + * @param \WideImage\Image $image + * @param str $function + * @param int $value + * @return \WideImage\Image + */ + public function filter($image, $function, $value) + { + for ($y = 0; $y < $image->getHeight(); $y++) { + for ($x = 0; $x< $image->getWidth(); $x++) { + $rgb = imagecolorat($image->getHandle(), $x, $y); + + $a = ($rgb >> 24) & 0xFF; + $r = ($rgb >> 16) & 0xFF; + $g = ($rgb >> 8) & 0xFF; + $b = $rgb & 0xFF; + + static::$function($r, $g, $b, $value); + + $color = imagecolorallocatealpha($image->getHandle(), $r, $g, $b, $a); + imagesetpixel($image->getHandle(), $x, $y, $color); + } + } + + return $image; + } + + /** + * Adds color noise by altering given R,G,B values using specififed amount + * + * @param int $r + * @param int $g + * @param int $b + * @param int $value + * @return void + */ + public function colorNoise_fun(&$r, &$g, &$b, $amount) + { + $r = static::byte($r + mt_rand(0, $amount) - ($amount >> 1) ); + $g = static::byte($g + mt_rand(0, $amount) - ($amount >> 1) ); + $b = static::byte($b + mt_rand(0, $amount) - ($amount >> 1) ); + } + + /** + * Adds mono noise by altering given R,G,B values using specififed amount + * + * @param int $r + * @param int $g + * @param int $b + * @param int $value + * @return void + */ + public function monoNoise_fun(&$r, &$g, &$b, $amount) + { + $rand = mt_rand(0, $amount) - ($amount >> 1); + + $r = static::byte($r + $rand); + $g = static::byte($g + $rand); + $b = static::byte($b + $rand); + } + + /** + * Adds salt&pepper noise by altering given R,G,B values using specififed amount + * + * @param int $r + * @param int $g + * @param int $b + * @param int $value + * @return void + */ + public function saltPepperNoise_fun(&$r, &$g, &$b, $amount) + { + if (mt_rand(0, 255 - $amount) != 0) { + return; + } + + $rand = mt_rand(0, 1); + + switch ($rand) { + case 0: + $r = $g = $b = 0; + break; + case 1: + $r = $g = $b = 255; + break; + } + } + + /** + * Returns value within (0,255) + * + * @param int $b + * @return int + */ + public function byte($b) + { + if ($b > 255) { + return 255; + } + + if ($b < 0) { + return 0; + } + + return (int) $b; + } +} diff --git a/htdocs/libraries/WideImage/Operation/ApplyConvolution.php b/htdocs/libraries/WideImage/Operation/ApplyConvolution.php new file mode 100644 index 000000000000..ab803d93c34c --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/ApplyConvolution.php @@ -0,0 +1,54 @@ +asTrueColor(); + + if (!imageconvolution($new->getHandle(), $matrix, $div, $offset)) { + throw new GDFunctionResultException("imageconvolution() returned false"); + } + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/ApplyFilter.php b/htdocs/libraries/WideImage/Operation/ApplyFilter.php new file mode 100644 index 000000000000..3c7d28f04489 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/ApplyFilter.php @@ -0,0 +1,72 @@ +asTrueColor(); + + if (in_array($filter, static::$one_arg_filters)) { + $res = imagefilter($new->getHandle(), $filter, $arg1); + } elseif (defined('IMG_FILTER_PIXELATE') && $filter == IMG_FILTER_PIXELATE) { + $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2); + } elseif ($filter == IMG_FILTER_COLORIZE) { + $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2, $arg3, $arg4); + } else { + $res = imagefilter($new->getHandle(), $filter); + } + + if (!$res) { + throw new GDFunctionResultException("imagefilter() returned false"); + } + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/ApplyMask.php b/htdocs/libraries/WideImage/Operation/ApplyMask.php new file mode 100644 index 000000000000..40c9af2cd890 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/ApplyMask.php @@ -0,0 +1,105 @@ +getWidth(), $mask->getWidth()); + $top = Coordinate::fix($top, $image->getHeight(), $mask->getHeight()); + + $width = $image->getWidth(); + $mask_width = $mask->getWidth(); + + $height = $image->getHeight(); + $mask_height = $mask->getHeight(); + + $result = $image->asTrueColor(); + + $result->alphaBlending(false); + $result->saveAlpha(true); + + $srcTransparentColor = $result->getTransparentColor(); + + if ($srcTransparentColor >= 0) { + $destTransparentColor = $srcTransparentColor; + } else { + $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127); + } + + for ($x = 0; $x < $width; $x++) { + for ($y = 0; $y < $height; $y++) { + $mx = $x - $left; + $my = $y - $top; + + if ($mx >= 0 && $mx < $mask_width && $my >= 0 && $my < $mask_height) { + $srcColor = $image->getColorAt($x, $y); + + if ($srcColor == $srcTransparentColor) { + $destColor = $destTransparentColor; + } else { + $maskRGB = $mask->getRGBAt($mx, $my); + + if ($maskRGB['red'] == 0) { + $destColor = $destTransparentColor; + } elseif ($srcColor >= 0) { + $imageRGB = $image->getRGBAt($x, $y); + $level = ($maskRGB['red'] / 255) * (1 - $imageRGB['alpha'] / 127); + $imageRGB['alpha'] = 127 - round($level * 127); + + if ($imageRGB['alpha'] == 127) { + $destColor = $destTransparentColor; + } else { + $destColor = $result->allocateColorAlpha($imageRGB); + } + } else { + $destColor = $destTransparentColor; + } + } + + $result->setColorAt($x, $y, $destColor); + } + } + } + + return $result; + } +} diff --git a/htdocs/libraries/WideImage/Operation/AsGrayscale.php b/htdocs/libraries/WideImage/Operation/AsGrayscale.php new file mode 100644 index 000000000000..0914895acca1 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/AsGrayscale.php @@ -0,0 +1,55 @@ +asTrueColor(); + + if (!imagefilter($new->getHandle(), IMG_FILTER_GRAYSCALE)) { + throw new GDFunctionResultException("imagefilter() returned false"); + } + + if (!$image->isTrueColor()) { + $new = $new->asPalette(); + } + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/AsNegative.php b/htdocs/libraries/WideImage/Operation/AsNegative.php new file mode 100644 index 000000000000..adad0ff9731e --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/AsNegative.php @@ -0,0 +1,70 @@ +isTrueColor(); + $transparent = $image->isTransparent(); + + if ($palette && $transparent) { + $tcrgb = $image->getTransparentColorRGB(); + } + + $new = $image->asTrueColor(); + + if (!imagefilter($new->getHandle(), IMG_FILTER_NEGATE)) { + throw new GDFunctionResultException("imagefilter() returned false"); + } + + if ($palette) { + $new = $new->asPalette(); + + if ($transparent) { + $irgb = array('red' => 255 - $tcrgb['red'], 'green' => 255 - $tcrgb['green'], 'blue' => 255 - $tcrgb['blue'], 'alpha' => 127); + + // needs imagecolorexactalpha instead of imagecolorexact, otherwise doesn't work on some transparent GIF images + $new_tci = imagecolorexactalpha($new->getHandle(), $irgb['red'], $irgb['green'], $irgb['blue'], 127); + $new->setTransparentColor($new_tci); + } + } + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/AutoCrop.php b/htdocs/libraries/WideImage/Operation/AutoCrop.php new file mode 100644 index 000000000000..f8b8cc801906 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/AutoCrop.php @@ -0,0 +1,166 @@ +getRGBAt(0, 0); + } else { + if ($base_color < 0) { + return $img->copy(); + } + + $rgb_base = $img->getColorRGB($base_color); + } + + $cut_rect = array('left' => 0, 'top' => 0, 'right' => $img->getWidth() - 1, 'bottom' => $img->getHeight() - 1); + + for ($y = 0; $y <= $cut_rect['bottom']; $y++) { + $count = 0; + + for ($x = 0; $x <= $cut_rect['right']; $x++) { + $rgb = $img->getRGBAt($x, $y); + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); + + if ($diff > $rgb_threshold) { + $count++; + + if ($count >= $pixel_cutoff) { + $cut_rect['top'] = $y; + break 2; + } + } + } + } + + for ($y = $img->getHeight() - 1; $y >= $cut_rect['top']; $y--) { + $count = 0; + + for ($x = 0; $x <= $cut_rect['right']; $x++) { + $rgb = $img->getRGBAt($x, $y); + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); + + if ($diff > $rgb_threshold) { + $count++; + + if ($count >= $pixel_cutoff) { + $cut_rect['bottom'] = $y; + break 2; + } + } + } + } + + for ($x = 0; $x <= $cut_rect['right']; $x++) { + $count = 0; + + for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) { + $rgb = $img->getRGBAt($x, $y); + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); + + if ($diff > $rgb_threshold) { + $count++; + + if ($count >= $pixel_cutoff) { + $cut_rect['left'] = $x; + break 2; + } + } + } + } + + for ($x = $cut_rect['right']; $x >= $cut_rect['left']; $x--) { + $count = 0; + + for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) { + $rgb = $img->getRGBAt($x, $y); + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); + + if ($diff > $rgb_threshold) { + $count++; + + if ($count >= $pixel_cutoff) { + $cut_rect['right'] = $x; + break 2; + } + } + } + } + + $cut_rect = array( + 'left' => $cut_rect['left'] - $margin, + 'top' => $cut_rect['top'] - $margin, + 'right' => $cut_rect['right'] + $margin, + 'bottom' => $cut_rect['bottom'] + $margin + ); + + if ($cut_rect['left'] < 0) { + $cut_rect['left'] = 0; + } + + if ($cut_rect['top'] < 0) { + $cut_rect['top'] = 0; + } + + if ($cut_rect['right'] >= $img->getWidth()) { + $cut_rect['right'] = $img->getWidth() - 1; + } + + if ($cut_rect['bottom'] >= $img->getHeight()) { + $cut_rect['bottom'] = $img->getHeight() - 1; + } + + return $img->crop($cut_rect['left'], $cut_rect['top'], $cut_rect['right'] - $cut_rect['left'] + 1, $cut_rect['bottom'] - $cut_rect['top'] + 1); + } +} diff --git a/htdocs/libraries/WideImage/Operation/CopyChannelsPalette.php b/htdocs/libraries/WideImage/Operation/CopyChannelsPalette.php new file mode 100644 index 000000000000..7f419d5771c3 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/CopyChannelsPalette.php @@ -0,0 +1,98 @@ + 0, 'green' => 0, 'blue' => 0); + + if (isset($channels['alpha'])) { + unset($channels['alpha']); + } + + $width = $img->getWidth(); + $height = $img->getHeight(); + $copy = PaletteImage::create($width, $height); + + if ($img->isTransparent()) { + $otci = $img->getTransparentColor(); + $TRGB = $img->getColorRGB($otci); + $tci = $copy->allocateColor($TRGB); + } else { + $otci = null; + $tci = null; + } + + for ($x = 0; $x < $width; $x++) { + for ($y = 0; $y < $height; $y++) { + $ci = $img->getColorAt($x, $y); + + if ($ci === $otci) { + $copy->setColorAt($x, $y, $tci); + continue; + } + + $RGB = $img->getColorRGB($ci); + + $newRGB = $blank; + + foreach ($channels as $channel) { + $newRGB[$channel] = $RGB[$channel]; + } + + $color = $copy->getExactColor($newRGB); + + if ($color == -1) { + $color = $copy->allocateColor($newRGB); + } + + $copy->setColorAt($x, $y, $color); + } + } + + if ($img->isTransparent()) { + $copy->setTransparentColor($tci); + } + + return $copy; + } +} diff --git a/htdocs/libraries/WideImage/Operation/CopyChannelsTrueColor.php b/htdocs/libraries/WideImage/Operation/CopyChannelsTrueColor.php new file mode 100644 index 000000000000..fbf2cb051319 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/CopyChannelsTrueColor.php @@ -0,0 +1,74 @@ + 0, 'green' => 0, 'blue' => 0, 'alpha' => 0); + + $width = $img->getWidth(); + $height = $img->getHeight(); + $copy = TrueColorImage::create($width, $height); + + if (count($channels) > 0) { + for ($x = 0; $x < $width; $x++) { + for ($y = 0; $y < $height; $y++) { + $RGBA = $img->getRGBAt($x, $y); + $newRGBA = $blank; + + foreach ($channels as $channel) { + $newRGBA[$channel] = $RGBA[$channel]; + } + + $color = $copy->getExactColorAlpha($newRGBA); + + if ($color == -1) { + $color = $copy->allocateColorAlpha($newRGBA); + } + + $copy->setColorAt($x, $y, $color); + } + } + } + + return $copy; + } +} diff --git a/htdocs/libraries/WideImage/Operation/CorrectGamma.php b/htdocs/libraries/WideImage/Operation/CorrectGamma.php new file mode 100644 index 000000000000..69d6cb71b6ce --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/CorrectGamma.php @@ -0,0 +1,52 @@ +copy(); + + if (!imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma)) { + throw new GDFunctionResultException("imagegammacorrect() returned false"); + } + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/Crop.php b/htdocs/libraries/WideImage/Operation/Crop.php new file mode 100644 index 000000000000..c809004d1eca --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/Crop.php @@ -0,0 +1,96 @@ +getWidth(), $width); + $height = Coordinate::fix($height, $img->getHeight(), $height); + $left = Coordinate::fix($left, $img->getWidth(), $width); + $top = Coordinate::fix($top, $img->getHeight(), $height); + + if ($left < 0) { + $width = $left + $width; + $left = 0; + } + + if ($width > $img->getWidth() - $left) { + $width = $img->getWidth() - $left; + } + + if ($top < 0) { + $height = $top + $height; + $top = 0; + } + + if ($height > $img->getHeight() - $top) { + $height = $img->getHeight() - $top; + } + + if ($width <= 0 || $height <= 0) { + throw new Exception("Can't crop outside of an image."); + } + + $new = $img->doCreate($width, $height); + + if ($img->isTransparent() || $img instanceof PaletteImage) { + $new->copyTransparencyFrom($img); + + if (!imagecopyresized($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) { + throw new GDFunctionResultException("imagecopyresized() returned false"); + } + } else { + $new->alphaBlending(false); + $new->saveAlpha(true); + + if (!imagecopyresampled($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) { + throw new GDFunctionResultException("imagecopyresampled() returned false"); + } + } + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/Exception/InvalidFitMethodException.php b/htdocs/libraries/WideImage/Operation/Exception/InvalidFitMethodException.php new file mode 100644 index 000000000000..beaa0bc98457 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/Exception/InvalidFitMethodException.php @@ -0,0 +1,10 @@ +copy(); + + $width = $image->getWidth(); + $height = $image->getHeight(); + + if ($new->isTransparent()) { + imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor()); + } + + for ($y = 0; $y < $height; $y++) { + if (!imagecopy($new->getHandle(), $image->getHandle(), 0, $y, 0, $height - $y - 1, $width, 1)) { + throw new GDFunctionResultException("imagecopy() returned false"); + } + } + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/GetMask.php b/htdocs/libraries/WideImage/Operation/GetMask.php new file mode 100644 index 000000000000..34d0d9c7b6fb --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/GetMask.php @@ -0,0 +1,76 @@ +getWidth(); + $height = $image->getHeight(); + + $mask = TrueColorImage::create($width, $height); + $mask->setTransparentColor(-1); + $mask->alphaBlending(false); + $mask->saveAlpha(false); + + for ($i = 0; $i <= 255; $i++) { + $greyscale[$i] = ImageColorAllocate($mask->getHandle(), $i, $i, $i); + } + + imagefilledrectangle($mask->getHandle(), 0, 0, $width, $height, $greyscale[255]); + + $transparentColor = $image->getTransparentColor(); + $alphaToGreyRatio = 255 / 127; + + for ($x = 0; $x < $width; $x++) { + for ($y = 0; $y < $height; $y++) { + $color = $image->getColorAt($x, $y); + + if ($color == $transparentColor) { + $rgba['alpha'] = 127; + } else { + $rgba = $image->getColorRGB($color); + } + + imagesetpixel($mask->getHandle(), $x, $y, $greyscale[255 - round($rgba['alpha'] * $alphaToGreyRatio)]); + } + } + + return $mask; + } +} diff --git a/htdocs/libraries/WideImage/Operation/Merge.php b/htdocs/libraries/WideImage/Operation/Merge.php new file mode 100644 index 000000000000..264d18056c5e --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/Merge.php @@ -0,0 +1,82 @@ +getWidth(), $overlay->getWidth()); + $y = Coordinate::fix($top, $base->getHeight(), $overlay->getHeight()); + + $result = $base->asTrueColor(); + $result->alphaBlending(true); + $result->saveAlpha(true); + + if ($pct <= 0) { + return $result; + } + + if ($pct < 100) { + if (!imagecopymerge( + $result->getHandle(), + $overlay->getHandle(), + $x, $y, 0, 0, + $overlay->getWidth(), + $overlay->getHeight(), + $pct)) { + throw new GDFunctionResultException("imagecopymerge() returned false"); + } + } else { + if (!imagecopy( + $result->getHandle(), + $overlay->getHandle(), + $x, $y, 0, 0, + $overlay->getWidth(), + $overlay->getHeight())) { + throw new GDFunctionResultException("imagecopy() returned false"); + } + } + + return $result; + } +} diff --git a/htdocs/libraries/WideImage/Operation/Mirror.php b/htdocs/libraries/WideImage/Operation/Mirror.php new file mode 100644 index 000000000000..199c423e4497 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/Mirror.php @@ -0,0 +1,60 @@ +copy(); + + $width = $image->getWidth(); + $height = $image->getHeight(); + + if ($new->isTransparent()) { + imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor()); + } + + for ($x = 0; $x < $width; $x++) { + if (!imagecopy($new->getHandle(), $image->getHandle(), $x, 0, $width - $x - 1, 0, 1, $height)) { + throw new GDFunctionResultException("imagecopy() returned false"); + } + } + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/Resize.php b/htdocs/libraries/WideImage/Operation/Resize.php new file mode 100644 index 000000000000..98520894df18 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/Resize.php @@ -0,0 +1,166 @@ + $img->getWidth(), 'height' => $img->getHeight()); + } + + if ($width !== null) { + $width = Coordinate::fix($width, $img->getWidth()); + $rx = $img->getWidth() / $width; + } else { + $rx = null; + } + + if ($height !== null) { + $height = Coordinate::fix($height, $img->getHeight()); + $ry = $img->getHeight() / $height; + } else { + $ry = null; + } + + if ($rx === null && $ry !== null) { + $rx = $ry; + $width = round($img->getWidth() / $rx); + } + + if ($ry === null && $rx !== null) { + $ry = $rx; + $height = round($img->getHeight() / $ry); + } + + if ($width === 0 || $height === 0) { + return array('width' => 0, 'height' => 0); + } + + if ($fit == null) { + $fit = 'inside'; + } + + $dim = array(); + + if ($fit == 'fill') { + $dim['width'] = $width; + $dim['height'] = $height; + } elseif ($fit == 'inside' || $fit == 'outside') { + if ($fit == 'inside') { + $ratio = ($rx > $ry) ? $rx : $ry; + } else { + $ratio = ($rx < $ry) ? $rx : $ry; + } + + $dim['width'] = round($img->getWidth() / $ratio); + $dim['height'] = round($img->getHeight() / $ratio); + } else { + throw new InvalidFitMethodException("{$fit} is not a valid resize-fit method."); + } + + return $dim; + } + + /** + * Returns a resized image + * + * @param \WideImage\Image $img + * @param smart_coordinate $width + * @param smart_coordinate $height + * @param string $fit + * @param string $scale + * @return \WideImage\Image + */ + public function execute($img, $width, $height, $fit, $scale) + { + $dim = $this->prepareDimensions($img, $width, $height, $fit); + + if (($scale === 'down' && ($dim['width'] >= $img->getWidth() && $dim['height'] >= $img->getHeight())) || + ($scale === 'up' && ($dim['width'] <= $img->getWidth() && $dim['height'] <= $img->getHeight()))) { + $dim = array('width' => $img->getWidth(), 'height' => $img->getHeight()); + } + + if ($dim['width'] <= 0 || $dim['height'] <= 0) { + throw new InvalidResizeDimensionException("Both dimensions must be larger than 0."); + } + + if ($img->isTransparent() || $img instanceof PaletteImage) { + $new = PaletteImage::create($dim['width'], $dim['height']); + $new->copyTransparencyFrom($img); + + if (!imagecopyresized( + $new->getHandle(), + $img->getHandle(), + 0, 0, 0, 0, + $new->getWidth(), + $new->getHeight(), + $img->getWidth(), + $img->getHeight())) { + throw new GDFunctionResultException("imagecopyresized() returned false"); + } + } else { + $new = TrueColorImage::create($dim['width'], $dim['height']); + $new->alphaBlending(false); + $new->saveAlpha(true); + + if (!imagecopyresampled( + $new->getHandle(), + $img->getHandle(), + 0, 0, 0, 0, + $new->getWidth(), + $new->getHeight(), + $img->getWidth(), + $img->getHeight())) { + throw new GDFunctionResultException("imagecopyresampled() returned false"); + } + + $new->alphaBlending(true); + } + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/ResizeCanvas.php b/htdocs/libraries/WideImage/Operation/ResizeCanvas.php new file mode 100644 index 000000000000..8fa39f2c6bcc --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/ResizeCanvas.php @@ -0,0 +1,109 @@ +getWidth()); + $new_height = Coordinate::fix($height, $img->getHeight()); + + if ($scale == 'down') { + $new_width = min($new_width, $img->getWidth()); + $new_height = min($new_height, $img->getHeight()); + } elseif ($scale == 'up') { + $new_width = max($new_width, $img->getWidth()); + $new_height = max($new_height, $img->getHeight()); + } + + $new = WideImage::createTrueColorImage($new_width, $new_height); + + if ($img->isTrueColor()) { + if ($color === null) { + $color = $new->allocateColorAlpha(0, 0, 0, 127); + } + } else { + imagepalettecopy($new->getHandle(), $img->getHandle()); + + if ($img->isTransparent()) { + $new->copyTransparencyFrom($img); + $tc_rgb = $img->getTransparentColorRGB(); + $t_color = $new->allocateColorAlpha($tc_rgb); + } + + if ($color === null) { + if ($img->isTransparent()) { + $color = $t_color; + } else { + $color = $new->allocateColorAlpha(255, 0, 127, 127); + } + + imagecolortransparent($new->getHandle(), $color); + } + } + + $new->fill(0, 0, $color); + + $x = Coordinate::fix($left, $new->getWidth(), $img->getWidth()); + $y = Coordinate::fix($top, $new->getHeight(), $img->getHeight()); + + // blending for truecolor images + if ($img->isTrueColor()) { + $new->alphaBlending($merge); + } + + // not-blending for palette images + if (!$merge && !$img->isTrueColor() && isset($t_color)) { + $new->getCanvas()->filledRectangle($x, $y, $x + $img->getWidth(), $y + $img->getHeight(), $t_color); + } + + $img->copyTo($new, $x, $y); + + return $new; + } +} diff --git a/htdocs/libraries/WideImage/Operation/Rotate.php b/htdocs/libraries/WideImage/Operation/Rotate.php new file mode 100644 index 000000000000..b6c40fab9f97 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/Rotate.php @@ -0,0 +1,71 @@ +copy(); + } + + $image = $image->asTrueColor(); + + if ($bgColor === null) { + $bgColor = $image->getTransparentColor(); + + if ($bgColor == -1) { + $bgColor = $image->allocateColorAlpha(255, 255, 255, 127); + imagecolortransparent($image->getHandle(), $bgColor); + } + } + + return new TrueColorImage(imagerotate($image->getHandle(), $angle, $bgColor, $ignoreTransparent)); + } +} diff --git a/htdocs/libraries/WideImage/Operation/RoundCorners.php b/htdocs/libraries/WideImage/Operation/RoundCorners.php new file mode 100644 index 000000000000..d81757a21573 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/RoundCorners.php @@ -0,0 +1,124 @@ + 16) { + $sample_ratio = 16; + } else { + $sample_ratio = $smoothness; + } + + $corner = WideImage::createTrueColorImage($radius * $sample_ratio, $radius * $sample_ratio); + + if ($color === null) { + imagepalettecopy($corner->getHandle(), $image->getHandle()); + $bg_color = $corner->allocateColor(0, 0, 0); + + $corner->fill(0, 0, $bg_color); + $fg_color = $corner->allocateColor(255, 255, 255); + $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color); + $corner = $corner->resize($radius, $radius); + + $result = $image->asTrueColor(); + + $tc = $result->getTransparentColor(); + + if ($tc == -1) { + $tc = $result->allocateColorAlpha(255, 255, 255, 127); + imagecolortransparent($result->getHandle(), $tc); + $result->setTransparentColor($tc); + } + + if ($corners & WideImage::SIDE_TOP_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_TOP) { + $result = $result->applyMask($corner, -1, -1); + } + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_TOP_RIGHT || $corners & WideImage::SIDE_TOP || $corners & WideImage::SIDE_RIGHT) { + $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100); + } + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_BOTTOM_RIGHT || $corners & WideImage::SIDE_RIGHT || $corners & WideImage::SIDE_BOTTOM) { + $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100); + } + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_BOTTOM_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_BOTTOM) { + $result = $result->applyMask($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100); + } + + return $result; + } else { + $bg_color = $color; + + $corner->fill(0, 0, $bg_color); + $fg_color = $corner->allocateColorAlpha(127, 127, 127, 127); + $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color); + $corner = $corner->resize($radius, $radius); + + $result = $image->copy(); + if ($corners & WideImage::SIDE_TOP_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_TOP) { + $result = $result->merge($corner, -1, -1, 100); + } + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_TOP_RIGHT || $corners & WideImage::SIDE_TOP || $corners & WideImage::SIDE_RIGHT) { + $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100); + } + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_BOTTOM_RIGHT || $corners & WideImage::SIDE_RIGHT || $corners & WideImage::SIDE_BOTTOM) { + $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100); + } + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_BOTTOM_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_BOTTOM) { + $result = $result->merge($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100); + } + + return $result; + } + } +} diff --git a/htdocs/libraries/WideImage/Operation/Unsharp.php b/htdocs/libraries/WideImage/Operation/Unsharp.php new file mode 100644 index 000000000000..a92201c89db4 --- /dev/null +++ b/htdocs/libraries/WideImage/Operation/Unsharp.php @@ -0,0 +1,154 @@ + 500) { + $amount = 500; + } + + $amount = $amount * 0.016; + + if ($radius > 50) { + $radius = 50; + } + + $radius = $radius * 2; + + if ($threshold > 255) { + $threshold = 255; + } + + $radius = abs(round($radius)); // Only integers make sense. + + if ($radius == 0) { + return $image; + } + + // Gaussian blur matrix + $matrix = array( + array(1, 2, 1), + array(2, 4, 2), + array(1, 2, 1) + ); + + $blurred = $image->applyConvolution($matrix, 16, 0); + + if ($threshold > 0) { + // Calculate the difference between the blurred pixels and the original + // and set the pixels + for ($x = 0; $x < $image->getWidth(); $x++) { + for ($y = 0; $y < $image->getHeight(); $y++) { + $rgbOrig = $image->getRGBAt($x, $y); + $rOrig = $rgbOrig["red"]; + $gOrig = $rgbOrig["green"]; + $bOrig = $rgbOrig["blue"]; + + $rgbBlur = $blurred->getRGBAt($x, $y); + $rBlur = $rgbBlur["red"]; + $gBlur = $rgbBlur["green"]; + $bBlur = $rgbBlur["blue"]; + + // When the masked pixels differ less from the original + // than the threshold specifies, they are set to their original value. + $rNew = (abs($rOrig - $rBlur) >= $threshold) + ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) + : $rOrig; + $gNew = (abs($gOrig - $gBlur) >= $threshold) + ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) + : $gOrig; + $bNew = (abs($bOrig - $bBlur) >= $threshold) + ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) + : $bOrig; + $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); + + if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) { + $image->setRGBAt($x, $y, $rgbNew); + } + } + } + } else { + $w = $image->getWidth(); + $h = $image->getHeight(); + + for ($x = 0; $x < $w; $x++) { + for ($y = 0; $y < $h; $y++) { + $rgbOrig = $image->getRGBAt($x, $y); + $rOrig = $rgbOrig["red"]; + $gOrig = $rgbOrig["green"]; + $bOrig = $rgbOrig["blue"]; + + $rgbBlur = $blurred->getRGBAt($x, $y); + $rBlur = $rgbBlur["red"]; + $gBlur = $rgbBlur["green"]; + $bBlur = $rgbBlur["blue"]; + + $rNew = static::bit(($amount * ($rOrig - $rBlur)) + $rOrig); + $gNew = static::bit(($amount * ($gOrig - $gBlur)) + $gOrig); + $bNew = static::bit(($amount * ($bOrig - $bBlur)) + $bOrig); + $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); + + $image->setRGBAt($x, $y, $rgbNew); + } + } + } + + return $image; + } + + protected static function bit($val) + { + if ($val > 255) { + return 255; + } + + if ($val < 0) { + return 0; + } + + return $val; + } +} diff --git a/htdocs/libraries/WideImage/OperationFactory.php b/htdocs/libraries/WideImage/OperationFactory.php new file mode 100644 index 000000000000..0f6b96ce50e8 --- /dev/null +++ b/htdocs/libraries/WideImage/OperationFactory.php @@ -0,0 +1,56 @@ +copy(); + } + + /** + * Returns a copy of the image + * + * @param $trueColor True if the new image should be truecolor + * @return \WideImage\Image + */ + protected function copyAsNew($trueColor = false) + { + $width = $this->getWidth(); + $height = $this->getHeight(); + + if ($trueColor) { + $new = TrueColorImage::create($width, $height); + } else { + $new = PaletteImage::create($width, $height); + } + + // copy transparency of source to target + if ($this->isTransparent()) { + $rgb = $this->getTransparentColorRGB(); + + if (is_array($rgb)) { + $tci = $new->allocateColor($rgb['red'], $rgb['green'], $rgb['blue']); + $new->fill(0, 0, $tci); + $new->setTransparentColor($tci); + } + } + + imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height); + + return $new; + } + + /** + * (non-PHPdoc) + * @see \WideImage\Image#asTrueColor() + */ + public function asTrueColor() + { + $width = $this->getWidth(); + $height = $this->getHeight(); + $new = WideImage::createTrueColorImage($width, $height); + + if ($this->isTransparent()) { + $new->copyTransparencyFrom($this); + } + + if (!imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height)) { + throw new GDFunctionResultException("imagecopy() returned false"); + } + + return $new; + } + + /** + * (non-PHPdoc) + * @see \WideImage\Image#getChannels() + */ + public function getChannels() + { + $args = func_get_args(); + + if (count($args) == 1 && is_array($args[0])) { + $args = $args[0]; + } + + return OperationFactory::get('CopyChannelsPalette')->execute($this, $args); + } + + /** + * (non-PHPdoc) + * @see \WideImage\Image#copyNoAlpha() + */ + public function copyNoAlpha() + { + return WideImage::loadFromString($this->asString('png')); + } +} diff --git a/htdocs/libraries/WideImage/TrueColorImage.php b/htdocs/libraries/WideImage/TrueColorImage.php new file mode 100644 index 000000000000..fa0101233142 --- /dev/null +++ b/htdocs/libraries/WideImage/TrueColorImage.php @@ -0,0 +1,293 @@ +alphaBlending(false); + $this->saveAlpha(true); + } + + /** + * Factory method that creates a true-color image object + * + * @param int $width + * @param int $height + * @return \WideImage\TrueColorImage + */ + public static function create($width, $height) + { + if ($width * $height <= 0 || $width < 0) { + throw new InvalidImageDimensionException("Can't create an image with dimensions [$width, $height]."); + } + + return new TrueColorImage(imagecreatetruecolor($width, $height)); + } + + public function doCreate($width, $height) + { + return static::create($width, $height); + } + + public function isTrueColor() + { + return true; + } + + /** + * Sets alpha blending mode via imagealphablending() + * + * @param bool $mode + * @return bool + */ + public function alphaBlending($mode) + { + return imagealphablending($this->handle, $mode); + } + + /** + * Toggle if alpha channel should be saved with the image via imagesavealpha() + * + * @param bool $on + * @return bool + */ + public function saveAlpha($on) + { + return imagesavealpha($this->handle, $on); + } + + /** + * Allocates a color and returns its index + * + * This method accepts either each component as an integer value, + * or an associative array that holds the color's components in keys + * 'red', 'green', 'blue', 'alpha'. + * + * @param mixed $R + * @param int $G + * @param int $B + * @param int $A + * @return int + */ + public function allocateColorAlpha($R, $G = null, $B = null, $A = null) + { + if (is_array($R)) { + return imageColorAllocateAlpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']); + } + + return imageColorAllocateAlpha($this->handle, $R, $G, $B, $A); + } + + /** + * @see \WideImage\Image#asPalette($nColors, $dither, $matchPalette) + */ + public function asPalette($nColors = 255, $dither = null, $matchPalette = true) + { + $nColors = intval($nColors); + + if ($nColors < 1) { + $nColors = 1; + } elseif ($nColors > 255) { + $nColors = 255; + } + + if ($dither === null) { + $dither = $this->isTransparent(); + } + + $temp = $this->copy(); + + imagetruecolortopalette($temp->handle, $dither, $nColors); + + if ($matchPalette == true && function_exists('imagecolormatch')) { + imagecolormatch($this->handle, $temp->handle); + } + + // The code below isn't working properly; it corrupts transparency on some palette->tc->palette conversions. + // Why is this code here? + /* + if ($this->isTransparent()) + { + $trgb = $this->getTransparentColorRGB(); + $tci = $temp->getClosestColor($trgb); + $temp->setTransparentColor($tci); + } + /**/ + + $temp->releaseHandle(); + + return new PaletteImage($temp->handle); + } + + /** + * Returns the index of the color that best match the given color components + * + * This method accepts either each component as an integer value, + * or an associative array that holds the color's components in keys + * 'red', 'green', 'blue', 'alpha'. + * + * @param mixed $R Red component value or an associative array + * @param int $G Green component + * @param int $B Blue component + * @param int $A Alpha component + * @return int The color index + */ + public function getClosestColorAlpha($R, $G = null, $B = null, $A = null) + { + if (is_array($R)) { + return imagecolorclosestalpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']); + } + + return imagecolorclosestalpha($this->handle, $R, $G, $B, $A); + } + + /** + * Returns the index of the color that exactly match the given color components + * + * This method accepts either each component as an integer value, + * or an associative array that holds the color's components in keys + * 'red', 'green', 'blue', 'alpha'. + * + * @param mixed $R Red component value or an associative array + * @param int $G Green component + * @param int $B Blue component + * @param int $A Alpha component + * @return int The color index + */ + public function getExactColorAlpha($R, $G = null, $B = null, $A = null) + { + if (is_array($R)) { + return imagecolorexactalpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']); + } + + return imagecolorexactalpha($this->handle, $R, $G, $B, $A); + } + + /** + * @see \WideImage\Image#getChannels() + */ + public function getChannels() + { + $args = func_get_args(); + + if (count($args) == 1 && is_array($args[0])) { + $args = $args[0]; + } + + return OperationFactory::get('CopyChannelsTrueColor')->execute($this, $args); + } + + /** + * (non-PHPdoc) + * @see \WideImage\Image#copyNoAlpha() + */ + public function copyNoAlpha() + { + $prev = $this->saveAlpha(false); + $result = WideImage::loadFromString($this->asString('png')); + $this->saveAlpha($prev); + //$result->releaseHandle(); + return $result; + } + + /** + * (non-PHPdoc) + * @see \WideImage\Image#asTrueColor() + * @return TrueColorImage + */ + public function asTrueColor() + { + return $this->copy(); + } + + /** + * Calls imageinterlace() using the current handler + * @see \WideImage\Image#asTrueColor() + * @return TrueColorImage A copy of the image, with imageinterlace() applied + */ + public function asProgressive() + { + $dest = $this->asTrueColor(); + + imageinterlace($dest->getHandle(), true); + + return $dest; + } + + /** + * Resizes the image proportionally inside the given width and height. + * The returned image will have always the specified width and height, and any space will be filled + * with the given $fillCollor + * + * @param int $width Exact width in pixels + * @param int $height Exact height in pixels + * @param string $fit 'inside' (default), 'outside' or 'fill' + * @param string $scale 'down' (default), 'up' or 'any' + * @param mixed $alignLeft Left position of the image over the fill space, smart coordinate + * @param mixed $alignTop Top position of the image over the fill space, smart coordinate + * @param int $mergeOpacity The opacity of the image over the fill space + * @param int|array $fillColor RGB color index or array. Background color to fill the resulting image with if it's smaller + * than the given size. By default (if null), the top left pixel color will be used. + * + * @return TrueColorImage A new, resized image + */ + public function resizeInsideRect($width, $height, $fit = 'inside', $scale = 'down', $alignLeft = 'center', + $alignTop = 'center', $mergeOpacity = 100, $fillColor = null) + { + + if ($fillColor) { + if (is_numeric($fillColor)) { + $fillColor = $this->getColorRGB($fillColor); + } + } else { + $fillColor = $this->getColorRGB($this->getColorAt(0, 0)); + } + + $rect = \WideImage::createTrueColorImage($width, $height); + $rect->fill(0, 0, $rect->allocateColor($fillColor)); + + $img = $this; + + for ($i = 0; $i < 4; $i++) { //4 times + $img = $img->resize($width, $height, $fit, $scale); + } + + return $rect->merge($img, $alignLeft, $alignTop, $mergeOpacity); + } +} + diff --git a/htdocs/libraries/WideImage/VERSION b/htdocs/libraries/WideImage/VERSION new file mode 100644 index 000000000000..7e152e6053f8 --- /dev/null +++ b/htdocs/libraries/WideImage/VERSION @@ -0,0 +1,2 @@ +Version: ##DEV## +Build date: ##BUILDDATE## diff --git a/htdocs/libraries/WideImage/WideImage.php b/htdocs/libraries/WideImage/WideImage.php new file mode 100644 index 000000000000..e617261e42aa --- /dev/null +++ b/htdocs/libraries/WideImage/WideImage.php @@ -0,0 +1,372 @@ + + * \WideImage\WideImage::registerCustomMapper('\\WideImage\\Mapper\\TGA', 'image/tga', 'tga'); + * + * + * @param string $mapper_class_name + * @param string $mime_type + * @param string $extension + */ + public static function registerCustomMapper($mapper_class_name, $mime_type, $extension) + { + MapperFactory::registerMapper($mapper_class_name, $mime_type, strtoupper($extension)); + } + + /** + * Loads an image from a file, URL, HTML input file field, binary string, or a valid image handle. + * The image format is auto-detected. + * + * Currently supported formats: PNG, GIF, JPG, BMP, TGA, GD, GD2. + * + * This function analyzes the input and decides whether to use WideImage::loadFromHandle(), + * WideImage::loadFromFile(), WideImage::loadFromUpload() or WideImage::loadFromString(), + * all of which you can also call directly to spare WideImage some guessing. + * + * Arrays are supported for upload fields; it returns an array of loaded images. + * To load only a single image from an array field, use WideImage::loadFromUpload('img', $i), + * where $i is the index of the image you want to load. + * + * + * $img = WideImage::load('http://url/image.png'); // image URL + * $img = WideImage::load('/path/to/image.png'); // local file path + * $img = WideImage::load('img'); // upload field name + * $img = WideImage::load(imagecreatetruecolor(10, 10)); // a GD resource + * $img = WideImage::load($image_data); // binary string containing image data + * + * + * @param mixed $source File name, url, HTML file input field name, binary string, or a GD image resource + * @return \WideImage\Image|\WideImage\PaletteImage|\WideImage\TrueColorImage + */ + public static function load($source) + { + $predictedSourceType = ''; + + if ($source == '') { + $predictedSourceType = 'String'; + } + + // Creating image via a valid resource + if (!$predictedSourceType && static::isValidImageHandle($source)) { + $predictedSourceType = 'Handle'; + } + + // Check for binary string + if (!$predictedSourceType) { + // search first $binLength bytes (at a maximum) for ord<32 characters (binary image data) + $binLength = 64; + $sourceLength = strlen($source); + $maxlen = ($sourceLength > $binLength) ? $binLength : $sourceLength; + + for ($i = 0; $i < $maxlen; $i++) { + if (ord($source[$i]) < 32) { + $predictedSourceType = 'String'; + break; + } + } + } + + // Uploaded image (array uploads not supported) + if (isset($_FILES[$source]) && isset($_FILES[$source]['tmp_name'])) { + $predictedSourceType = 'Upload'; + } + + // Otherwise, must be a file or an URL + if (!$predictedSourceType) { + $predictedSourceType = 'File'; + } + + return call_user_func(array(__CLASS__, 'loadFrom' . $predictedSourceType), $source); + } + + /** + * Create and load an image from a file or URL. The image format is auto-detected. + * + * @param string $uri File or url + * @return \WideImage\Image|\WideImage\PaletteImage|\WideImage\TrueColorImage + */ + public static function loadFromFile($uri) + { + $data = file_get_contents($uri); + $handle = @imagecreatefromstring($data); + + if (!static::isValidImageHandle($handle)) { + try { + // try to find a mapper first + $mapper = MapperFactory::selectMapper($uri); + + if ($mapper) { + $handle = $mapper->load($uri); + } + } catch (UnsupportedFormatException $e) { + // mapper not found + } + + // try all custom mappers + if (!static::isValidImageHandle($handle)) { + $custom_mappers = MapperFactory::getCustomMappers(); + + foreach ($custom_mappers as $mime_type => $mapper_class) { + $mapper = MapperFactory::selectMapper(null, $mime_type); + $handle = $mapper->loadFromString($data); + + if (static::isValidImageHandle($handle)) { + break; + } + } + } + } + + if (!static::isValidImageHandle($handle)) { + throw new InvalidImageSourceException("File '{$uri}' appears to be an invalid image source."); + } + + return static::loadFromHandle($handle); + } + + /** + * Create and load an image from a string. Format is auto-detected. + * + * @param string $string Binary data, i.e. from BLOB field in the database + * @return \WideImage\Image|\WideImage\PaletteImage|\WideImage\TrueColorImage + */ + public static function loadFromString($string) + { + if (strlen($string) < 128) { + throw new InvalidImageSourceException("String doesn't contain image data."); + } + + $handle = @imagecreatefromstring($string); + + if (!static::isValidImageHandle($handle)) { + $custom_mappers = MapperFactory::getCustomMappers(); + + foreach ($custom_mappers as $mime_type => $mapper_class) { + $mapper = MapperFactory::selectMapper(null, $mime_type); + $handle = $mapper->loadFromString($string); + + if (static::isValidImageHandle($handle)) { + break; + } + } + } + + if (!static::isValidImageHandle($handle)) { + throw new InvalidImageSourceException("String doesn't contain valid image data."); + } + + return static::loadFromHandle($handle); + } + + /** + * Create and load an image from an image handle. + * + * Note: the resulting image object takes ownership of the passed + * handle. When the newly-created image object is destroyed, the handle is + * destroyed too, so it's not a valid image handle anymore. In order to + * preserve the handle for use after object destruction, you have to call + * \WideImage\Image::releaseHandle() on the created image instance prior to its + * destruction. + * + * + * $handle = imagecreatefrompng('file.png'); + * $image = WideImage::loadFromHandle($handle); + * + * + * @param resource $handle A valid GD image resource + * @return \WideImage\Image|\WideImage\PaletteImage|\WideImage\TrueColorImage + */ + public static function loadFromHandle($handle) + { + if (!static::isValidImageHandle($handle)) { + throw new InvalidImageSourceException("Handle is not a valid GD image resource."); + } + + if (imageistruecolor($handle)) { + return new TrueColorImage($handle); + } + + return new PaletteImage($handle); + } + + /** + * This method loads a file from the $_FILES array. The image format is auto-detected. + * + * You only have to pass the field name as the parameter. For array fields, this function will + * return an array of image objects, unless you specify the $index parameter, which will + * load the desired image. + * + * @param $field_name Name of the key in $_FILES array + * @param int $index The index of the file to load (if the input field is an array) + * @return \WideImage\Image The loaded image + */ + public static function loadFromUpload($field_name, $index = null) + { + if (!array_key_exists($field_name, $_FILES)) { + throw new InvalidImageSourceException("Upload field '{$field_name}' doesn't exist."); + } + + if (is_array($_FILES[$field_name]['tmp_name'])) { + if (isset($_FILES[$field_name]['tmp_name'][$index])) { + $filename = $_FILES[$field_name]['tmp_name'][$index]; + } else { + $result = array(); + + foreach ($_FILES[$field_name]['tmp_name'] as $idx => $tmp_name) { + $result[$idx] = static::loadFromFile($tmp_name); + } + + return $result; + } + } else { + $filename = $_FILES[$field_name]['tmp_name']; + } + + if (!file_exists($filename)) { + throw new InvalidImageSourceException("Uploaded file doesn't exist."); + } + + return static::loadFromFile($filename); + } + + /** + * Factory method for creating a palette image + * + * @param int $width + * @param int $height + * @return \WideImage\PaletteImage + */ + public static function createPaletteImage($width, $height) + { + return PaletteImage::create($width, $height); + } + + /** + * Factory method for creating a true-color image + * + * @param int $width + * @param int $height + * @return \WideImage\TrueColorImage + */ + public static function createTrueColorImage($width, $height) + { + return TrueColorImage::create($width, $height); + } + + /** + * Check whether the given handle is a valid GD resource + * + * @param mixed $handle The variable to check + * @return bool + */ + public static function isValidImageHandle($handle) + { + return ($handle instanceof \GdImage || (is_resource($handle) && get_resource_type($handle) == 'gd')); + } + + /** + * Throws exception if the handle isn't a valid GD resource + * + * @param mixed $handle The variable to check + */ + public static function assertValidImageHandle($handle) + { + if (!static::isValidImageHandle($handle)) { + throw new InvalidImageHandleException("{$handle} is not a valid image handle."); + } + } +} + +WideImage::checkGD(); + +WideImage::registerCustomMapper('\\WideImage\\Mapper\\BMP', 'image/bmp', 'bmp'); +WideImage::registerCustomMapper('\\WideImage\\Mapper\\TGA', 'image/tga', 'tga'); + \ No newline at end of file diff --git a/htdocs/libraries/WideImage/gpl.txt b/htdocs/libraries/WideImage/gpl.txt new file mode 100644 index 000000000000..d511905c1647 --- /dev/null +++ b/htdocs/libraries/WideImage/gpl.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/htdocs/libraries/WideImage/index.html b/htdocs/libraries/WideImage/index.html new file mode 100644 index 000000000000..990cbd60372e --- /dev/null +++ b/htdocs/libraries/WideImage/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lgpl.txt b/htdocs/libraries/WideImage/lgpl.txt new file mode 100644 index 000000000000..5ab7695ab8ca --- /dev/null +++ b/htdocs/libraries/WideImage/lgpl.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/htdocs/libraries/WideImage/lib/Canvas.php b/htdocs/libraries/WideImage/lib/Canvas.php new file mode 100755 index 000000000000..359ef51bc67d --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Canvas.php @@ -0,0 +1,167 @@ +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: + * + * $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'); + * + * + * @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: + * + * $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)); + * + */ + 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}."); + } + } diff --git a/htdocs/libraries/WideImage/lib/Coordinate.php b/htdocs/libraries/WideImage/lib/Coordinate.php new file mode 100755 index 000000000000..a3f6f63732e0 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Coordinate.php @@ -0,0 +1,208 @@ + '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; + } + } diff --git a/htdocs/libraries/WideImage/lib/Exception.php b/htdocs/libraries/WideImage/lib/Exception.php new file mode 100755 index 000000000000..0aae4f0f90ed --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Exception.php @@ -0,0 +1,31 @@ += 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); + } + } diff --git a/htdocs/libraries/WideImage/lib/Font/PS.php b/htdocs/libraries/WideImage/lib/Font/PS.php new file mode 100755 index 000000000000..9359e2e5c7a2 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Font/PS.php @@ -0,0 +1,60 @@ +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; + } + } diff --git a/htdocs/libraries/WideImage/lib/Font/TTF.php b/htdocs/libraries/WideImage/lib/Font/TTF.php new file mode 100755 index 000000000000..10877117f2c3 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Font/TTF.php @@ -0,0 +1,75 @@ +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); + } + } diff --git a/htdocs/libraries/WideImage/lib/Font/index.html b/htdocs/libraries/WideImage/lib/Font/index.html new file mode 100644 index 000000000000..74b6f45c8f33 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Font/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/Image.php b/htdocs/libraries/WideImage/lib/Image.php new file mode 100755 index 000000000000..3a99280008f0 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Image.php @@ -0,0 +1,964 @@ +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: + * + * // 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'); + * + * + * @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: + * + * WideImage::load('image1.png')->resize(100, 100)->output('gif'); + * + * + * @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): + * + * $smaller = $image->resize('50%'); + * + * $smaller = $image->resize('100', '100', 'inside', 'down'); + * is the same as + * $smaller = $image->resizeDown(100, 100, 'inside'); + * + * + * @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: + * + * $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 + * + * + * @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]. + * + * $image = WideImage::load('someimage.jpg'); // 100x150 + * $white = $image->allocateColor(255, 255, 255); + * $image->resizeCanvas('200%', '100% + 20', 10, 'center+20', $white); + * + * + * 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: + * + * $nice = $ugly->roundCorners(20, $ugly->allocateColor(255, 0, 0), 2); + * + * + * 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: + * + * $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); + * + * + * @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: + * + * $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 + * + * + * This operation supports alignment notation in left/top coordinates. + * Example: + * + * $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 + * + * + * @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: + * + * $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'); + * + * + * @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: + * + * $channels = $img->getChannels('red', 'blue'); + * $channels = $img->getChannels('alpha', 'green'); + * $channels = $img->getChannels(array('green', 'blue')); + * + * + * @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; + } + } diff --git a/htdocs/libraries/WideImage/lib/Mapper/BMP.php b/htdocs/libraries/WideImage/lib/Mapper/BMP.php new file mode 100755 index 000000000000..0620f0590f62 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Mapper/BMP.php @@ -0,0 +1,51 @@ +history.go(-1); \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/MapperFactory.php b/htdocs/libraries/WideImage/lib/MapperFactory.php new file mode 100755 index 000000000000..4f453df22459 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/MapperFactory.php @@ -0,0 +1,126 @@ + 'JPEG', + 'image/jpeg' => 'JPEG', + 'image/pjpeg' => 'JPEG', + 'image/gif' => 'GIF', + 'image/png' => 'PNG' + ); + + /** + * Returns a mapper, based on the $uri and $format + * + * @param string $uri File URI + * @param string $format File format (extension or mime-type) or null + * @return WideImage_Mapper + **/ + static function selectMapper($uri, $format = null) + { + $format = self::determineFormat($uri, $format); + + if (array_key_exists($format, self::$mappers)) + return self::$mappers[$format]; + + $mapperClassName = 'WideImage_Mapper_' . $format; + + if (!class_exists($mapperClassName, false)) + { + $mapperFileName = WideImage::path() . 'Mapper/' . $format . '.php'; + if (file_exists($mapperFileName)) + require_once $mapperFileName; + } + + if (class_exists($mapperClassName)) + { + self::$mappers[$format] = new $mapperClassName(); + return self::$mappers[$format]; + } + + throw new WideImage_UnsupportedFormatException("Format '{$format}' is not supported."); + } + + static function registerMapper($mapper_class_name, $mime_type, $extension) + { + self::$customMappers[$mime_type] = $mapper_class_name; + self::$mimeTable[$mime_type] = $extension; + } + + static function getCustomMappers() + { + return self::$customMappers; + } + + static function determineFormat($uri, $format = null) + { + if ($format == null) + $format = self::extractExtension($uri); + + // mime-type match + if (preg_match('~[a-z]*/[a-z-]*~i', $format)) + if (isset(self::$mimeTable[strtolower($format)])) + { + return self::$mimeTable[strtolower($format)]; + } + + // clean the string + $format = strtoupper(preg_replace('/[^a-z0-9_-]/i', '', $format)); + if ($format == 'JPG') + $format = 'JPEG'; + + return $format; + } + + static function mimeType($format) + { + return array_search(strtoupper($format), self::$mimeTable); + } + + static function extractExtension($uri) + { + $p = strrpos($uri, '.'); + if ($p === false) + return ''; + else + return substr($uri, $p + 1); + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/AddNoise.php b/htdocs/libraries/WideImage/lib/Operation/AddNoise.php new file mode 100644 index 000000000000..5206c3ef3907 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/AddNoise.php @@ -0,0 +1,153 @@ +asTrueColor(), $fun, $amount); + } + + /** + * Returns image with every pixel changed by specififed function + * + * @param WideImage_Image $image + * @param str $function + * @param int $value + * @return WideImage_Image + */ + function filter($image, $function, $value) + { + for ($y = 0; $y < $image->getHeight(); $y++) + { + for ($x = 0; $x< $image->getWidth(); $x++) + { + $rgb = imagecolorat($image->getHandle(), $x, $y); + + $a = ($rgb >> 24) & 0xFF; + $r = ($rgb >> 16) & 0xFF; + $g = ($rgb >> 8) & 0xFF; + $b = $rgb & 0xFF; + + + self::$function($r, $g, $b, $value); + + $color = imagecolorallocatealpha($image->getHandle(), $r, $g, $b, $a); + imagesetpixel($image->getHandle(), $x, $y, $color); + } + } + return $image; + } + /** + * Adds color noise by altering given R,G,B values using specififed amount + * + * @param int $r + * @param int $g + * @param int $b + * @param int $value + * @return void + */ + function colorNoise_fun(&$r, &$g, &$b, $amount) + { + $r = self::byte($r + mt_rand(0, $amount) - ($amount >> 1) ); + $g = self::byte($g + mt_rand(0, $amount) - ($amount >> 1) ); + $b = self::byte($b + mt_rand(0, $amount) - ($amount >> 1) ); + } + /** + * Adds mono noise by altering given R,G,B values using specififed amount + * + * @param int $r + * @param int $g + * @param int $b + * @param int $value + * @return void + */ + function monoNoise_fun(&$r, &$g, &$b, $amount) + { + $rand = mt_rand(0, $amount) - ($amount >> 1); + + $r = self::byte($r + $rand); + $g = self::byte($g + $rand); + $b = self::byte($b + $rand); + } + /** + * Adds salt&pepper noise by altering given R,G,B values using specififed amount + * + * @param int $r + * @param int $g + * @param int $b + * @param int $value + * @return void + */ + function saltPepperNoise_fun(&$r, &$g, &$b, $amount) + { + if (mt_rand(0, 255 - $amount) != 0) return; + + $rand = mt_rand(0, 1); + switch ($rand) + { + case 0 : $r = $g = $b = 0; + break; + case 1 : $r = $g = $b = 255; + break; + } + } + /** + * Returns value within (0,255) + * + * @param int $b + * @return int + */ + function byte($b) + { + if ($b > 255) return 255; + if ($b < 0) return 0; + return (int) $b; + } + + } diff --git a/htdocs/libraries/WideImage/lib/Operation/ApplyConvolution.php b/htdocs/libraries/WideImage/lib/Operation/ApplyConvolution.php new file mode 100755 index 000000000000..9a1c5f74c40a --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/ApplyConvolution.php @@ -0,0 +1,48 @@ +asTrueColor(); + if (!imageconvolution($new->getHandle(), $matrix, $div, $offset)) + throw new WideImage_GDFunctionResultException("imageconvolution() returned false"); + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/ApplyFilter.php b/htdocs/libraries/WideImage/lib/Operation/ApplyFilter.php new file mode 100755 index 000000000000..ec6d210b213d --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/ApplyFilter.php @@ -0,0 +1,67 @@ +asTrueColor(); + + if (in_array($filter, self::$one_arg_filters)) + $res = imagefilter($new->getHandle(), $filter, $arg1); + elseif (defined('IMG_FILTER_PIXELATE') && $filter == IMG_FILTER_PIXELATE) + $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2); + elseif ($filter == IMG_FILTER_COLORIZE) + $res = imagefilter($new->getHandle(), $filter, $arg1, $arg2, $arg3, $arg4); + else + $res = imagefilter($new->getHandle(), $filter); + + if (!$res) + throw new WideImage_GDFunctionResultException("imagefilter() returned false"); + + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/ApplyMask.php b/htdocs/libraries/WideImage/lib/Operation/ApplyMask.php new file mode 100755 index 000000000000..949213f0c192 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/ApplyMask.php @@ -0,0 +1,105 @@ +getWidth(), $mask->getWidth()); + $top = WideImage_Coordinate::fix($top, $image->getHeight(), $mask->getHeight()); + + $width = $image->getWidth(); + $mask_width = $mask->getWidth(); + + $height = $image->getHeight(); + $mask_height = $mask->getHeight(); + + $result = $image->asTrueColor(); + + $result->alphaBlending(false); + $result->saveAlpha(true); + + $srcTransparentColor = $result->getTransparentColor(); + if ($srcTransparentColor >= 0) + { + # this was here. works without. + #$trgb = $image->getColorRGB($srcTransparentColor); + #$trgb['alpha'] = 127; + #$destTransparentColor = $result->allocateColorAlpha($trgb); + #$result->setTransparentColor($destTransparentColor); + $destTransparentColor = $srcTransparentColor; + } + else + { + $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127); + } + + for ($x = 0; $x < $width; $x++) + for ($y = 0; $y < $height; $y++) + { + $mx = $x - $left; + $my = $y - $top; + if ($mx >= 0 && $mx < $mask_width && $my >= 0 && $my < $mask_height) + { + $srcColor = $image->getColorAt($x, $y); + if ($srcColor == $srcTransparentColor) + $destColor = $destTransparentColor; + else + { + $maskRGB = $mask->getRGBAt($mx, $my); + if ($maskRGB['red'] == 0) + $destColor = $destTransparentColor; + elseif ($srcColor >= 0) + { + $imageRGB = $image->getRGBAt($x, $y); + $level = ($maskRGB['red'] / 255) * (1 - $imageRGB['alpha'] / 127); + $imageRGB['alpha'] = 127 - round($level * 127); + if ($imageRGB['alpha'] == 127) + $destColor = $destTransparentColor; + else + $destColor = $result->allocateColorAlpha($imageRGB); + } + else + $destColor = $destTransparentColor; + } + $result->setColorAt($x, $y, $destColor); + } + } + return $result; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/AsGrayscale.php b/htdocs/libraries/WideImage/lib/Operation/AsGrayscale.php new file mode 100755 index 000000000000..dc72f8554c36 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/AsGrayscale.php @@ -0,0 +1,49 @@ +asTrueColor(); + if (!imagefilter($new->getHandle(), IMG_FILTER_GRAYSCALE)) + throw new WideImage_GDFunctionResultException("imagefilter() returned false"); + + if (!$image->isTrueColor()) + $new = $new->asPalette(); + + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/AsNegative.php b/htdocs/libraries/WideImage/lib/Operation/AsNegative.php new file mode 100644 index 000000000000..9a13c42973c7 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/AsNegative.php @@ -0,0 +1,63 @@ +isTrueColor(); + $transparent = $image->isTransparent(); + + if ($palette && $transparent) + $tcrgb = $image->getTransparentColorRGB(); + + $new = $image->asTrueColor(); + if (!imagefilter($new->getHandle(), IMG_FILTER_NEGATE)) + throw new WideImage_GDFunctionResultException("imagefilter() returned false"); + + if ($palette) + { + $new = $new->asPalette(); + if ($transparent) + { + $irgb = array('red' => 255 - $tcrgb['red'], 'green' => 255 - $tcrgb['green'], 'blue' => 255 - $tcrgb['blue'], 'alpha' => 127); + // needs imagecolorexactalpha instead of imagecolorexact, otherwise doesn't work on some transparent GIF images + $new_tci = imagecolorexactalpha($new->getHandle(), $irgb['red'], $irgb['green'], $irgb['blue'], 127); + $new->setTransparentColor($new_tci); + } + } + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/AutoCrop.php b/htdocs/libraries/WideImage/lib/Operation/AutoCrop.php new file mode 100755 index 000000000000..2fd0909e6e89 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/AutoCrop.php @@ -0,0 +1,162 @@ +getRGBAt(0, 0); + else + { + if ($base_color < 0) + return $img->copy(); + + $rgb_base = $img->getColorRGB($base_color); + } + + $cut_rect = array('left' => 0, 'top' => 0, 'right' => $img->getWidth() - 1, 'bottom' => $img->getHeight() - 1); + + for ($y = 0; $y <= $cut_rect['bottom']; $y++) + { + $count = 0; + for ($x = 0; $x <= $cut_rect['right']; $x++) + { + $rgb = $img->getRGBAt($x, $y); + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); + if ($diff > $rgb_threshold) + { + $count++; + if ($count >= $pixel_cutoff) + { + $cut_rect['top'] = $y; + break 2; + } + } + } + } + + for ($y = $img->getHeight() - 1; $y >= $cut_rect['top']; $y--) + { + $count = 0; + for ($x = 0; $x <= $cut_rect['right']; $x++) + { + $rgb = $img->getRGBAt($x, $y); + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); + if ($diff > $rgb_threshold) + { + $count++; + if ($count >= $pixel_cutoff) + { + $cut_rect['bottom'] = $y; + break 2; + } + } + } + } + + for ($x = 0; $x <= $cut_rect['right']; $x++) + { + $count = 0; + for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) + { + $rgb = $img->getRGBAt($x, $y); + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); + if ($diff > $rgb_threshold) + { + $count++; + if ($count >= $pixel_cutoff) + { + $cut_rect['left'] = $x; + break 2; + } + } + } + } + + for ($x = $cut_rect['right']; $x >= $cut_rect['left']; $x--) + { + $count = 0; + for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) + { + $rgb = $img->getRGBAt($x, $y); + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); + if ($diff > $rgb_threshold) + { + $count++; + if ($count >= $pixel_cutoff) + { + $cut_rect['right'] = $x; + break 2; + } + } + } + } + + $cut_rect = array( + 'left' => $cut_rect['left'] - $margin, + 'top' => $cut_rect['top'] - $margin, + 'right' => $cut_rect['right'] + $margin, + 'bottom' => $cut_rect['bottom'] + $margin + ); + + if ($cut_rect['left'] < 0) + $cut_rect['left'] = 0; + + if ($cut_rect['top'] < 0) + $cut_rect['top'] = 0; + + if ($cut_rect['right'] >= $img->getWidth()) + $cut_rect['right'] = $img->getWidth() - 1; + + if ($cut_rect['bottom'] >= $img->getHeight()) + $cut_rect['bottom'] = $img->getHeight() - 1; + + return $img->crop($cut_rect['left'], $cut_rect['top'], $cut_rect['right'] - $cut_rect['left'] + 1, $cut_rect['bottom'] - $cut_rect['top'] + 1); + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/CopyChannelsPalette.php b/htdocs/libraries/WideImage/lib/Operation/CopyChannelsPalette.php new file mode 100755 index 000000000000..048975005788 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/CopyChannelsPalette.php @@ -0,0 +1,90 @@ + 0, 'green' => 0, 'blue' => 0); + if (isset($channels['alpha'])) + unset($channels['alpha']); + + $width = $img->getWidth(); + $height = $img->getHeight(); + $copy = WideImage_PaletteImage::create($width, $height); + + if ($img->isTransparent()) + { + $otci = $img->getTransparentColor(); + $TRGB = $img->getColorRGB($otci); + $tci = $copy->allocateColor($TRGB); + } + else + { + $otci = null; + $tci = null; + } + + for ($x = 0; $x < $width; $x++) + for ($y = 0; $y < $height; $y++) + { + $ci = $img->getColorAt($x, $y); + if ($ci === $otci) + { + $copy->setColorAt($x, $y, $tci); + continue; + } + $RGB = $img->getColorRGB($ci); + + $newRGB = $blank; + foreach ($channels as $channel) + $newRGB[$channel] = $RGB[$channel]; + + $color = $copy->getExactColor($newRGB); + if ($color == -1) + $color = $copy->allocateColor($newRGB); + + $copy->setColorAt($x, $y, $color); + } + + if ($img->isTransparent()) + $copy->setTransparentColor($tci); + + return $copy; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/CopyChannelsTrueColor.php b/htdocs/libraries/WideImage/lib/Operation/CopyChannelsTrueColor.php new file mode 100755 index 000000000000..bf39520cd102 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/CopyChannelsTrueColor.php @@ -0,0 +1,67 @@ + 0, 'green' => 0, 'blue' => 0, 'alpha' => 0); + + $width = $img->getWidth(); + $height = $img->getHeight(); + $copy = WideImage_TrueColorImage::create($width, $height); + + if (count($channels) > 0) + for ($x = 0; $x < $width; $x++) + for ($y = 0; $y < $height; $y++) + { + $RGBA = $img->getRGBAt($x, $y); + $newRGBA = $blank; + foreach ($channels as $channel) + $newRGBA[$channel] = $RGBA[$channel]; + + $color = $copy->getExactColorAlpha($newRGBA); + if ($color == -1) + $color = $copy->allocateColorAlpha($newRGBA); + + $copy->setColorAt($x, $y, $color); + } + + return $copy; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/CorrectGamma.php b/htdocs/libraries/WideImage/lib/Operation/CorrectGamma.php new file mode 100755 index 000000000000..49562f1d3c2d --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/CorrectGamma.php @@ -0,0 +1,48 @@ +copy(); + if (!imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma)) + throw new WideImage_GDFunctionResultException("imagegammacorrect() returned false"); + + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/Crop.php b/htdocs/libraries/WideImage/lib/Operation/Crop.php new file mode 100755 index 000000000000..6a9d4f5b303d --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/Crop.php @@ -0,0 +1,86 @@ +getWidth(), $width); + $height = WideImage_Coordinate::fix($height, $img->getHeight(), $height); + $left = WideImage_Coordinate::fix($left, $img->getWidth(), $width); + $top = WideImage_Coordinate::fix($top, $img->getHeight(), $height); + if ($left < 0) + { + $width = $left + $width; + $left = 0; + } + + if ($width > $img->getWidth() - $left) + $width = $img->getWidth() - $left; + + if ($top < 0) + { + $height = $top + $height; + $top = 0; + } + + if ($height > $img->getHeight() - $top) + $height = $img->getHeight() - $top; + + if ($width <= 0 || $height <= 0) + throw new WideImage_Exception("Can't crop outside of an image."); + + $new = $img->doCreate($width, $height); + + if ($img->isTransparent() || $img instanceof WideImage_PaletteImage) + { + $new->copyTransparencyFrom($img); + if (!imagecopyresized($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) + throw new WideImage_GDFunctionResultException("imagecopyresized() returned false"); + } + else + { + $new->alphaBlending(false); + $new->saveAlpha(true); + if (!imagecopyresampled($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) + throw new WideImage_GDFunctionResultException("imagecopyresampled() returned false"); + } + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/Flip.php b/htdocs/libraries/WideImage/lib/Operation/Flip.php new file mode 100755 index 000000000000..d2f189c7b819 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/Flip.php @@ -0,0 +1,54 @@ +copy(); + + $width = $image->getWidth(); + $height = $image->getHeight(); + + if ($new->isTransparent()) + imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor()); + + for ($y = 0; $y < $height; $y++) + if (!imagecopy($new->getHandle(), $image->getHandle(), 0, $y, 0, $height - $y - 1, $width, 1)) + throw new WideImage_GDFunctionResultException("imagecopy() returned false"); + + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/GetMask.php b/htdocs/libraries/WideImage/lib/Operation/GetMask.php new file mode 100755 index 000000000000..f203a91d644a --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/GetMask.php @@ -0,0 +1,67 @@ +getWidth(); + $height = $image->getHeight(); + + $mask = WideImage_TrueColorImage::create($width, $height); + $mask->setTransparentColor(-1); + $mask->alphaBlending(false); + $mask->saveAlpha(false); + + for ($i = 0; $i <= 255; $i++) + $greyscale[$i] = ImageColorAllocate($mask->getHandle(), $i, $i, $i); + + imagefilledrectangle($mask->getHandle(), 0, 0, $width, $height, $greyscale[255]); + + $transparentColor = $image->getTransparentColor(); + $alphaToGreyRatio = 255 / 127; + for ($x = 0; $x < $width; $x++) + for ($y = 0; $y < $height; $y++) + { + $color = $image->getColorAt($x, $y); + if ($color == $transparentColor) + $rgba['alpha'] = 127; + else + $rgba = $image->getColorRGB($color); + imagesetpixel($mask->getHandle(), $x, $y, $greyscale[255 - round($rgba['alpha'] * $alphaToGreyRatio)]); + } + return $mask; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/Merge.php b/htdocs/libraries/WideImage/lib/Operation/Merge.php new file mode 100755 index 000000000000..ee897119b6ee --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/Merge.php @@ -0,0 +1,78 @@ +getWidth(), $overlay->getWidth()); + $y = WideImage_Coordinate::fix($top, $base->getHeight(), $overlay->getHeight()); + + $result = $base->asTrueColor(); + $result->alphaBlending(true); + $result->saveAlpha(true); + + if ($pct <= 0) + return $result; + + if ($pct < 100) + { + if (!imagecopymerge( + $result->getHandle(), + $overlay->getHandle(), + $x, $y, 0, 0, + $overlay->getWidth(), + $overlay->getHeight(), + $pct)) + throw new WideImage_GDFunctionResultException("imagecopymerge() returned false"); + } + else + { + if (!imagecopy( + $result->getHandle(), + $overlay->getHandle(), + $x, $y, 0, 0, + $overlay->getWidth(), + $overlay->getHeight())) + throw new WideImage_GDFunctionResultException("imagecopy() returned false"); + } + + return $result; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/Mirror.php b/htdocs/libraries/WideImage/lib/Operation/Mirror.php new file mode 100755 index 000000000000..ebefbfc4fd40 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/Mirror.php @@ -0,0 +1,55 @@ +copy(); + + $width = $image->getWidth(); + $height = $image->getHeight(); + + if ($new->isTransparent()) + imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor()); + + for ($x = 0; $x < $width; $x++) + { + if (!imagecopy($new->getHandle(), $image->getHandle(), $x, 0, $width - $x - 1, 0, 1, $height)) + throw new WideImage_GDFunctionResultException("imagecopy() returned false"); + } + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/Resize.php b/htdocs/libraries/WideImage/lib/Operation/Resize.php new file mode 100755 index 000000000000..c495b7cd3950 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/Resize.php @@ -0,0 +1,157 @@ +getWidth(); + $height = $img->getHeight(); + } + + if ($width !== null) + $width = WideImage_Coordinate::fix($width, $img->getWidth()); + + if ($height !== null) + $height = WideImage_Coordinate::fix($height, $img->getHeight()); + + if ($width === null) + $width = floor($img->getWidth() * $height / $img->getHeight()); + + if ($height === null) + $height = floor($img->getHeight() * $width / $img->getWidth()); + + if ($width === 0 || $height === 0) + return array('width' => 0, 'height' => 0); + + if ($fit == null) + $fit = 'inside'; + + $dim = array(); + if ($fit == 'fill') + { + $dim['width'] = $width; + $dim['height'] = $height; + } + elseif ($fit == 'inside' || $fit == 'outside') + { + $rx = $img->getWidth() / $width; + $ry = $img->getHeight() / $height; + + if ($fit == 'inside') + $ratio = ($rx > $ry) ? $rx : $ry; + else + $ratio = ($rx < $ry) ? $rx : $ry; + + $dim['width'] = round($img->getWidth() / $ratio); + $dim['height'] = round($img->getHeight() / $ratio); + } + else + throw new WideImage_Operation_InvalidFitMethodException("{$fit} is not a valid resize-fit method."); + + return $dim; + } + + /** + * Returns a resized image + * + * @param WideImage_Image $img + * @param smart_coordinate $width + * @param smart_coordinate $height + * @param string $fit + * @param string $scale + * @return WideImage_Image + */ + function execute($img, $width, $height, $fit, $scale) + { + $dim = $this->prepareDimensions($img, $width, $height, $fit); + if (($scale === 'down' && ($dim['width'] >= $img->getWidth() && $dim['height'] >= $img->getHeight())) || + ($scale === 'up' && ($dim['width'] <= $img->getWidth() && $dim['height'] <= $img->getHeight()))) + $dim = array('width' => $img->getWidth(), 'height' => $img->getHeight()); + + if ($dim['width'] <= 0 || $dim['height'] <= 0) + throw new WideImage_Operation_InvalidResizeDimensionException("Both dimensions must be larger than 0."); + + if ($img->isTransparent() || $img instanceof WideImage_PaletteImage) + { + $new = WideImage_PaletteImage::create($dim['width'], $dim['height']); + $new->copyTransparencyFrom($img); + if (!imagecopyresized( + $new->getHandle(), + $img->getHandle(), + 0, 0, 0, 0, + $new->getWidth(), + $new->getHeight(), + $img->getWidth(), + $img->getHeight())) + throw new WideImage_GDFunctionResultException("imagecopyresized() returned false"); + } + else + { + $new = WideImage_TrueColorImage::create($dim['width'], $dim['height']); + $new->alphaBlending(false); + $new->saveAlpha(true); + if (!imagecopyresampled( + $new->getHandle(), + $img->getHandle(), + 0, 0, 0, 0, + $new->getWidth(), + $new->getHeight(), + $img->getWidth(), + $img->getHeight())) + throw new WideImage_GDFunctionResultException("imagecopyresampled() returned false"); + $new->alphaBlending(true); + } + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/ResizeCanvas.php b/htdocs/libraries/WideImage/lib/Operation/ResizeCanvas.php new file mode 100644 index 000000000000..8262b15ae33d --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/ResizeCanvas.php @@ -0,0 +1,107 @@ +getWidth()); + $new_height = WideImage_Coordinate::fix($height, $img->getHeight()); + + if ($scale == 'down') + { + $new_width = min($new_width, $img->getWidth()); + $new_height = min($new_height, $img->getHeight()); + } + elseif ($scale == 'up') + { + $new_width = max($new_width, $img->getWidth()); + $new_height = max($new_height, $img->getHeight()); + } + + $new = WideImage::createTrueColorImage($new_width, $new_height); + if ($img->isTrueColor()) + { + if ($color === null) + $color = $new->allocateColorAlpha(0, 0, 0, 127); + } + else + { + imagepalettecopy($new->getHandle(), $img->getHandle()); + + if ($img->isTransparent()) + { + $new->copyTransparencyFrom($img); + $tc_rgb = $img->getTransparentColorRGB(); + $t_color = $new->allocateColorAlpha($tc_rgb); + } + + if ($color === null) + { + if ($img->isTransparent()) + $color = $t_color; + else + $color = $new->allocateColorAlpha(255, 0, 127, 127); + + imagecolortransparent($new->getHandle(), $color); + } + } + $new->fill(0, 0, $color); + + + $x = WideImage_Coordinate::fix($left, $new->getWidth(), $img->getWidth()); + $y = WideImage_Coordinate::fix($top, $new->getHeight(), $img->getHeight()); + + // blending for truecolor images + if ($img->isTrueColor()) + $new->alphaBlending($merge); + + // not-blending for palette images + if (!$merge && !$img->isTrueColor() && isset($t_color)) + $new->getCanvas()->filledRectangle($x, $y, $x + $img->getWidth(), $y + $img->getHeight(), $t_color); + + $img->copyTo($new, $x, $y); + return $new; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/Rotate.php b/htdocs/libraries/WideImage/lib/Operation/Rotate.php new file mode 100755 index 000000000000..690b04f521c2 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/Rotate.php @@ -0,0 +1,64 @@ +copy(); + + $image = $image->asTrueColor(); + + if ($bgColor === null) + { + $bgColor = $image->getTransparentColor(); + if ($bgColor == -1) + { + $bgColor = $image->allocateColorAlpha(255, 255, 255, 127); + imagecolortransparent($image->getHandle(), $bgColor); + } + } + return new WideImage_TrueColorImage(imagerotate($image->getHandle(), $angle, $bgColor, $ignoreTransparent)); + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/RoundCorners.php b/htdocs/libraries/WideImage/lib/Operation/RoundCorners.php new file mode 100644 index 000000000000..22eb84991b62 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/RoundCorners.php @@ -0,0 +1,114 @@ + 16) + $sample_ratio = 16; + else + $sample_ratio = $smoothness; + + $corner = WideImage::createTrueColorImage($radius * $sample_ratio, $radius * $sample_ratio); + if ($color === null) + { + imagepalettecopy($corner->getHandle(), $image->getHandle()); + $bg_color = $corner->allocateColor(0, 0, 0); + + $corner->fill(0, 0, $bg_color); + $fg_color = $corner->allocateColor(255, 255, 255); + $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color); + $corner = $corner->resize($radius, $radius); + + $result = $image->asTrueColor(); + + $tc = $result->getTransparentColor(); + if ($tc == -1) + { + $tc = $result->allocateColorAlpha(255, 255, 255, 127); + imagecolortransparent($result->getHandle(), $tc); + $result->setTransparentColor($tc); + } + + if ($corners & WideImage::SIDE_TOP_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_TOP) + $result = $result->applyMask($corner, -1, -1); + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_TOP_RIGHT || $corners & WideImage::SIDE_TOP || $corners & WideImage::SIDE_RIGHT) + $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100); + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_BOTTOM_RIGHT || $corners & WideImage::SIDE_RIGHT || $corners & WideImage::SIDE_BOTTOM) + $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100); + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_BOTTOM_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_BOTTOM) + $result = $result->applyMask($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100); + + return $result; + } + else + { + $bg_color = $color; + + $corner->fill(0, 0, $bg_color); + $fg_color = $corner->allocateColorAlpha(127, 127, 127, 127); + $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color); + $corner = $corner->resize($radius, $radius); + + $result = $image->copy(); + if ($corners & WideImage::SIDE_TOP_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_TOP) + $result = $result->merge($corner, -1, -1, 100); + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_TOP_RIGHT || $corners & WideImage::SIDE_TOP || $corners & WideImage::SIDE_RIGHT) + $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100); + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_BOTTOM_RIGHT || $corners & WideImage::SIDE_RIGHT || $corners & WideImage::SIDE_BOTTOM) + $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100); + + $corner = $corner->rotate(90); + if ($corners & WideImage::SIDE_BOTTOM_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_BOTTOM) + $result = $result->merge($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100); + + return $result; + } + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/Unsharp.php b/htdocs/libraries/WideImage/lib/Operation/Unsharp.php new file mode 100755 index 000000000000..4c5087e390fc --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/Unsharp.php @@ -0,0 +1,135 @@ + 500) $amount = 500; + $amount = $amount * 0.016; + if ($radius > 50) $radius = 50; + $radius = $radius * 2; + if ($threshold > 255) $threshold = 255; + + $radius = abs(round($radius)); // Only integers make sense. + if ($radius == 0) { + return $image; + } + + // Gaussian blur matrix + + $matrix = array( + array(1, 2, 1), + array(2, 4, 2), + array(1, 2, 1) + ); + + $blurred = $image->applyConvolution($matrix, 16, 0); + + if($threshold > 0) { + // Calculate the difference between the blurred pixels and the original + // and set the pixels + for ($x = 0; $x < $image->getWidth(); $x++) { + for ($y = 0; $y < $image->getHeight(); $y++) { + $rgbOrig = $image->getRGBAt($x, $y); + $rOrig = $rgbOrig["red"]; + $gOrig = $rgbOrig["green"]; + $bOrig = $rgbOrig["blue"]; + + $rgbBlur = $blurred->getRGBAt($x, $y); + $rBlur = $rgbBlur["red"]; + $gBlur = $rgbBlur["green"]; + $bBlur = $rgbBlur["blue"]; + + // When the masked pixels differ less from the original + // than the threshold specifies, they are set to their original value. + $rNew = (abs($rOrig - $rBlur) >= $threshold) + ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) + : $rOrig; + $gNew = (abs($gOrig - $gBlur) >= $threshold) + ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) + : $gOrig; + $bNew = (abs($bOrig - $bBlur) >= $threshold) + ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) + : $bOrig; + $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); + + if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) { + $image->setRGBAt($x, $y, $rgbNew); + } + } + } + } + else { + $w = $image->getWidth(); + $h = $image->getHeight(); + for ($x = 0; $x < $w; $x++) { + for ($y = 0; $y < $h; $y++) { + $rgbOrig = $image->getRGBAt($x, $y); + $rOrig = $rgbOrig["red"]; + $gOrig = $rgbOrig["green"]; + $bOrig = $rgbOrig["blue"]; + + $rgbBlur = $blurred->getRGBAt($x, $y); + $rBlur = $rgbBlur["red"]; + $gBlur = $rgbBlur["green"]; + $bBlur = $rgbBlur["blue"]; + + $rNew = ($amount * ($rOrig - $rBlur)) + $rOrig; + if($rNew>255){$rNew=255;} + elseif($rNew<0){$rNew=0;} + $gNew = ($amount * ($gOrig - $gBlur)) + $gOrig; + if($gNew>255){$gNew=255;} + elseif($gNew<0){$gNew=0;} + $bNew = ($amount * ($bOrig - $bBlur)) + $bOrig; + if($bNew>255){$bNew=255;} + elseif($bNew<0){$bNew=0;} + $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); + + $image->setRGBAt($x, $y, $rgbNew); + } + } + } + + return $image; + } + } diff --git a/htdocs/libraries/WideImage/lib/Operation/index.html b/htdocs/libraries/WideImage/lib/Operation/index.html new file mode 100644 index 000000000000..74b6f45c8f33 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/Operation/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/OperationFactory.php b/htdocs/libraries/WideImage/lib/OperationFactory.php new file mode 100755 index 000000000000..3a5f36c49161 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/OperationFactory.php @@ -0,0 +1,57 @@ +copy(); + } + + /** + * Returns a copy of the image + * + * @param $trueColor True if the new image should be truecolor + * @return WideImage_Image + */ + protected function copyAsNew($trueColor = false) + { + $width = $this->getWidth(); + $height = $this->getHeight(); + + if ($trueColor) + $new = WideImage_TrueColorImage::create($width, $height); + else + $new = WideImage_PaletteImage::create($width, $height); + + // copy transparency of source to target + if ($this->isTransparent()) + { + $rgb = $this->getTransparentColorRGB(); + if (is_array($rgb)) + { + $tci = $new->allocateColor($rgb['red'], $rgb['green'], $rgb['blue']); + $new->fill(0, 0, $tci); + $new->setTransparentColor($tci); + } + } + + imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height); + return $new; + } + + /** + * (non-PHPdoc) + * @see WideImage_Image#asTrueColor() + */ + function asTrueColor() + { + $width = $this->getWidth(); + $height = $this->getHeight(); + $new = WideImage::createTrueColorImage($width, $height); + if ($this->isTransparent()) + $new->copyTransparencyFrom($this); + if (!imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height)) + throw new WideImage_GDFunctionResultException("imagecopy() returned false"); + return $new; + } + + /** + * (non-PHPdoc) + * @see WideImage_Image#getChannels() + */ + function getChannels() + { + $args = func_get_args(); + if (count($args) == 1 && is_array($args[0])) + $args = $args[0]; + return WideImage_OperationFactory::get('CopyChannelsPalette')->execute($this, $args); + } + + /** + * (non-PHPdoc) + * @see WideImage_Image#copyNoAlpha() + */ + function copyNoAlpha() + { + return WideImage_Image::loadFromString($this->asString('png')); + } + } diff --git a/htdocs/libraries/WideImage/lib/README b/htdocs/libraries/WideImage/lib/README new file mode 100644 index 000000000000..7b265312db26 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/README @@ -0,0 +1,21 @@ +WideImage, a PHP image manipulation library +Copyright 2007-2011 Gasper Kozak + +For documentation, please visit http://wideimage.sourceforge.net/ + + + 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 diff --git a/htdocs/libraries/WideImage/lib/TrueColorImage.php b/htdocs/libraries/WideImage/lib/TrueColorImage.php new file mode 100755 index 000000000000..a4addcdfa73f --- /dev/null +++ b/htdocs/libraries/WideImage/lib/TrueColorImage.php @@ -0,0 +1,218 @@ +alphaBlending(false); + $this->saveAlpha(true); + } + + /** + * Factory method that creates a true-color image object + * + * @param int $width + * @param int $height + * @return WideImage_TrueColorImage + */ + static function create($width, $height) + { + if ($width * $height <= 0 || $width < 0) + throw new WideImage_InvalidImageDimensionException("Can't create an image with dimensions [$width, $height]."); + + return new WideImage_TrueColorImage(imagecreatetruecolor($width, $height)); + } + + function doCreate($width, $height) + { + return self::create($width, $height); + } + + function isTrueColor() + { + return true; + } + + /** + * Sets alpha blending mode via imagealphablending() + * + * @param bool $mode + * @return bool + */ + function alphaBlending($mode) + { + return imagealphablending($this->handle, $mode); + } + + /** + * Toggle if alpha channel should be saved with the image via imagesavealpha() + * + * @param bool $on + * @return bool + */ + function saveAlpha($on) + { + return imagesavealpha($this->handle, $on); + } + + /** + * Allocates a color and returns its index + * + * This method accepts either each component as an integer value, + * or an associative array that holds the color's components in keys + * 'red', 'green', 'blue', 'alpha'. + * + * @param mixed $R + * @param int $G + * @param int $B + * @param int $A + * @return int + */ + function allocateColorAlpha($R, $G = null, $B = null, $A = null) + { + if (is_array($R)) + return imageColorAllocateAlpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']); + else + return imageColorAllocateAlpha($this->handle, $R, $G, $B, $A); + } + + /** + * @see WideImage_Image#asPalette($nColors, $dither, $matchPalette) + */ + function asPalette($nColors = 255, $dither = null, $matchPalette = true) + { + $nColors = intval($nColors); + if ($nColors < 1) + $nColors = 1; + elseif ($nColors > 255) + $nColors = 255; + + if ($dither === null) + $dither = $this->isTransparent(); + + $temp = $this->copy(); + imagetruecolortopalette($temp->handle, $dither, $nColors); + if ($matchPalette == true && function_exists('imagecolormatch')) + imagecolormatch($this->handle, $temp->handle); + + // The code below isn't working properly; it corrupts transparency on some palette->tc->palette conversions. + // Why is this code here? + /* + if ($this->isTransparent()) + { + $trgb = $this->getTransparentColorRGB(); + $tci = $temp->getClosestColor($trgb); + $temp->setTransparentColor($tci); + } + /**/ + + $temp->releaseHandle(); + return new WideImage_PaletteImage($temp->handle); + } + + /** + * Returns the index of the color that best match the given color components + * + * This method accepts either each component as an integer value, + * or an associative array that holds the color's components in keys + * 'red', 'green', 'blue', 'alpha'. + * + * @param mixed $R Red component value or an associative array + * @param int $G Green component + * @param int $B Blue component + * @param int $A Alpha component + * @return int The color index + */ + function getClosestColorAlpha($R, $G = null, $B = null, $A = null) + { + if (is_array($R)) + return imagecolorclosestalpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']); + else + return imagecolorclosestalpha($this->handle, $R, $G, $B, $A); + } + + /** + * Returns the index of the color that exactly match the given color components + * + * This method accepts either each component as an integer value, + * or an associative array that holds the color's components in keys + * 'red', 'green', 'blue', 'alpha'. + * + * @param mixed $R Red component value or an associative array + * @param int $G Green component + * @param int $B Blue component + * @param int $A Alpha component + * @return int The color index + */ + function getExactColorAlpha($R, $G = null, $B = null, $A = null) + { + if (is_array($R)) + return imagecolorexactalpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']); + else + return imagecolorexactalpha($this->handle, $R, $G, $B, $A); + } + + /** + * @see WideImage_Image#getChannels() + */ + function getChannels() + { + $args = func_get_args(); + if (count($args) == 1 && is_array($args[0])) + $args = $args[0]; + return WideImage_OperationFactory::get('CopyChannelsTrueColor')->execute($this, $args); + } + + /** + * (non-PHPdoc) + * @see WideImage_Image#copyNoAlpha() + */ + function copyNoAlpha() + { + $prev = $this->saveAlpha(false); + $result = WideImage_Image::loadFromString($this->asString('png')); + $this->saveAlpha($prev); + //$result->releaseHandle(); + return $result; + } + + /** + * (non-PHPdoc) + * @see WideImage_Image#asTrueColor() + */ + function asTrueColor() + { + return $this->copy(); + } + } diff --git a/htdocs/libraries/WideImage/lib/VERSION b/htdocs/libraries/WideImage/lib/VERSION new file mode 100644 index 000000000000..d344316bbe4e --- /dev/null +++ b/htdocs/libraries/WideImage/lib/VERSION @@ -0,0 +1,2 @@ +Version: 11.02.19 +Build date: 2011-02-19 diff --git a/htdocs/libraries/WideImage/lib/WideImage.php b/htdocs/libraries/WideImage/lib/WideImage.php new file mode 100755 index 000000000000..fd5419f5d2fe --- /dev/null +++ b/htdocs/libraries/WideImage/lib/WideImage.php @@ -0,0 +1,377 @@ + + * WideImage::registerCustomMapper('WideImage_Mapper_TGA', 'image/tga', 'tga'); + * + * + * @param string $mapper_class_name + * @param string $mime_type + * @param string $extension + */ + static function registerCustomMapper($mapper_class_name, $mime_type, $extension) + { + WideImage_MapperFactory::registerMapper($mapper_class_name, $mime_type, strtoupper($extension)); + } + + /** + * Loads an image from a file, URL, HTML input file field, binary string, or a valid image handle. + * The image format is auto-detected. + * + * Currently supported formats: PNG, GIF, JPG, BMP, TGA, GD, GD2. + * + * This function analyzes the input and decides whether to use WideImage::loadFromHandle(), + * WideImage::loadFromFile(), WideImage::loadFromUpload() or WideImage::loadFromString(), + * all of which you can also call directly to spare WideImage some guessing. + * + * Arrays are supported for upload fields; it returns an array of loaded images. + * To load only a single image from an array field, use WideImage::loadFromUpload('img', $i), + * where $i is the index of the image you want to load. + * + * + * $img = WideImage::load('http://url/image.png'); // image URL + * $img = WideImage::load('/path/to/image.png'); // local file path + * $img = WideImage::load('img'); // upload field name + * $img = WideImage::load(imagecreatetruecolor(10, 10)); // a GD resource + * $img = WideImage::load($image_data); // binary string containing image data + * + * + * @param mixed $source File name, url, HTML file input field name, binary string, or a GD image resource + * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance + */ + static function load($source) + { + $predictedSourceType = ''; + + if ($source == '') + $predictedSourceType = 'String'; + + // Creating image via a valid resource + if (!$predictedSourceType && self::isValidImageHandle($source)) + $predictedSourceType = 'Handle'; + + // Check for binary string + if (!$predictedSourceType) + { + // search first $binLength bytes (at a maximum) for ord<32 characters (binary image data) + $binLength = 64; + $sourceLength = strlen($source); + $maxlen = ($sourceLength > $binLength) ? $binLength : $sourceLength; + for ($i = 0; $i < $maxlen; $i++) + if (ord($source[$i]) < 32) + { + $predictedSourceType = 'String'; + break; + } + } + + // Uploaded image (array uploads not supported) + if (isset($_FILES[$source]) && isset($_FILES[$source]['tmp_name'])) + $predictedSourceType = 'Upload'; + + // Otherwise, must be a file or an URL + if (!$predictedSourceType) + $predictedSourceType = 'File'; + + return call_user_func(array('WideImage', 'loadFrom' . $predictedSourceType), $source); + } + + /** + * Create and load an image from a file or URL. The image format is auto-detected. + * + * @param string $uri File or url + * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance + */ + static function loadFromFile($uri) + { + $data = file_get_contents($uri); + $handle = @imagecreatefromstring($data); + if (!self::isValidImageHandle($handle)) + { + try + { + // try to find a mapper first + $mapper = WideImage_MapperFactory::selectMapper($uri); + if ($mapper) + $handle = $mapper->load($uri); + } + catch (WideImage_UnsupportedFormatException $e) + { + // mapper not found + } + + // try all custom mappers + if (!self::isValidImageHandle($handle)) + { + $custom_mappers = WideImage_MapperFactory::getCustomMappers(); + foreach ($custom_mappers as $mime_type => $mapper_class) + { + $mapper = WideImage_MapperFactory::selectMapper(null, $mime_type); + $handle = $mapper->loadFromString($data); + if (self::isValidImageHandle($handle)) + break; + } + } + } + + if (!self::isValidImageHandle($handle)) + throw new WideImage_InvalidImageSourceException("File '{$uri}' appears to be an invalid image source."); + + return self::loadFromHandle($handle); + } + + /** + * Create and load an image from a string. Format is auto-detected. + * + * @param string $string Binary data, i.e. from BLOB field in the database + * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance + */ + static function loadFromString($string) + { + if (strlen($string) < 128) + throw new WideImage_InvalidImageSourceException("String doesn't contain image data."); + + $handle = @imagecreatefromstring($string); + if (!self::isValidImageHandle($handle)) + { + $custom_mappers = WideImage_MapperFactory::getCustomMappers(); + foreach ($custom_mappers as $mime_type => $mapper_class) + { + $mapper = WideImage_MapperFactory::selectMapper(null, $mime_type); + $handle = $mapper->loadFromString($string); + if (self::isValidImageHandle($handle)) + break; + } + } + + if (!self::isValidImageHandle($handle)) + throw new WideImage_InvalidImageSourceException("String doesn't contain valid image data."); + + return self::loadFromHandle($handle); + } + + /** + * Create and load an image from an image handle. + * + * Note: the resulting image object takes ownership of the passed + * handle. When the newly-created image object is destroyed, the handle is + * destroyed too, so it's not a valid image handle anymore. In order to + * preserve the handle for use after object destruction, you have to call + * WideImage_Image::releaseHandle() on the created image instance prior to its + * destruction. + * + * + * $handle = imagecreatefrompng('file.png'); + * $image = WideImage::loadFromHandle($handle); + * + * + * @param resource $handle A valid GD image resource + * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance + */ + static function loadFromHandle($handle) + { + if (!self::isValidImageHandle($handle)) + throw new WideImage_InvalidImageSourceException("Handle is not a valid GD image resource."); + + if (imageistruecolor($handle)) + return new WideImage_TrueColorImage($handle); + else + return new WideImage_PaletteImage($handle); + } + + /** + * This method loads a file from the $_FILES array. The image format is auto-detected. + * + * You only have to pass the field name as the parameter. For array fields, this function will + * return an array of image objects, unless you specify the $index parameter, which will + * load the desired image. + * + * @param $field_name Name of the key in $_FILES array + * @param int $index The index of the file to load (if the input field is an array) + * @return WideImage_Image The loaded image + */ + static function loadFromUpload($field_name, $index = null) + { + if (!array_key_exists($field_name, $_FILES)) + throw new WideImage_InvalidImageSourceException("Upload field '{$field_name}' doesn't exist."); + + if (is_array($_FILES[$field_name]['tmp_name'])) + { + if (isset($_FILES[$field_name]['tmp_name'][$index])) + $filename = $_FILES[$field_name]['tmp_name'][$index]; + else + { + $result = array(); + foreach ($_FILES[$field_name]['tmp_name'] as $idx => $tmp_name) + $result[$idx] = self::loadFromFile($tmp_name); + return $result; + } + } + else + $filename = $_FILES[$field_name]['tmp_name']; + + if (!file_exists($filename)) + throw new WideImage_InvalidImageSourceException("Uploaded file doesn't exist."); + return self::loadFromFile($filename); + } + + /** + * Factory method for creating a palette image + * + * @param int $width + * @param int $height + * @return WideImage_PaletteImage + */ + static function createPaletteImage($width, $height) + { + return WideImage_PaletteImage::create($width, $height); + } + + /** + * Factory method for creating a true-color image + * + * @param int $width + * @param int $height + * @return WideImage_TrueColorImage + */ + static function createTrueColorImage($width, $height) + { + return WideImage_TrueColorImage::create($width, $height); + } + + /** + * Check whether the given handle is a valid GD resource + * + * @param mixed $handle The variable to check + * @return bool + */ + static function isValidImageHandle($handle) + { + return (is_resource($handle) && get_resource_type($handle) == 'gd'); + } + + /** + * Throws exception if the handle isn't a valid GD resource + * + * @param mixed $handle The variable to check + */ + static function assertValidImageHandle($handle) + { + if (!self::isValidImageHandle($handle)) + throw new WideImage_InvalidImageHandleException("{$handle} is not a valid image handle."); + } + } + + WideImage::checkGD(); + + WideImage::registerCustomMapper('WideImage_Mapper_BMP', 'image/bmp', 'bmp'); + WideImage::registerCustomMapper('WideImage_Mapper_TGA', 'image/tga', 'tga'); + \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/gpl.txt b/htdocs/libraries/WideImage/lib/gpl.txt new file mode 100644 index 000000000000..82fa1daad468 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/gpl.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/htdocs/libraries/WideImage/lib/index.html b/htdocs/libraries/WideImage/lib/index.html new file mode 100644 index 000000000000..990cbd60372e --- /dev/null +++ b/htdocs/libraries/WideImage/lib/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/lgpl.txt b/htdocs/libraries/WideImage/lib/lgpl.txt new file mode 100644 index 000000000000..5ab7695ab8ca --- /dev/null +++ b/htdocs/libraries/WideImage/lib/lgpl.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/htdocs/libraries/WideImage/lib/vendor/JPEXS/bmp.php b/htdocs/libraries/WideImage/lib/vendor/JPEXS/bmp.php new file mode 100755 index 000000000000..77f7261b71b7 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/vendor/JPEXS/bmp.php @@ -0,0 +1,537 @@ +0)and($ColorCount<=2)) {$ColorCount=2; $BitCount=1;}; + if(($ColorCount>2)and($ColorCount<=16)) { $ColorCount=16; $BitCount=4;}; + if(($ColorCount>16)and($ColorCount<=256)) { $ColorCount=0; $BitCount=8;}; + + $Width=imagesx($img); + $Height=imagesy($img); + + $Zbytek=(4-($Width/(8/$BitCount))%4)%4; + + if($BitCount<24) $palsize=pow(2,$BitCount)*4; + + $size=(floor($Width/(8/$BitCount))+$Zbytek)*$Height+54; + $size+=$palsize; + $offset=54+$palsize; + + // Bitmap File Header + $ret = 'BM'; // header (2b) + $ret .= jpexs_int_to_dword($size); // size of file (4b) + $ret .= jpexs_int_to_dword(0); // reserved (4b) + $ret .= jpexs_int_to_dword($offset); // byte location in the file which is first byte of IMAGE (4b) + // Bitmap Info Header + $ret .= jpexs_int_to_dword(40); // Size of BITMAPINFOHEADER (4b) + $ret .= jpexs_int_to_dword($Width); // width of bitmap (4b) + $ret .= jpexs_int_to_dword($Height); // height of bitmap (4b) + $ret .= jpexs_int_to_word(1); // biPlanes = 1 (2b) + $ret .= jpexs_int_to_word($BitCount); // biBitCount = {1 (mono) or 4 (16 clr ) or 8 (256 clr) or 24 (16 Mil)} (2b) + $ret .= jpexs_int_to_dword($useRLE); // RLE COMPRESSION (4b) + $ret .= jpexs_int_to_dword(0); // width x height (4b) + $ret .= jpexs_int_to_dword(0); // biXPelsPerMeter (4b) + $ret .= jpexs_int_to_dword(0); // biYPelsPerMeter (4b) + $ret .= jpexs_int_to_dword(0); // Number of palettes used (4b) + $ret .= jpexs_int_to_dword(0); // Number of important colour (4b) + // image data + + $retd = ""; + + $CC=$ColorCount; + $sl1=strlen($ret); + if($CC==0) $CC=256; + if($BitCount<24) + { + $ColorTotal=imagecolorstotal($img); + if($IsTransparent) $ColorTotal--; + + for($p=0;$p<$ColorTotal;$p++) + { + $color=imagecolorsforindex($img,$p); + $ret.=jpexs_inttobyte($color["blue"]); + $ret.=jpexs_inttobyte($color["green"]); + $ret.=jpexs_inttobyte($color["red"]); + $ret.=jpexs_inttobyte(0); //RESERVED + }; + + $CT=$ColorTotal; + for($p=$ColorTotal;$p<$CC;$p++) + { + $ret.=jpexs_inttobyte(0); + $ret.=jpexs_inttobyte(0); + $ret.=jpexs_inttobyte(0); + $ret.=jpexs_inttobyte(0); //RESERVED + }; + }; + + + if($BitCount<=8) + { + + for($y=$Height-1;$y>=0;$y--) + { + $bWrite=""; + for($x=0;$x<$Width;$x++) + { + $color=imagecolorat($img,$x,$y); + $bWrite.=jpexs_decbinx($color,$BitCount); + if(strlen($bWrite)==8) + { + $retd.=jpexs_inttobyte(bindec($bWrite)); + $bWrite=""; + }; + }; + + if((strlen($bWrite)<8)and(strlen($bWrite)!=0)) + { + $sl=strlen($bWrite); + for($t=0;$t<8-$sl;$t++) + $sl.="0"; + $retd.=jpexs_inttobyte(bindec($bWrite)); + }; + for($z=0;$z<$Zbytek;$z++) + $retd.=jpexs_inttobyte(0); + }; + }; + + if(($useRLE)and($BitCount==8)) + { + for($t=0;$t=0;$y--) + { + for($x=0;$x<$Width;$x++) + { + $color=imagecolorsforindex($img,ImageColorAt($img,$x,$y)); + $ret.=chr($color["blue"]).chr($color["green"]).chr($color["red"]); + } + $ret.=$Dopl; + }; + + }; + + if($file!="") + { + $r=($f=fopen($file,"w")); + $r=$r and fwrite($f,$ret); + $r=$r and fclose($f); + return $r; + } + else + { + echo $ret; + }; +}; + + +/** + * Reads image from a BMP file and converts it to image resource + * @global int $jpexs_CurrentBit Internal variable + * @param string $file File to read BMP image from + * @return resource Image resource or false on error + * + * Note: + * Reading RLE compressed bitmaps is EXPERIMENTAL + * Reading palette based bitmaps with less than 8bit palette is EXPERIMENTAL + */ +function imagecreatefrombmp($file) +{ + global $jpexs_CurrentBit; + + $f=fopen($file,"r"); + $Header=fread($f,2); + + if($Header=="BM") + { + $Size=jpexs_freaddword($f); + $Reserved1=jpexs_freadword($f); + $Reserved2=jpexs_freadword($f); + $FirstByteOfImage=jpexs_freaddword($f); + + $SizeBITMAPINFOHEADER=jpexs_freaddword($f); + $Width=jpexs_freaddword($f); + $Height=jpexs_freaddword($f); + $biPlanes=jpexs_freadword($f); + $biBitCount=jpexs_freadword($f); + $RLECompression=jpexs_freaddword($f); + $WidthxHeight=jpexs_freaddword($f); + $biXPelsPerMeter=jpexs_freaddword($f); + $biYPelsPerMeter=jpexs_freaddword($f); + $NumberOfPalettesUsed=jpexs_freaddword($f); + $NumberOfImportantColors=jpexs_freaddword($f); + + if($biBitCount<24) + { + $img=imagecreate($Width,$Height); + $Colors=pow(2,$biBitCount); + for($p=0;$p<$Colors;$p++) + { + $B=jpexs_freadbyte($f); + $G=jpexs_freadbyte($f); + $R=jpexs_freadbyte($f); + $Reserved=jpexs_freadbyte($f); + $Palette[]=imagecolorallocate($img,$R,$G,$B); + }; + + + + + if($RLECompression==0) + { + $Zbytek=(4-ceil(($Width/(8/$biBitCount)))%4)%4; + + for($y=$Height-1;$y>=0;$y--) + { + $jpexs_CurrentBit=0; + for($x=0;$x<$Width;$x++) + { + $C=jpexs_freadbits($f,$biBitCount); + imagesetpixel($img,$x,$y,$Palette[$C]); + }; + if($jpexs_CurrentBit!=0) {jpexs_freadbyte($f);}; + for($g=0;$g<$Zbytek;$g++) + jpexs_freadbyte($f); + }; + + }; + }; + + + if($RLECompression==1) //$BI_RLE8 + { + $y=$Height; + + $pocetb=0; + + while(true) + { + $y--; + $prefix=jpexs_freadbyte($f); + $suffix=jpexs_freadbyte($f); + $pocetb+=2; + + $echoit=false; + + if($echoit)echo "Prefix: $prefix Suffix: $suffix
"; + if(($prefix==0)and($suffix==1)) break; + if(feof($f)) break; + + while(!(($prefix==0)and($suffix==0))) + { + if($prefix==0) + { + $pocet=$suffix; + $Data.=fread($f,$pocet); + $pocetb+=$pocet; + if($pocetb%2==1) {jpexs_freadbyte($f); $pocetb++;}; + }; + if($prefix>0) + { + $pocet=$prefix; + for($r=0;$r<$pocet;$r++) + $Data.=chr($suffix); + }; + $prefix=jpexs_freadbyte($f); + $suffix=jpexs_freadbyte($f); + $pocetb+=2; + if($echoit) echo "Prefix: $prefix Suffix: $suffix
"; + }; + + for($x=0;$x";*/ + while(true) + { + //break; + $y--; + $prefix=jpexs_freadbyte($f); + $suffix=jpexs_freadbyte($f); + $pocetb+=2; + + $echoit=false; + + if($echoit)echo "Prefix: $prefix Suffix: $suffix
"; + if(($prefix==0)and($suffix==1)) break; + if(feof($f)) break; + + while(!(($prefix==0)and($suffix==0))) + { + if($prefix==0) + { + $pocet=$suffix; + + $jpexs_CurrentBit=0; + for($h=0;$h<$pocet;$h++) + $Data.=chr(jpexs_freadbits($f,4)); + if($jpexs_CurrentBit!=0) jpexs_freadbits($f,4); + $pocetb+=ceil(($pocet/2)); + if($pocetb%2==1) {jpexs_freadbyte($f); $pocetb++;}; + }; + if($prefix>0) + { + $pocet=$prefix; + $i=0; + for($r=0;$r<$pocet;$r++) + { + if($i%2==0) + { + $Data.=chr($suffix%16); + } + else + { + $Data.=chr(floor($suffix/16)); + }; + $i++; + }; + }; + $prefix=jpexs_freadbyte($f); + $suffix=jpexs_freadbyte($f); + $pocetb+=2; + if($echoit) echo "Prefix: $prefix Suffix: $suffix
"; + }; + + for($x=0;$x=0;$y--) + { + for($x=0;$x<$Width;$x++) + { + $B=jpexs_freadbyte($f); + $G=jpexs_freadbyte($f); + $R=jpexs_freadbyte($f); + $color=imagecolorexact($img,$R,$G,$B); + if($color==-1) $color=imagecolorallocate($img,$R,$G,$B); + imagesetpixel($img,$x,$y,$color); + } + for($z=0;$z<$Zbytek;$z++) + jpexs_freadbyte($f); + }; + }; + return $img; + + } + else{ + return false; + } + + + fclose($f); + + +}; + + + + + +/* + * Internal functions: + *------------------------- + * + * jpexs_freadbyte($file) - reads 1 byte from $file + * jpexs_freadword($file) - reads 2 bytes (1 word) from $file + * jpexs_freaddword($file) - reads 4 bytes (1 dword) from $file + * jpexs_freadlngint($file) - same as freaddword($file) + * jpexs_decbin8($d) - returns binary string of d zero filled to 8 + * jpexs_retBits($byte,$start,$len) - returns bits $start->$start+$len from $byte + * jpexs_freadbits($file,$count) - reads next $count bits from $file + * jpexs_int_to_dword($n) - returns 4 byte representation of $n + * jpexs_int_to_word($n) - returns 2 byte representation of $n + */ + +function jpexs_freadbyte($f) +{ + return ord(fread($f,1)); +}; + +function jpexs_freadword($f) +{ + $b1=jpexs_freadbyte($f); + $b2=jpexs_freadbyte($f); + return $b2*256+$b1; +}; + + +function jpexs_freadlngint($f) +{ + return jpexs_freaddword($f); +}; + +function jpexs_freaddword($f) +{ + $b1=jpexs_freadword($f); + $b2=jpexs_freadword($f); + return $b2*65536+$b1; +}; + + + +function jpexs_retBits($byte,$start,$len) +{ + $bin=jpexs_decbin8($byte); + $r=bindec(substr($bin,$start,$len)); + return $r; + +}; + + + +$jpexs_CurrentBit=0; +function jpexs_freadbits($f,$count) +{ + global $jpexs_CurrentBit,$SMode; + $Byte=jpexs_freadbyte($f); + $LastCBit=$jpexs_CurrentBit; + $jpexs_CurrentBit+=$count; + if($jpexs_CurrentBit==8) + { + $jpexs_CurrentBit=0; + } + else + { + fseek($f,ftell($f)-1); + }; + return jpexs_retBits($Byte,$LastCBit,$count); +}; + + + +function jpexs_int_to_dword($n) +{ + return chr($n & 255).chr(($n >> 8) & 255).chr(($n >> 16) & 255).chr(($n >> 24) & 255); +} +function jpexs_int_to_word($n) +{ + return chr($n & 255).chr(($n >> 8) & 255); +} + + +function jpexs_decbin8($d) +{ + return jpexs_decbinx($d,8); +}; + +function jpexs_decbinx($d,$n) +{ + $bin=decbin($d); + $sbin=strlen($bin); + for($j=0;$j<$n-$sbin;$j++) + $bin="0$bin"; + return $bin; +}; + +function jpexs_inttobyte($n) +{ + return chr($n); +}; + +?> \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/vendor/JPEXS/ico.php b/htdocs/libraries/WideImage/lib/vendor/JPEXS/ico.php new file mode 100755 index 000000000000..f4290fc2e405 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/vendor/JPEXS/ico.php @@ -0,0 +1,965 @@ +=$Ikona[$ColMax]["NumberOfColors"])) +if(($icoSize==$Ikona[$p]["Width"])or($icoSize==ICO_MAX_SIZE)) + { + $ColMax=$p; + }; + +if(($SizeMax==-1)or($Ikona[$p]["Width"]>=$Ikona[$SizeMax]["Width"])) +if(($icoColorCount==$Ikona[$p]["NumberOfColors"])or($icoColorCount==ICO_MAX_COLOR)) + { + $SizeMax=$p; + }; + + +if($Ikona[$p]["NumberOfColors"]==$icoColorCount) +if($Ikona[$p]["Width"]==$icoSize) + { + + $IconID=$p; + }; +}; + + if($icoColorCount==ICO_MAX_COLOR) $IconID=$ColMax; + if($icoSize==ICO_MAX_SIZE) $IconID=$SizeMax; + +$ColName=$icoColorCount; + +if($icoSize==ICO_MAX_SIZE) $icoSize="Max"; +if($ColName==ICO_TRUE_COLOR) $ColName="True"; +if($ColName==ICO_XP_COLOR) $ColName="XP"; +if($ColName==ICO_MAX_COLOR) $ColName="Max"; +if($IconID==-1) die("Icon with $ColName colors and $icoSize x $icoSize size doesn't exist in this file!"); + + +jpexs_readIcon($filename,$IconID,$Ikona); + + $biBitCount=$Ikona[$IconID]["Info"]["BitsPerPixel"]; + + + if($Ikona[$IconID]["Info"]["BitsPerPixel"]==0) + { + $Ikona[$IconID]["Info"]["BitsPerPixel"]=24; + }; + + $biBitCount=$Ikona[$IconID]["Info"]["BitsPerPixel"]; + if($biBitCount==0) $biBitCount=1; + + +$Ikona[$IconID]["BitCount"]=$Ikona[$IconID]["Info"]["BitsPerPixel"]; + + + +if($Ikona[$IconID]["BitCount"]>=24) +{ +$img=imagecreatetruecolor($Ikona[$IconID]["Width"],$Ikona[$IconID]["Height"]); +if($Ikona[$IconID]["BitCount"]==32): + $backcolor=imagecolorallocate($img,$alphaBgR,$alphaBgG,$alphaBgB); + imagefilledrectangle($img,0,0,$Ikona[$IconID]["Width"]-1,$Ikona[$IconID]["Height"]-1,$backcolor); +endif; +for($y=0;$y<$Ikona[$IconID]["Height"];$y++) +for($x=0;$x<$Ikona[$IconID]["Width"];$x++) + { + $R=$Ikona[$IconID]["Data"][$x][$y]["r"]; + $G=$Ikona[$IconID]["Data"][$x][$y]["g"]; + $B=$Ikona[$IconID]["Data"][$x][$y]["b"]; + if($Ikona[$IconID]["BitCount"]==32) + { + $Alpha=127-round($Ikona[$IconID]["Data"][$x][$y]["alpha"]*127/255); + if($Ikona[$IconID]["Maska"][$x][$y]==1) $Alpha=127; + $color=imagecolorexactalpha($img,$R,$G,$B,$Alpha); + if($color==-1) $color=imagecolorallocatealpha($img,$R,$G,$B,$Alpha); + } + else + { + $color=imagecolorexact($img,$R,$G,$B); + if($color==-1) $color=imagecolorallocate($img,$R,$G,$B); + }; + + imagesetpixel($img,$x,$y,$color); + + }; + +} +else +{ +$img=imagecreate($Ikona[$IconID]["Width"],$Ikona[$IconID]["Height"]); +for($p=0;$p=24)or(imagecolorstotal($img)>=256)) + { + $img2=imagecreatetruecolor(imagesx($img),imagesy($img)); + imagecopy($img2,$img,0,0,0,0,imagesx($img),imagesy($img)); + imagedestroy($img); + $img=$img2; + imagetruecolortopalette($img,true,255); + + }; + $Pruhledna=imagecolorallocate($img,0,0,0); + for($y=0;$y<$Ikona[$IconID]["Height"];$y++) + for($x=0;$x<$Ikona[$IconID]["Width"];$x++) + if($Ikona[$IconID]["Maska"][$x][$y]==1) + { + imagesetpixel($img,$x,$y,$Pruhledna); + }; + imagecolortransparent($img,$Pruhledna); + }; + +return $img; + + +}; + + + + +function jpexs_readIcon($filename,$id,&$Ikona) +{ +global $jpexs_currentBit; + +$f=fopen($filename,"rb"); + +fseek($f,6+$id*16); + $Width=jpexs_freadbyte($f); + $Height=jpexs_freadbyte($f); +fseek($f,6+$id*16+12); +$OffSet=jpexs_freaddword($f); +fseek($f,$OffSet); + +$p=$id; + + $Ikona[$p]["Info"]["HeaderSize"]=jpexs_freadlngint($f); + $Ikona[$p]["Info"]["ImageWidth"]=jpexs_freadlngint($f); + $Ikona[$p]["Info"]["ImageHeight"]=jpexs_freadlngint($f); + $Ikona[$p]["Info"]["NumberOfImagePlanes"]=jpexs_freadword($f); + $Ikona[$p]["Info"]["BitsPerPixel"]=jpexs_freadword($f); + $Ikona[$p]["Info"]["CompressionMethod"]=jpexs_freadlngint($f); + $Ikona[$p]["Info"]["SizeOfBitmap"]=jpexs_freadlngint($f); + $Ikona[$p]["Info"]["HorzResolution"]=jpexs_freadlngint($f); + $Ikona[$p]["Info"]["VertResolution"]=jpexs_freadlngint($f); + $Ikona[$p]["Info"]["NumColorUsed"]=jpexs_freadlngint($f); + $Ikona[$p]["Info"]["NumSignificantColors"]=jpexs_freadlngint($f); + + + $biBitCount=$Ikona[$p]["Info"]["BitsPerPixel"]; + + if($Ikona[$p]["Info"]["BitsPerPixel"]<=8) + { + + $barev=pow(2,$biBitCount); + + for($b=0;$b<$barev;$b++) + { + $Ikona[$p]["Paleta"][$b]["b"]=jpexs_freadbyte($f); + $Ikona[$p]["Paleta"][$b]["g"]=jpexs_freadbyte($f); + $Ikona[$p]["Paleta"][$b]["r"]=jpexs_freadbyte($f); + jpexs_freadbyte($f); + }; + +$Zbytek=(4-ceil(($Width/(8/$biBitCount)))%4)%4; + + +for($y=$Height-1;$y>=0;$y--) + { + $jpexs_currentBit=0; + for($x=0;$x<$Width;$x++) + { + $C=jpexs_freadbits($f,$biBitCount); + $Ikona[$p]["Data"][$x][$y]=$C; + }; + + if($jpexs_currentBit!=0) {jpexs_freadbyte($f);}; + for($g=0;$g<$Zbytek;$g++) + jpexs_freadbyte($f); + }; + +} +elseif($biBitCount==24) +{ + $Zbytek=$Width%4; + + for($y=$Height-1;$y>=0;$y--) + { + for($x=0;$x<$Width;$x++) + { + $B=jpexs_freadbyte($f); + $G=jpexs_freadbyte($f); + $R=jpexs_freadbyte($f); + $Ikona[$p]["Data"][$x][$y]["r"]=$R; + $Ikona[$p]["Data"][$x][$y]["g"]=$G; + $Ikona[$p]["Data"][$x][$y]["b"]=$B; + } + for($z=0;$z<$Zbytek;$z++) + jpexs_freadbyte($f); + }; +} +elseif($biBitCount==32) +{ + $Zbytek=$Width%4; + + for($y=$Height-1;$y>=0;$y--) + { + for($x=0;$x<$Width;$x++) + { + $B=jpexs_freadbyte($f); + $G=jpexs_freadbyte($f); + $R=jpexs_freadbyte($f); + $Alpha=jpexs_freadbyte($f); + $Ikona[$p]["Data"][$x][$y]["r"]=$R; + $Ikona[$p]["Data"][$x][$y]["g"]=$G; + $Ikona[$p]["Data"][$x][$y]["b"]=$B; + $Ikona[$p]["Data"][$x][$y]["alpha"]=$Alpha; + } + for($z=0;$z<$Zbytek;$z++) + jpexs_freadbyte($f); + }; +}; + + +//Maska +$Zbytek=(4-ceil(($Width/(8)))%4)%4; +for($y=$Height-1;$y>=0;$y--) + { + $jpexs_currentBit=0; + for($x=0;$x<$Width;$x++) + { + $C=jpexs_freadbits($f,1); + $Ikona[$p]["Maska"][$x][$y]=$C; + }; + if($jpexs_currentBit!=0) {jpexs_freadbyte($f);}; + for($g=0;$g<$Zbytek;$g++) + jpexs_freadbyte($f); + }; +//-------------- + +fclose($f); + +}; + +function jpexs_GetIconsInfo($filename) +{ +global $jpexs_currentBit; + +$f=fopen($filename,"rb"); + +$Reserved=jpexs_freadword($f); +$Type=jpexs_freadword($f); +$Count=jpexs_freadword($f); +for($p=0;$p<$Count;$p++) + { + $Ikona[$p]["Width"]=jpexs_freadbyte($f); + $Ikona[$p]["Height"]=jpexs_freadbyte($f); + $Ikona[$p]["ColorCount"]=jpexs_freadword($f); + if($Ikona[$p]["ColorCount"]==0) $Ikona[$p]["ColorCount"]=256; + $Ikona[$p]["Planes"]=jpexs_freadword($f); + $Ikona[$p]["BitCount"]=jpexs_freadword($f); + $Ikona[$p]["BytesInRes"]=jpexs_freaddword($f); + $Ikona[$p]["ImageOffset"]=jpexs_freaddword($f); + }; + +if(!feof($f)): + for($p=0;$p<$Count;$p++) + { + fseek($f,$Ikona[$p]["ImageOffset"]+14); + $Ikona[$p]["Info"]["BitsPerPixel"]=jpexs_freadword($f); + }; +endif; +fclose($f); +return $Ikona; +}; + + + + +/** + * Reads image from a icon in exe file + * @param string $filename Target exefile + * @param int $icoIndex Index of the icon in exefile + * @param int $icoColorCount Icon color count (For multiple icons ico file) - 2,16,256, ICO_TRUE_COLOR, ICO_XP_COLOR or ICO_MAX_COLOR + * @param int $icoSize Icon width (For multiple icons ico file) or ICO_MAX_SIZE + * @param int $alphaBgR Background color R value for alpha-channel images (Default is White) + * @param int $alphaBgG Background color G value for alpha-channel images (Default is White) + * @param int $alphaBgB Background color B value for alpha-channel images (Default is White) + * @return resource Image resource or false on error + */ +function imageCreateFromExeIco($filename,$icoIndex,$icoColorCount=16,$icoSize=16,$alphaBgR=255,$alphaBgG=255,$alphaBgB=255) +{ + $ok=saveExeIcon($filename,"icotemp.dat",$icoIndex); + if(!$ok): + $im=false; + else: + $im=imageCreateFromIco("icotemp.dat",$icoColorCount,$icoSize,$alphaBgR,$alphaBgG,$alphaBgB); + unlink("icotemp.dat"); + endif; + return $im; +}; + + +/** + * Saves icon(s) from the exe file + * @global int $jpexs_StartOfRsrc Internal reserved variable + * @global int $jpexs_ImageBase Internal reserved variable + * @global int $jpexs_ResVirtualAddress Internal reserved variable + * @param string $filename Target exefile + * @param string $icoFileNameOrPath Filename to save ico or path (Default "") Path if you want more than 1 icon. If "", the filename is "$icoIndex.ico" + * @param int|array $iconIndex Index(es) of the icon in exefile (Default -1) If -1, all icons are saved, Can be an array of indexes. + * @return boolean True on successful save + */ +function saveExeIcon($filename,$icoFileNameOrPath="",$iconIndex=-1) /*-1 for all,or can be array*/ +{ + global $jpexs_f,$jpexs_StartOfRsrc,$jpexs_ImageBase,$jpexs_ResVirtualAddress; + $jpexs_f=fopen($filename,"r"); + $MZ=fread($jpexs_f,2); + if($MZ!="MZ") NotValidExe(); + fseek($jpexs_f,60); + $OffsetToNewHeader=jpexs_freaddword($jpexs_f); + fseek($jpexs_f,$OffsetToNewHeader); + $PE=fread($jpexs_f,2); + if($PE!="PE") NotValidExe(); + fread($jpexs_f,4); + $NumberOfSections=jpexs_freadword($jpexs_f); + fseek($jpexs_f,ftell($jpexs_f)+12); + $SizeOfOptionalHeader=jpexs_freadword($jpexs_f); + $PosMagic=ftell($jpexs_f)+2; + fseek($jpexs_f,$PosMagic+$SizeOfOptionalHeader); + + for($p=0;$p<$NumberOfSections;$p++): + $SectionName[$p]=trim(fread($jpexs_f,8)); + $VirtualSize[$p]=jpexs_freaddword($jpexs_f); + $VirtualAddress[$p]=jpexs_freaddword($jpexs_f); + $PhysicalSize[$p]=jpexs_freaddword($jpexs_f); + $PhysicalOffset[$p]=jpexs_freaddword($jpexs_f); + fread($jpexs_f,16); + if($SectionName[$p]==".rsrc"): + $jpexs_ResVirtualAddress=$VirtualAddress[$p]; + fseek($jpexs_f,$PhysicalOffset[$p]); + $jpexs_StartOfRsrc=$PhysicalOffset[$p]; + jpexs_readResDirectoryEntry($R,$PhysicalOffset[$p]); + $IconCount=null; + $Ikona=null; + while (list ($key, $val) = each ($R["Subdir"])): + if($key==14): + $r=0; + while (list ($key2, $val2) = each ($R["Subdir"][$key]["Subdir"])): + while (list ($key3, $val3) = each ($R["Subdir"][$key]["Subdir"][$key2]["Subdir"])): + fseek($jpexs_f,$val3["DataOffset"]); + $Reserved=jpexs_freadword($jpexs_f); + $Type=jpexs_freadword($jpexs_f); + $ic=jpexs_freadword($jpexs_f); + $IconCount[]=$ic; + for($s=0;$s<$ic;$s++) + { + $Ikona[$r][$s]["Width"]=jpexs_freadbyte($jpexs_f); + $Ikona[$r][$s]["Height"]=jpexs_freadbyte($jpexs_f); + $Ikona[$r][$s]["ColorCount"]=jpexs_freadword($jpexs_f); + $Ikona[$r][$s]["Planes"]=jpexs_freadword($jpexs_f); + $Ikona[$r][$s]["BitCount"]=jpexs_freadword($jpexs_f); + $Ikona[$r][$s]["BytesInRes"]=jpexs_freaddword($jpexs_f); + $Ikona[$r][$s]["IconId"]=jpexs_freadword($jpexs_f); + }; + fseek($jpexs_f,$val3["DataOffset"]); + $r++; + endwhile; + endwhile; + endif; + endwhile; + + reset ($R["Subdir"]); + + while (list ($key, $val) = each ($R["Subdir"])): + if($key==3): + while (list ($key2, $val2) = each ($R["Subdir"][$key]["Subdir"])): + for($r=0;$r=0x80000000): + //String Name + $ResNameOffset=$ResName-0x80000000; + fseek($jpexs_f,$jpexs_StartOfRsrc+$ResNameOffset); + $StringLength=jpexs_freadword($jpexs_f); + $Identificator=(fread($jpexs_f,$StringLength*2)); + fseek($jpexs_f,$lastPos2); + else: + //Integer Id + $Identificator=$ResName; + endif; + + $ResOffsetToData=jpexs_freaddword($jpexs_f); + if($ResOffsetToData>=0x80000000): + $SubResOffset=$ResOffsetToData-0x80000000; + jpexs_readResDirectoryEntry($Res["$Identificator"],$jpexs_StartOfRsrc+$SubResOffset); + else: + $RawDataOffset=$ResOffsetToData; + $lastPos2=ftell($jpexs_f); + fseek($jpexs_f,$jpexs_StartOfRsrc+$RawDataOffset); + //IMAGE_RESOURCE_DATA_ENTRY + $OffsetToData=jpexs_freaddword($jpexs_f); + $Res["$Identificator"]["DataOffset"]=$jpexs_StartOfRsrc-$jpexs_ResVirtualAddress+$OffsetToData; + $Res["$Identificator"]["DataSize"]=jpexs_freaddword($jpexs_f); + $CodePage=jpexs_freaddword($jpexs_f); + $Reserved=jpexs_freaddword($jpexs_f); + fseek($jpexs_f,$lastPos2); + endif; + endfor; +fseek($jpexs_f,$lastPos); +$parentRes["Subdir"]=$Res; +}; + +/** + * Creates ico file from image resource(s) + * @param resource|array $images Target Image resource (Can be array of image resources) + * @param string $filename Target ico file to save icon to, If ommited or "", image is written to snadard output - use header("Content-type: image/x-icon"); */ +function imageIco($images,$filename="") +{ + +if(is_array($images)) +{ +$ImageCount=count($images); +$Image=$images; +} +else +{ +$Image[0]=$images; +$ImageCount=1; +}; + + +$WriteToFile=false; + +if($filename!="") +{ +$WriteToFile=true; +}; + + +$ret=""; + +$ret.=jpexs_inttoword(0); //PASSWORD +$ret.=jpexs_inttoword(1); //SOURCE +$ret.=jpexs_inttoword($ImageCount); //ICONCOUNT + + +for($q=0;$q<$ImageCount;$q++) +{ +$img=$Image[$q]; + +$Width=imagesx($img); +$Height=imagesy($img); + +$ColorCount=imagecolorstotal($img); + +$Transparent=imagecolortransparent($img); +$IsTransparent=$Transparent!=-1; + + +if($IsTransparent) $ColorCount--; + +if($ColorCount==0) {$ColorCount=0; $BitCount=24;}; +if(($ColorCount>0)and($ColorCount<=2)) {$ColorCount=2; $BitCount=1;}; +if(($ColorCount>2)and($ColorCount<=16)) { $ColorCount=16; $BitCount=4;}; +if(($ColorCount>16)and($ColorCount<=256)) { $ColorCount=0; $BitCount=8;}; + + + + + +//ICONINFO: +$ret.=jpexs_inttobyte($Width);// +$ret.=jpexs_inttobyte($Height);// +$ret.=jpexs_inttobyte($ColorCount);// +$ret.=jpexs_inttobyte(0);//RESERVED + +$Planes=0; +if($BitCount>=8) $Planes=1; + +$ret.=jpexs_inttoword($f,$Planes);//PLANES +if($BitCount>=8) $WBitCount=$BitCount; +if($BitCount==4) $WBitCount=0; +if($BitCount==1) $WBitCount=0; +$ret.=jpexs_inttoword($WBitCount);//BITS + +$Zbytek=(4-($Width/(8/$BitCount))%4)%4; +$ZbytekMask=(4-($Width/8)%4)%4; + +$PalSize=0; + +$Size=40+($Width/(8/$BitCount)+$Zbytek)*$Height+(($Width/8+$ZbytekMask) * $Height); +if($BitCount<24) + $Size+=pow(2,$BitCount)*4; +$IconId=1; +$ret.=jpexs_inttodword($Size); //SIZE +$OffSet=6+16*$ImageCount+$FullSize; +$ret.=jpexs_inttodword(6+16*$ImageCount+$FullSize);//OFFSET +$FullSize+=$Size; +//------------- + +}; + + +for($q=0;$q<$ImageCount;$q++) +{ +$img=$Image[$q]; +$Width=imagesx($img); +$Height=imagesy($img); +$ColorCount=imagecolorstotal($img); + +$Transparent=imagecolortransparent($img); +$IsTransparent=$Transparent!=-1; + +if($IsTransparent) $ColorCount--; +if($ColorCount==0) {$ColorCount=0; $BitCount=24;}; +if(($ColorCount>0)and($ColorCount<=2)) {$ColorCount=2; $BitCount=1;}; +if(($ColorCount>2)and($ColorCount<=16)) { $ColorCount=16; $BitCount=4;}; +if(($ColorCount>16)and($ColorCount<=256)) { $ColorCount=0; $BitCount=8;}; + + + +//ICONS +$ret.=jpexs_inttodword(40);//HEADSIZE +$ret.=jpexs_inttodword($Width);// +$ret.=jpexs_inttodword(2*$Height);// +$ret.=jpexs_inttoword(1); //PLANES +$ret.=jpexs_inttoword($BitCount); // +$ret.=jpexs_inttodword(0);//Compress method + + +$ZbytekMask=($Width/8)%4; + +$Zbytek=($Width/(8/$BitCount))%4; +$Size=($Width/(8/$BitCount)+$Zbytek)*$Height+(($Width/8+$ZbytekMask) * $Height); + +$ret.=jpexs_inttodword($Size);//SIZE + +$ret.=jpexs_inttodword(0);//HPIXEL_M +$ret.=jpexs_inttodword(0);//V_PIXEL_M +$ret.=jpexs_inttodword($ColorCount); //UCOLORS +$ret.=jpexs_inttodword(0); //DCOLORS +//--------------- + + +$CC=$ColorCount; +if($CC==0) $CC=256; + +if($BitCount<24) +{ + $ColorTotal=imagecolorstotal($img); + if($IsTransparent) $ColorTotal--; + + for($p=0;$p<$ColorTotal;$p++) + { + $color=imagecolorsforindex($img,$p); + $ret.=jpexs_inttobyte($color["blue"]); + $ret.=jpexs_inttobyte($color["green"]); + $ret.=jpexs_inttobyte($color["red"]); + $ret.=jpexs_inttobyte(0); //RESERVED + }; + + $CT=$ColorTotal; + for($p=$ColorTotal;$p<$CC;$p++) + { + $ret.=jpexs_inttobyte(0); + $ret.=jpexs_inttobyte(0); + $ret.=jpexs_inttobyte(0); + $ret.=jpexs_inttobyte(0); //RESERVED + }; +}; + + + + + + +if($BitCount<=8) +{ + + for($y=$Height-1;$y>=0;$y--) + { + $bWrite=""; + for($x=0;$x<$Width;$x++) + { + $color=imagecolorat($img,$x,$y); + if($color==$Transparent) + $color=imagecolorexact($img,0,0,0); + if($color==-1) $color=0; + if($color>pow(2,$BitCount)-1) $color=0; + + $bWrite.=jpexs_decbinx($color,$BitCount); + if(strlen($bWrite)==8) + { + $ret.=jpexs_inttobyte(bindec($bWrite)); + $bWrite=""; + }; + }; + + if((strlen($bWrite)<8)and(strlen($bWrite)!=0)) + { + $sl=strlen($bWrite); + for($t=0;$t<8-$sl;$t++) + $sl.="0"; + $ret.=jpexs_inttobyte(bindec($bWrite)); + }; + for($z=0;$z<$Zbytek;$z++) + $ret.=jpexs_inttobyte(0); + }; +}; + + + +if($BitCount>=24) +{ + for($y=$Height-1;$y>=0;$y--) + { + for($x=0;$x<$Width;$x++) + { + $color=imagecolorsforindex($img,imagecolorat($img,$x,$y)); + $ret.=jpexs_inttobyte($color["blue"]); + $ret.=jpexs_inttobyte($color["green"]); + $ret.=jpexs_inttobyte($color["red"]); + if($BitCount==32) + $ret.=jpexs_inttobyte(0);//Alpha for ICO_XP_COLORS + }; + for($z=0;$z<$Zbytek;$z++) + $ret.=jpexs_inttobyte(0); + }; +}; + + +//MASK + + for($y=$Height-1;$y>=0;$y--) + { + $byteCount=0; + $bOut=""; + for($x=0;$x<$Width;$x++) + { + if(($Transparent!=-1)and(imagecolorat($img,$x,$y)==$Transparent)) + { + $bOut.="1"; + } + else + { + $bOut.="0"; + }; + }; + for($p=0;$p$start+$len from $byte +* jpexs_freadbits($file,$count) - reads next $count bits from $file +*/ + + +function jpexs_decbin8($d) +{ +return jpexs_decbinx($d,8); +}; + +function jpexs_decbinx($d,$n) +{ +$bin=decbin($d); +$sbin=strlen($bin); +for($j=0;$j<$n-$sbin;$j++) + $bin="0$bin"; +return $bin; +}; + +function jpexs_retBits($byte,$start,$len) +{ +$bin=jpexs_decbin8($byte); +$r=bindec(substr($bin,$start,$len)); +return $r; + +}; + + + +$jpexs_currentBit=0; +function jpexs_freadbits($f,$count) +{ + global $jpexs_currentBit,$jpexs_SMode; + $Byte=jpexs_freadbyte($f); + $LastCBit=$jpexs_currentBit; + $jpexs_currentBit+=$count; + if($jpexs_currentBit==8) + { + $jpexs_currentBit=0; + } + else + { + fseek($f,ftell($f)-1); + }; + return jpexs_retBits($Byte,$LastCBit,$count); +}; + + +function jpexs_freadbyte($f) +{ + return ord(fread($f,1)); +}; + +function jpexs_freadword($f) +{ + $b1=jpexs_freadbyte($f); + $b2=jpexs_freadbyte($f); + return $b2*256+$b1; +}; + + +function jpexs_freadlngint($f) +{ +return jpexs_freaddword($f); +}; + +function jpexs_freaddword($f) +{ + $b1=jpexs_freadword($f); + $b2=jpexs_freadword($f); + return $b2*65536+$b1; +}; + +function jpexs_inttobyte($n) +{ +return chr($n); +}; + +function jpexs_inttodword($n) +{ +return chr($n & 255).chr(($n >> 8) & 255).chr(($n >> 16) & 255).chr(($n >> 24) & 255); +}; + +function jpexs_inttoword($n) + { + return chr($n & 255).chr(($n >> 8) & 255); + }; + +?> \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/vendor/JPEXS/index.html b/htdocs/libraries/WideImage/lib/vendor/JPEXS/index.html new file mode 100644 index 000000000000..74b6f45c8f33 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/vendor/JPEXS/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/vendor/de77/BMP.php b/htdocs/libraries/WideImage/lib/vendor/de77/BMP.php new file mode 100644 index 000000000000..c95532dc9a67 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/vendor/de77/BMP.php @@ -0,0 +1,264 @@ +=0; $y--) + { + for ($x=0; $x<$wid; $x++) + { + $rgb = imagecolorat($img, $x, $y); + fwrite($f, self::byte3($rgb)); + } + fwrite($f, $wid_pad); + } + fclose($f); + } + else + { + foreach ($header AS $h) + { + echo $h; + } + + //save pixels + for ($y=$hei-1; $y>=0; $y--) + { + for ($x=0; $x<$wid; $x++) + { + $rgb = imagecolorat($img, $x, $y); + echo self::byte3($rgb); + } + echo $wid_pad; + } + } + return true; + } + + public static function imagecreatefromstring($data) + { + //read header + $pos = 0; + $header = substr($data, 0, 54); + $pos = 54; + + if (strlen($header) < 54) + return false; + + $header = unpack( 'c2identifier/Vfile_size/Vreserved/Vbitmap_data/Vheader_size/' . + 'Vwidth/Vheight/vplanes/vbits_per_pixel/Vcompression/Vdata_size/'. + 'Vh_resolution/Vv_resolution/Vcolors/Vimportant_colors', $header); + + if ($header['identifier1'] != 66 or $header['identifier2'] != 77) + { + return false; + //die('Not a valid bmp file'); + } + + if (!in_array($header['bits_per_pixel'], array(24, 32, 8, 4, 1))) + { + return false; + //die('Only 1, 4, 8, 24 and 32 bit BMP images are supported'); + } + + $bps = $header['bits_per_pixel']; //bits per pixel + $wid2 = ceil(($bps/8 * $header['width']) / 4) * 4; + $colors = pow(2, $bps); + + $wid = $header['width']; + $hei = $header['height']; + + $img = imagecreatetruecolor($header['width'], $header['height']); + + //read palette + if ($bps < 9) + { + for ($i=0; $i<$colors; $i++) + { + $palette[] = self::undword(substr($data, $pos, 4)); + $pos += 4; + } + } + else + { + if ($bps == 32) + { + imagealphablending($img, false); + imagesavealpha($img, true); + } + $palette = array(); + } + + //read pixels + for ($y=$hei-1; $y>=0; $y--) + { + $row = substr($data, $pos, $wid2); + $pos += $wid2; + $pixels = self::str_split2($row, $bps, $palette); + for ($x=0; $x<$wid; $x++) + { + self::makepixel($img, $x, $y, $pixels[$x], $bps); + } + } + + return $img; + } + + public static function imagecreatefrombmp($filename) + { + return self::imagecreatefromstring(file_get_contents($filename)); + } + + private static function str_split2($row, $bps, $palette) + { + switch ($bps) + { + case 32: + case 24: return str_split($row, $bps/8); + case 8: $out = array(); + $count = strlen($row); + for ($i=0; $i<$count; $i++) + { + $out[] = $palette[ ord($row[$i]) ]; + } + return $out; + case 4: $out = array(); + $count = strlen($row); + for ($i=0; $i<$count; $i++) + { + $roww = ord($row[$i]); + $out[] = $palette[ ($roww & 240) >> 4 ]; + $out[] = $palette[ ($roww & 15) ]; + } + return $out; + case 1: $out = array(); + $count = strlen($row); + for ($i=0; $i<$count; $i++) + { + $roww = ord($row[$i]); + $out[] = $palette[ ($roww & 128) >> 7 ]; + $out[] = $palette[ ($roww & 64) >> 6 ]; + $out[] = $palette[ ($roww & 32) >> 5 ]; + $out[] = $palette[ ($roww & 16) >> 4 ]; + $out[] = $palette[ ($roww & 8) >> 3 ]; + $out[] = $palette[ ($roww & 4) >> 2 ]; + $out[] = $palette[ ($roww & 2) >> 1 ]; + $out[] = $palette[ ($roww & 1) ]; + } + return $out; + } + } + + private static function makepixel($img, $x, $y, $str, $bps) + { + switch ($bps) + { + case 32 : $a = ord($str[0]); + $b = ord($str[1]); + $c = ord($str[2]); + $d = 256 - ord($str[3]); //TODO: gives imperfect results + $pixel = $d*256*256*256 + $c*256*256 + $b*256 + $a; + imagesetpixel($img, $x, $y, $pixel); + break; + case 24 : $a = ord($str[0]); + $b = ord($str[1]); + $c = ord($str[2]); + $pixel = $c*256*256 + $b*256 + $a; + imagesetpixel($img, $x, $y, $pixel); + break; + case 8 : + case 4 : + case 1 : imagesetpixel($img, $x, $y, $str); + break; + } + } + + private static function byte3($n) + { + return chr($n & 255) . chr(($n >> 8) & 255) . chr(($n >> 16) & 255); + } + + private static function undword($n) + { + $r = unpack("V", $n); + return $r[1]; + } + + private static function dword($n) + { + return pack("V", $n); + } + + private static function word($n) + { + return pack("v", $n); + } +} diff --git a/htdocs/libraries/WideImage/lib/vendor/de77/TGA.php b/htdocs/libraries/WideImage/lib/vendor/de77/TGA.php new file mode 100644 index 000000000000..d71058f1aea9 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/vendor/de77/TGA.php @@ -0,0 +1,206 @@ += $datalen) + { + break; + } + + $i++; + + if ($type == 0) //raw + { + for ($j=0; $j<3*$value; $j++) + { + $out .= $data[$j+$i]; + $k++; + } + $i += $value*3; + } + else //rle + { + for ($j=0; $j<$value; $j++) + { + $out .= $data[$i] . $data[$i+1] . $data[$i+2]; + $k++; + } + $i += 3; + } + } + return $out; + } + + static function dec_bits($byte, &$type, &$value) + { + $type = ($byte & 0x80) >> 7; + $value = 1 + ($byte & 0x7F); + } + + static function imagecreatefromstring($bin_data) + { + $bin_pos = 0; + $header = substr($bin_data, $bin_pos, 18); + $bin_pos += 18; + $header = unpack( "cimage_id_len/ccolor_map_type/cimage_type/vcolor_map_origin/vcolor_map_len/" . + "ccolor_map_entry_size/vx_origin/vy_origin/vwidth/vheight/" . + "cpixel_size/cdescriptor", $header); + + switch ($header['image_type']) + { + case 2: //no palette, uncompressed + case 10: //no palette, rle + break; + default: return false; //die('Unsupported TGA format'); + } + + if ($header['pixel_size'] != 24) + { + return false; + //die('Unsupported TGA color depth'); + } + + $bytes = $header['pixel_size'] / 8; + + if ($header['image_id_len'] > 0) + { + $header['image_id'] = substr($bin_data, $bin_pos, $header['image_id_len']); + $bin_pos += $header['image_id_len']; + } + else + { + $header['image_id'] = ''; + } + + $im = imagecreatetruecolor($header['width'], $header['height']); + + $size = $header['width'] * $header['height'] * 3; + + //-- check whether this is NEW TGA or not + $pos = $bin_pos; + $bin_pos = strlen($bin_data) - 26; + $newtga = substr($bin_data, $bin_pos, 26); + if (substr($newtga, 8, 16) != 'TRUEVISION-XFILE') + { + $newtga = false; + } + + $bin_pos = strlen($bin_data); + $datasize = $bin_pos - $pos; + if ($newtga) + { + $datasize -= 26; + } + + $bin_pos = $pos; + + //-- end of check + $data = substr($bin_data, $bin_pos, $datasize); + $bin_pos += $datasize; + if ($header['image_type'] == 10) + { + $data = self::rle_decode($data, $size); + } + if (self::bit5($header['descriptor']) == 1) + { + $reverse = true; + } + else + { + $reverse = false; + } + + $pixels = str_split($data, 3); + $i = 0; + + //read pixels + if ($reverse) + { + for ($y=0; $y<$header['height']; $y++) + { + for ($x=0; $x<$header['width']; $x++) + { + imagesetpixel($im, $x, $y, self::dwordize($pixels[$i])); + $i++; + } + } + } + else + { + for ($y=$header['height']-1; $y>=0; $y--) + { + for ($x=0; $x<$header['width']; $x++) + { + imagesetpixel($im, $x, $y, self::dwordize($pixels[$i])); + $i++; + } + } + } + + return $im; + } + + static function imagecreatefromtga($filename) + { + return self::imagecreatefromstring(file_get_contents($filename)); + } + + static function dwordize($str) + { + $a = ord($str[0]); + $b = ord($str[1]); + $c = ord($str[2]); + return $c*256*256 + $b*256 + $a; + } + + static function bit5($x) + { + return ($x & 32) >> 5; + } +} \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/vendor/de77/index.html b/htdocs/libraries/WideImage/lib/vendor/de77/index.html new file mode 100644 index 000000000000..74b6f45c8f33 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/vendor/de77/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/libraries/WideImage/lib/vendor/index.html b/htdocs/libraries/WideImage/lib/vendor/index.html new file mode 100644 index 000000000000..74b6f45c8f33 --- /dev/null +++ b/htdocs/libraries/WideImage/lib/vendor/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/libraries/WideImage/pax_global_header b/htdocs/libraries/WideImage/pax_global_header new file mode 100644 index 000000000000..6ee1a632043e --- /dev/null +++ b/htdocs/libraries/WideImage/pax_global_header @@ -0,0 +1 @@ +52 comment=755d1b2b474ce9c32092aa6ac0357ebf857545f5 diff --git a/htdocs/libraries/WideImage/vendor/de77/BMP.php b/htdocs/libraries/WideImage/vendor/de77/BMP.php new file mode 100755 index 000000000000..8376d39d5ee5 --- /dev/null +++ b/htdocs/libraries/WideImage/vendor/de77/BMP.php @@ -0,0 +1,270 @@ += 0; $y--) { + for ($x = 0; $x < $wid; $x++) { + $rgb = imagecolorat($img, $x, $y); + fwrite($f, self::byte3($rgb)); + } + + fwrite($f, $wid_pad); + } + + fclose($f); + } else { + foreach ($header as $h) { + echo $h; + } + + //save pixels + for ($y = $hei-1; $y >= 0; $y--) { + for ($x = 0; $x < $wid; $x++) { + $rgb = imagecolorat($img, $x, $y); + echo self::byte3($rgb); + } + + echo $wid_pad; + } + } + + return true; + } + + public static function imagecreatefromstring($data) + { + //read header + $pos = 0; + $header = substr($data, 0, 54); + $pos = 54; + + if (strlen($header) < 54) { + return false; + } + + $header = unpack( 'c2identifier/Vfile_size/Vreserved/Vbitmap_data/Vheader_size/' . + 'Vwidth/Vheight/vplanes/vbits_per_pixel/Vcompression/Vdata_size/'. + 'Vh_resolution/Vv_resolution/Vcolors/Vimportant_colors', $header); + + if ($header['identifier1'] != 66 or $header['identifier2'] != 77) { + return false; + } + + if (!in_array($header['bits_per_pixel'], array(24, 32, 8, 4, 1))) { + return false; + } + + $bps = $header['bits_per_pixel']; //bits per pixel + $wid2 = ceil(($bps/8 * $header['width']) / 4) * 4; + $colors = $header['colors']; + // The absolute height value is necessary because ImageHeight can be negative + // If Height is a positive number, then the image is a "bottom-up" bitmap with the origin in the lower-left corner. + // If Height is a negative number, then the image is a "top-down" bitmap with the origin in the upper-left corner. + $header['height'] = abs($header['height']); + + $wid = $header['width']; + $hei = $header['height']; + + $img = imagecreatetruecolor($header['width'], $header['height']); + if (!$img) { + return false; // Invalid width or height + } + //read palette + $palette = []; + + if ($bps < 9) { + // A color table is mandatory for color depths <= 8 + if (isset($header['colors']) && $header['colors'] > 0) { + // The number of entries in the palette is either 2n + // or a smaller number specified in the header + $colors = min($header['colors'], $colors); + } + for ($i = 0; $i < $colors; $i++) { + $palette[] = self::undword(substr($data, $pos, 4)); + $pos += 4; + } + } else { + if ($bps == 32) { + imagealphablending($img, false); + imagesavealpha($img, true); + } + + $palette = array(); + } + + //read pixels + for ($y = $hei-1; $y >= 0; $y--) { + $row = substr($data, $pos, $wid2); + $pos += $wid2; + $pixels = self::str_split2($row, $bps, $palette); + + for ($x = 0; $x < $wid; $x++) { + self::makepixel($img, $x, $y, $pixels[$x], $bps); + } + } + + return $img; + } + + public static function imagecreatefrombmp($filename) + { + return self::imagecreatefromstring(file_get_contents($filename)); + } + + private static function str_split2($row, $bps, $palette) + { + switch ($bps) { + case 32: + case 24: return str_split($row, $bps / 8); + case 8: $out = array(); + $count = strlen($row); + + for ($i = 0; $i < $count; $i++) { + $out[] = $palette[ ord($row[$i]) ]; + } + + return $out; + case 4: $out = array(); + $count = strlen($row); + + for ($i = 0; $i < $count; $i++) { + $roww = ord($row[$i]); + $out[] = $palette[ ($roww & 240) >> 4 ]; + $out[] = $palette[ ($roww & 15) ]; + } + + return $out; + case 1: $out = array(); + $count = strlen($row); + + for ($i = 0; $i < $count; $i++) { + $roww = ord($row[$i]); + $out[] = $palette[ ($roww & 128) >> 7 ]; + $out[] = $palette[ ($roww & 64) >> 6 ]; + $out[] = $palette[ ($roww & 32) >> 5 ]; + $out[] = $palette[ ($roww & 16) >> 4 ]; + $out[] = $palette[ ($roww & 8) >> 3 ]; + $out[] = $palette[ ($roww & 4) >> 2 ]; + $out[] = $palette[ ($roww & 2) >> 1 ]; + $out[] = $palette[ ($roww & 1) ]; + } + + return $out; + } + } + + private static function makepixel($img, $x, $y, $str, $bps) + { + switch ($bps) { + case 32 : $a = ord($str[0]); + $b = ord($str[1]); + $c = ord($str[2]); + $d = 256 - ord($str[3]); //TODO: gives imperfect results + $pixel = $d*256*256*256 + $c*256*256 + $b*256 + $a; + imagesetpixel($img, $x, $y, $pixel); + break; + case 24 : $a = ord($str[0]); + $b = ord($str[1]); + $c = ord($str[2]); + $pixel = $c*256*256 + $b*256 + $a; + imagesetpixel($img, $x, $y, $pixel); + break; + case 8 : + case 4 : + case 1 : imagesetpixel($img, $x, $y, $str); + break; + } + } + + private static function byte3($n) + { + return chr($n & 255) . chr(($n >> 8) & 255) . chr(($n >> 16) & 255); + } + + private static function undword($n) + { + $r = unpack("V", $n); + return $r[1]; + } + + private static function dword($n) + { + return pack("V", $n); + } + + private static function word($n) + { + return pack("v", $n); + } +} diff --git a/htdocs/libraries/WideImage/vendor/de77/TGA.php b/htdocs/libraries/WideImage/vendor/de77/TGA.php new file mode 100644 index 000000000000..fd64a70da822 --- /dev/null +++ b/htdocs/libraries/WideImage/vendor/de77/TGA.php @@ -0,0 +1,193 @@ += $datalen) { + break; + } + + $i++; + + if ($type == 0) { //raw + for ($j = 0; $j < (3 * $value); $j++) { + $out .= $data[$j+$i]; + $k++; + } + + $i += $value * 3; + } else { //rle + for ($j = 0; $j < $value; $j++) { + $out .= $data[$i] . $data[$i+1] . $data[$i+2]; + $k++; + } + + $i += 3; + } + } + + return $out; + } + + public static function dec_bits($byte, &$type, &$value) + { + $type = ($byte & 0x80) >> 7; + $value = 1 + ($byte & 0x7F); + } + + public static function imagecreatefromstring($bin_data) + { + if (!trim($bin_data)) { + return false; + } + + $bin_pos = 0; + $header = substr($bin_data, $bin_pos, 18); + $bin_pos += 18; + $header = unpack( "cimage_id_len/ccolor_map_type/cimage_type/vcolor_map_origin/vcolor_map_len/" . + "ccolor_map_entry_size/vx_origin/vy_origin/vwidth/vheight/" . + "cpixel_size/cdescriptor", $header); + + switch ($header['image_type']) { + case 2: //no palette, uncompressed + case 10: //no palette, rle + break; + default: return false; + } + + if ($header['pixel_size'] != 24) { + return false; + //die('Unsupported TGA color depth'); + } + + $bytes = $header['pixel_size'] / 8; + + if ($header['image_id_len'] > 0) { + $header['image_id'] = substr($bin_data, $bin_pos, $header['image_id_len']); + $bin_pos += $header['image_id_len']; + } else { + $header['image_id'] = ''; + } + + $im = imagecreatetruecolor($header['width'], $header['height']); + + $size = $header['width'] * $header['height'] * 3; + + //-- check whether this is NEW TGA or not + $pos = $bin_pos; + $bin_pos = strlen($bin_data) - 26; + $newtga = substr($bin_data, $bin_pos, 26); + + if (substr($newtga, 8, 16) != 'TRUEVISION-XFILE') { + $newtga = false; + } + + $bin_pos = strlen($bin_data); + $datasize = $bin_pos - $pos; + + if ($newtga) { + $datasize -= 26; + } + + $bin_pos = $pos; + + //-- end of check + $data = substr($bin_data, $bin_pos, $datasize); + $bin_pos += $datasize; + + if ($header['image_type'] == 10) { + $data = self::rle_decode($data, $size); + } + + $reverse = self::bit5($header['descriptor']) == 1; + $pixels = str_split($data, 3); + + $i = 0; + + //read pixels + if ($reverse) { + for ($y = 0; $y < $header['height']; $y++) { + for ($x = 0; $x < $header['width']; $x++) { + imagesetpixel($im, $x, $y, self::dwordize($pixels[$i])); + $i++; + } + } + } else { + for ($y = $header['height']-1; $y >= 0; $y--) { + for ($x=0; $x<$header['width']; $x++) { + imagesetpixel($im, $x, $y, self::dwordize($pixels[$i])); + $i++; + } + } + } + + return $im; + } + + public static function imagecreatefromtga($filename) + { + return self::imagecreatefromstring(file_get_contents($filename)); + } + + public static function dwordize($str) + { + $a = ord($str[0]); + $b = ord($str[1]); + $c = ord($str[2]); + + return $c*256*256 + $b*256 + $a; + } + + public static function bit5($x) + { + return ($x & 32) >> 5; + } +} diff --git a/htdocs/libraries/smarty/icms_plugins/function.resized_image.php b/htdocs/libraries/smarty/icms_plugins/function.resized_image.php index 047d1acbd149..26b1ae886bf2 100644 --- a/htdocs/libraries/smarty/icms_plugins/function.resized_image.php +++ b/htdocs/libraries/smarty/icms_plugins/function.resized_image.php @@ -1,196 +1,191 @@ - * Based on work by Monte Ohrt and Duda - * @version 1.11 + * Based on work by Monte Ohrt and Duda + * @version 1.11 * @param array * @param Smarty * @return string * @uses smarty_function_escape_special_chars() * @uses WideImage library */ -function smarty_function_resized_image($params, &$smarty) -{ - require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); - +function smarty_function_resized_image($params, &$smarty) { + require_once $smarty->_get_plugin_filepath('shared', 'escape_special_chars'); + // Preparing arrays that will store original and resized image data - $original = array (); - $resized = array (); - + $original = array(); + $resized = array(); + // Get parameters from the tag - $alt = ''; - $file = ''; - $height = ''; - $width = ''; - $extra = ''; - $prefix = ''; - $suffix = ''; - $fit = 'inside'; - $return = 'img'; - $path_prefix = ''; - $server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; // Really? HTTP_SERVER_VARS ?? WTF come on, it's been deprecated years!!!!! - $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : ''; - $subpath = str_replace($basedir, '', ICMS_ROOT_PATH); - foreach($params as $_key => $_val) { - switch($_key) { - case 'file': - case 'height': - case 'width': - case 'fit': - case 'return': - case 'path_prefix': - case 'basedir': - $$_key = $_val; - break; + $alt = ''; + $file = ''; + $height = ''; + $width = ''; + $extra = ''; + $prefix = ''; + $suffix = ''; + $fit = 'inside'; + $return = 'img'; + $path_prefix = ''; + $server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; // Really? HTTP_SERVER_VARS ?? WTF come on, it's been deprecated years!!!!! + $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : ''; + $subpath = str_replace($basedir, '', ICMS_ROOT_PATH); + foreach ($params as $_key => $_val) { + switch ($_key) { + case 'file': + case 'height': + case 'width': + case 'fit': + case 'return': + case 'path_prefix': + case 'basedir': + $$_key = $_val; + break; - case 'alt': - if(!is_array($_val)) { - $$_key = smarty_function_escape_special_chars($_val); - } else { - $smarty->trigger_error("resized_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); - } - break; + case 'alt': + if (!is_array($_val)) { + $$_key = smarty_function_escape_special_chars($_val); + } else { + $smarty->trigger_error("resized_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + } + break; - case 'link': - case 'href': - $prefix = ''; - $suffix = ''; - break; + case 'link': + case 'href': + $prefix = ''; + $suffix = ''; + break; - default: - if(!is_array($_val)) { - $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; - } else { - $smarty->trigger_error("resized_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); - } - break; - } - } + default: + if (!is_array($_val)) { + $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; + } else { + $smarty->trigger_error("resized_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + } + break; + } + } // Checking the existence of required parameters - if (empty($file)) { - $smarty->trigger_error("resized_image: missing 'file' parameter", E_USER_ERROR); - return; - } + if (empty($file)) { + $smarty->trigger_error("resized_image: missing 'file' parameter", E_USER_ERROR); + return; + } if (!isset($params['width']) && !isset($params['height'])) { $smarty->trigger_error("resized_image: New size was not specified", E_USER_ERROR); return; } // If image resized is 'fit', both height and width are required - if ($fit == 'fill' && (empty($width) || empty($height) ) ) { + if ($fit == 'fill' && (empty($width) || empty($height))) { $smarty->trigger_error("resized_image: When you choose 'fill' fit, you have to specify both width and height", E_USER_ERROR); } // Transliteration - prepare a clean name for file $clean_file = str_replace(' ', '_', $file); // remove spaces $from = explode(' ', 'Á á É é è ê È Ê Í í Ó ó Ú ú Ñ ñ Ç ç'); - $to = explode(' ', 'A a E e e e E E I i O o U u N n C c'); + $to = explode(' ', 'A a E e e e E E I i O o U u N n C c'); $clean_file = str_replace($from, $to, strtolower($clean_file)); // removing special characters, convert to lowercase, encoding in URL the remaining for safe $clean_file = str_replace('%2F', '/', urlencode($clean_file)); // URLencode the remaining, but taking into consideration the / char. - $clean_file = str_replace($subpath, '', $clean_file); // strip off remnants of the document root (including subdir) + $clean_file = str_replace($subpath, '', $clean_file); // strip off remnants of the document root (including subdir) - // Preparing paths - if (substr($file,0,1) == '/') { + // Preparing paths + if (substr($file, 0, 1) == '/') { $original['path'] = $basedir . $file; - $clean_file = str_replace($basedir, '', urldecode($clean_file)); // Clean file should not have Full Path - $resized['path'] = ICMS_ROOT_PATH.'/cache'.$clean_file; - $resized['url'] = ICMS_URL.'/cache'.$clean_file; - } elseif (strpos($file, ICMS_URL) === 0) { // In case of full URL - $original['path'] = ICMS_ROOT_PATH. str_replace(ICMS_URL, '', $file); + $clean_file = str_replace($basedir, '', urldecode($clean_file)); // Clean file should not have Full Path + $resized['path'] = ICMS_ROOT_PATH . '/cache' . $clean_file; + $resized['url'] = ICMS_URL . '/cache' . $clean_file; + } elseif (strpos($file, ICMS_URL) === 0) { // In case of full URL + $original['path'] = ICMS_ROOT_PATH . str_replace(ICMS_URL, '', $file); $clean_file = str_replace(ICMS_URL, '', urldecode($clean_file)); // Clean file should not have Full URL - $resized['path'] = ICMS_ROOT_PATH.'/cache'.$clean_file; - $resized['url'] = ICMS_URL.'/cache'.$clean_file; + $resized['path'] = ICMS_ROOT_PATH . '/cache' . $clean_file; + $resized['url'] = ICMS_URL . '/cache' . $clean_file; } else { $original['path'] = $file; - $clean_file = str_replace(ICMS_ROOT_PATH, '', urldecode($clean_file)); - $resized['path'] = ICMS_ROOT_PATH.'/cache/'.$clean_file; - $resized['url'] = ICMS_URL.'/cache/'.$clean_file; + $clean_file = str_replace(ICMS_ROOT_PATH, '', urldecode($clean_file)); + $resized['path'] = ICMS_ROOT_PATH . '/cache/' . $clean_file; + $resized['url'] = ICMS_URL . '/cache/' . $clean_file; } - // Check if original image exists - if(!$_image_data = @getimagesize($original['path'])) { - if(!file_exists($original['path'])) { - $smarty->trigger_error("resized_image: unable to find '".$original['path']."'", E_USER_NOTICE); + // Check if original image exists + if (!$_image_data = @getimagesize($original['path'])) { + if (!file_exists($original['path'])) { + $smarty->trigger_error("resized_image: unable to find '" . $original['path'] . "'", E_USER_NOTICE); return; - } else if(!is_readable($original['path'])) { - $smarty->trigger_error("resized_image: unable to read '".$original['path']."'", E_USER_NOTICE); + } else if (!is_readable($original['path'])) { + $smarty->trigger_error("resized_image: unable to read '" . $original['path'] . "'", E_USER_NOTICE); return; } else { - $smarty->trigger_error("resized_image: '".$original['path']."' is not a valid image file", E_USER_NOTICE); + $smarty->trigger_error("resized_image: '" . $original['path'] . "' is not a valid image file", E_USER_NOTICE); return; } } // Smarty Security check (comes from Smarty html_image tag, being honest, I don't understand what it does). - if ($smarty->security && - ($_params = array('resource_type' => 'file', 'resource_name' => $original['path'])) && - (require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) && - (!smarty_core_is_secure($_params, $smarty)) ) { - $smarty->trigger_error("resized_image: (secure) '".$original['path']."' not in secure directory", E_USER_NOTICE); + if ($smarty->security && ($_params = array( + 'resource_type' => 'file', 'resource_name' => $original['path'])) && (require_once (SMARTY_CORE_DIR . 'core.is_secure.php')) && (!smarty_core_is_secure($_params, $smarty))) { + $smarty->trigger_error("resized_image: (secure) '" . $original['path'] . "' not in secure directory", E_USER_NOTICE); } - + // Original and resized dimensions - if(!isset($params['width'])) { + if (!isset($params['width'])) { $original['width'] = $_image_data[0]; } - if(!isset($params['height'])) { + if (!isset($params['height'])) { $original['height'] = $_image_data[1]; } - + $resized['width'] = $width; $resized['height'] = $height; // build resized file name $resized['dir'] = substr($resized['path'], 0, strrpos($resized['path'], "/")); // extract path - $resized['path'] = substr($resized['path'], 0, strrpos($resized['path'], ".") ) - . "-" . $resized['width']. "x" . $resized['height'] - . substr($resized['path'], strrpos($resized['path'], ".") ); // build path + file name - $resized['url'] = substr($resized['url'], 0, strrpos($resized['url'], ".") ) - . "-" . $resized['width']. "x" . $resized['height'] - . substr($resized['url'], strrpos($resized['url'], ".") ); // build file URL - + $resized['path'] = substr($resized['path'], 0, strrpos($resized['path'], ".")) . "-" . $resized['width'] . "x" . $resized['height'] . substr($resized['path'], strrpos($resized['path'], ".")); // build path + file name + $resized['url'] = substr($resized['url'], 0, strrpos($resized['url'], ".")) . "-" . $resized['width'] . "x" . $resized['height'] . substr($resized['url'], strrpos($resized['url'], ".")); // build file URL + // If file does not exist // or it's outdated, create: - if (!file_exists($resized['path']) or ( filemtime ($original['path']) > filemtime ($resized['path']) ) ) { + if (!file_exists($resized['path']) or (filemtime($original['path']) > filemtime($resized['path']))) { if (!is_dir($resized['dir'])) { // If dir does not exist, create - mkdir ($resized['dir'], 0755, true); + mkdir($resized['dir'], 0755, true); } // Resize image using WideImage library - include_once ICMS_LIBRARIES_PATH.'/wideimage/lib/WideImage.php'; $resized_img = WideImage::load($original['path'], 'jpg'); - + $resized_img->resize($resized['width'], $resized['height'], $fit)->saveToFile($resized['path']); } if ($return == 'url') { - return $resized['url']; + return $resized['url']; } else { - return $prefix . ''.$alt.'' . $suffix; + return $prefix . '' . $alt . '' . $suffix; } } From 43c1368a589085a5f4031f998b32087433d679c0 Mon Sep 17 00:00:00 2001 From: Steve Kenow Date: Wed, 14 Jun 2023 22:28:19 -0500 Subject: [PATCH 5/9] The wideimage preload can be removed - the class autoloads --- htdocs/plugins/preloads/wideimage.php | 38 --------------------------- 1 file changed, 38 deletions(-) delete mode 100644 htdocs/plugins/preloads/wideimage.php diff --git a/htdocs/plugins/preloads/wideimage.php b/htdocs/plugins/preloads/wideimage.php deleted file mode 100644 index 7168a736ec12..000000000000 --- a/htdocs/plugins/preloads/wideimage.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @version $Id: wideimage.php 10326 2010-07-11 18:54:25Z malanciault $ - */ -/** - * - * Event triggers for WideImage library - * @since 1.2 - * - */ -class IcmsPreloadWideimage extends icms_preload_Item { - /** - * Function to be triggered at the end of the output init process - * - * @return void - */ - function eventStartOutputInit() { - // just including the file... more to come - include_once ICMS_LIBRARIES_PATH . '/wideimage/lib/WideImage.php' ; - } - - /** - * - * Events to be triggered at the start of the admin pages loading - */ - function eventAdminHeader() { - include_once ICMS_LIBRARIES_PATH . '/wideimage/lib/WideImage.php' ; - } -} From 2b2aef5cf96a5bcad0f736a5b0a95cf435f00472 Mon Sep 17 00:00:00 2001 From: Steve Kenow Date: Sat, 19 Aug 2023 17:09:03 -0500 Subject: [PATCH 6/9] Fix fatal error in icms_random_str Fix #1488 --- htdocs/include/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/include/functions.php b/htdocs/include/functions.php index 3d59ba4b1294..96b10d517cef 100644 --- a/htdocs/include/functions.php +++ b/htdocs/include/functions.php @@ -1785,7 +1785,7 @@ function icms_random_str($numchar){ $letras = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,x,w,y,z,1,2,3,4,5,6,7,8,9,0"; $array = explode(",", $letras); shuffle($array); - $senha = implode($array, ""); + $senha = implode($array); return substr($senha, 0, $numchar); } From f87bec5a6b1b6f462b28f6f6c22039d14496485b Mon Sep 17 00:00:00 2001 From: Steve Kenow Date: Sat, 19 Aug 2023 17:13:19 -0500 Subject: [PATCH 7/9] Add missing argument for strncmp - root cause of the image editor issue strncmp requires 3 arguments and there were only 2 --- htdocs/libraries/image-editor/plugins/crop/crop_image.php | 2 +- htdocs/libraries/image-editor/plugins/filter/filter_image.php | 2 +- htdocs/libraries/image-editor/plugins/resize/resize_image.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/libraries/image-editor/plugins/crop/crop_image.php b/htdocs/libraries/image-editor/plugins/crop/crop_image.php index b02d60b0a4ec..2af458d1d89c 100644 --- a/htdocs/libraries/image-editor/plugins/crop/crop_image.php +++ b/htdocs/libraries/image-editor/plugins/crop/crop_image.php @@ -19,7 +19,7 @@ /* prevent remote file inclusion */ $valid_path = ICMS_IMANAGER_FOLDER_PATH . '/temp'; -if (!empty($image_path) && strncmp(realpath($image_path), strlen($valid_path)) == 0) { +if (!empty($image_path) && strncmp(realpath($image_path), $image_path, strlen($valid_path)) == 0) { $image_path = realpath($image_path); } else { $image_path = null; diff --git a/htdocs/libraries/image-editor/plugins/filter/filter_image.php b/htdocs/libraries/image-editor/plugins/filter/filter_image.php index beb297c945f6..0755d4620c10 100644 --- a/htdocs/libraries/image-editor/plugins/filter/filter_image.php +++ b/htdocs/libraries/image-editor/plugins/filter/filter_image.php @@ -20,7 +20,7 @@ /* prevent remote file inclusion */ $valid_path = ICMS_IMANAGER_FOLDER_PATH . '/temp'; -if (!empty($image_path) && strncmp(realpath($image_path), strlen($valid_path)) == 0) { +if (!empty($image_path) && strncmp(realpath($image_path), $image_path, strlen($valid_path)) == 0) { $image_path = realpath($image_path); } else { $image_path = null; diff --git a/htdocs/libraries/image-editor/plugins/resize/resize_image.php b/htdocs/libraries/image-editor/plugins/resize/resize_image.php index 16071b934409..4e621615b5dc 100644 --- a/htdocs/libraries/image-editor/plugins/resize/resize_image.php +++ b/htdocs/libraries/image-editor/plugins/resize/resize_image.php @@ -20,7 +20,7 @@ /* prevent remote file inclusion */ $valid_path = ICMS_IMANAGER_FOLDER_PATH . '/temp'; -if (!empty($image_path) && strncmp(realpath($image_path), strlen($valid_path)) == 0) { +if (!empty($image_path) && strncmp(realpath($image_path), $image_path, strlen($valid_path)) == 0) { $image_path = realpath($image_path); } else { $image_path = null; From 280a701c908768f5465dc1e5c5d9aa5de7082f5d Mon Sep 17 00:00:00 2001 From: Steve Kenow Date: Sat, 19 Aug 2023 17:18:25 -0500 Subject: [PATCH 8/9] Adding missing line ending (;) - caused errors in parsing image editor --- .../image-editor/plugins/crop/image-crop.js | 1438 ++++++++--------- .../plugins/filter/filter_image.js | 332 ++-- .../plugins/resize/resize_image.js | 220 +-- 3 files changed, 995 insertions(+), 995 deletions(-) diff --git a/htdocs/libraries/image-editor/plugins/crop/image-crop.js b/htdocs/libraries/image-editor/plugins/crop/image-crop.js index 2d9d1c350bcd..7e414bdfac54 100644 --- a/htdocs/libraries/image-editor/plugins/crop/image-crop.js +++ b/htdocs/libraries/image-editor/plugins/crop/image-crop.js @@ -1,720 +1,720 @@ -/************************************************************************************************************ -(C) www.dhtmlgoodies.com, April 2006 - -Update log: -August, 9th, 2006: Added a fix to the preserve aspect ratio feature ( Thanks to Urko Benito) -August, 11th, 2006: If fixed ratio is set, resize crop area initially - -This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. - -Terms of use: -You are free to use this script as long as the copyright message is kept intact. However, you may not -redistribute, sell or repost it without our permission. - -Thank you! - -www.dhtmlgoodies.com -Alf Magne Kalleland - -************************************************************************************************************/ - - - -var crop_script_alwaysPreserveAspectRatio = false; -var crop_script_fixedRatio = false; // Fixed aspect ratio(example of value: 1.5). Width of cropping area relative to height(1.5 means that the width is 150% of the height) -// Set this variable to false if you don't want a fixed aspect ratio - -var crop_script_browserIsOpera = navigator.userAgent.indexOf('Opera')>=0?true:false; -var cropDiv_left = false; -var cropDiv_top = false; -var cropDiv_right = false; -var cropDiv_bottom = false; -var cropDiv_dotted = false; - -var crop_currentResizeType = false; - -var cropEvent_posX; -var cropEvent_posY; - -var cropEvent_eventX; -var cropEvent_eventY; -var crop_resizeCounter = -1; -var crop_moveCounter = -1; - -var crop_imageDiv = false; -var imageDiv_currentWidth = false; -var imageDiv_currentHeight = false; -var imageDiv_currentLeft = false; -var imageDiv_currentTop = false; - -var smallSquare_tl; -var smallSquare_tc; -var smallSquare_tr; -var smallSquare_lc; -var smallSquare_rc; -var smallSquare_bl; -var smallSquare_bc; -var smallSquare_br; - -var offsetSmallSquares = Math.floor(smallSquareWidth/2); - -var cropScriptAjaxObjects = new Array(); -var preserveAspectRatio = false; - -var cropWidthRatio = false; // width of cropping area relative to height -function crop_createDivElements() -{ - - - - crop_imageDiv= document.getElementById('imageContainer'); - - cropDiv_left = document.createElement('DIV'); - cropDiv_left.className = 'crop_transparentDiv'; - cropDiv_left.style.visibility = 'visible'; - cropDiv_left.style.left = '0px'; - cropDiv_left.style.top = '0px'; - cropDiv_left.style.height = crop_imageHeight + 'px'; - cropDiv_left.style.width = '0px'; - cropDiv_left.innerHTML = ''; - cropDiv_left.id = 'cropDiv_left'; - crop_imageDiv.appendChild(cropDiv_left); - - cropDiv_top = document.createElement('DIV'); - cropDiv_top.className = 'crop_transparentDiv'; - cropDiv_top.style.visibility = 'visible'; - cropDiv_top.style.left = '0px'; - cropDiv_top.style.top = '0px'; - cropDiv_top.style.height = '0px'; - cropDiv_top.style.width = crop_imageWidth + 'px'; - cropDiv_top.innerHTML = ''; - cropDiv_top.id = 'cropDiv_top'; - crop_imageDiv.appendChild(cropDiv_top); - - cropDiv_right = document.createElement('DIV'); - cropDiv_right.className = 'crop_transparentDiv'; - cropDiv_right.style.visibility = 'visible'; - cropDiv_right.style.left = (crop_imageWidth) + 'px'; - cropDiv_right.style.top = '0px'; - cropDiv_right.style.height = crop_imageHeight + 'px'; - cropDiv_right.style.width = '0px'; - cropDiv_right.innerHTML = ''; - cropDiv_right.id = 'cropDiv_right'; - crop_imageDiv.appendChild(cropDiv_right); - - cropDiv_bottom = document.createElement('DIV'); - cropDiv_bottom.className = 'crop_transparentDiv'; - cropDiv_bottom.style.visibility = 'visible'; - cropDiv_bottom.style.left = '0px'; - cropDiv_bottom.style.top = (crop_imageHeight) + 'px'; - cropDiv_bottom.style.height = '0px'; - cropDiv_bottom.style.width = crop_imageWidth + 'px'; - cropDiv_bottom.innerHTML = ''; - cropDiv_bottom.id = 'cropDiv_bottom'; - crop_imageDiv.appendChild(cropDiv_bottom); - - cropDiv_dotted = document.createElement('DIV'); - cropDiv_dotted.className='crop_dottedDiv'; - cropDiv_dotted.style.left = '0px'; - cropDiv_dotted.style.top = '0px'; - cropDiv_dotted.style.width = (crop_imageWidth-(cropToolBorderWidth*2)) + 'px'; - cropDiv_dotted.style.height = (crop_imageHeight-(cropToolBorderWidth*2)) + 'px'; - cropDiv_dotted.innerHTML = '
'; - cropDiv_dotted.style.cursor = 'move'; - cropDiv_dotted.id = 'cropDiv_dotted'; - - if(crop_script_browserIsOpera){ - var div = cropDiv_dotted.getElementsByTagName('DIV')[0]; - div.style.backgroundColor='transparent'; - cropDiv_bottom.style.backgroundColor='transparent'; - cropDiv_right.style.backgroundColor='transparent'; - cropDiv_top.style.backgroundColor='transparent'; - cropDiv_left.style.backgroundColor='transparent'; - - } - - cropDiv_dotted.onmousedown = cropScript_initMove; - - smallSquare_tl = document.createElement('IMG'); - smallSquare_tl.src = 'images/small_square.gif'; - smallSquare_tl.style.position = 'absolute'; - smallSquare_tl.style.left = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_tl.style.top = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_tl.style.cursor = 'nw-resize'; - smallSquare_tl.id = 'nw-resize'; - smallSquare_tl.onmousedown = cropScript_initResize; - cropDiv_dotted.appendChild(smallSquare_tl); - - smallSquare_tr = document.createElement('IMG'); - smallSquare_tr.src = 'images/small_square.gif'; - smallSquare_tr.style.position = 'absolute'; - smallSquare_tr.style.left = (crop_imageWidth - offsetSmallSquares - (cropToolBorderWidth*2)) + 'px'; - smallSquare_tr.style.top = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_tr.style.cursor = 'ne-resize'; - smallSquare_tr.id = 'ne-resize'; - smallSquare_tr.onmousedown = cropScript_initResize; - cropDiv_dotted.appendChild(smallSquare_tr); - - smallSquare_bl = document.createElement('IMG'); - smallSquare_bl.src = 'images/small_square.gif'; - smallSquare_bl.style.position = 'absolute'; - smallSquare_bl.style.left = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_bl.style.top = (crop_imageHeight - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_bl.style.cursor = 'sw-resize'; - smallSquare_bl.id = 'sw-resize'; - smallSquare_bl.onmousedown = cropScript_initResize; - cropDiv_dotted.appendChild(smallSquare_bl); - - smallSquare_br = document.createElement('IMG'); - smallSquare_br.src = 'images/small_square.gif'; - smallSquare_br.style.position = 'absolute'; - smallSquare_br.style.left = (crop_imageWidth - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_br.style.top = (crop_imageHeight - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_br.style.cursor = 'se-resize'; - smallSquare_br.id = 'se-resize'; - smallSquare_br.onmousedown = cropScript_initResize; - cropDiv_dotted.appendChild(smallSquare_br); - - smallSquare_tc = document.createElement('IMG'); - smallSquare_tc.src = 'images/small_square.gif'; - smallSquare_tc.style.position = 'absolute'; - smallSquare_tc.style.left = (Math.floor(crop_imageWidth/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_tc.style.top = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_tc.style.cursor = 's-resize'; - smallSquare_tc.id = 'n-resize'; - smallSquare_tc.onmousedown = cropScript_initResize; - cropDiv_dotted.appendChild(smallSquare_tc); - - smallSquare_bc = document.createElement('IMG'); - smallSquare_bc.src = 'images/small_square.gif'; - smallSquare_bc.style.position = 'absolute'; - smallSquare_bc.style.left = (Math.floor(crop_imageWidth/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_bc.style.top = (crop_imageHeight - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_bc.style.cursor = 's-resize'; - smallSquare_bc.id = 's-resize'; - smallSquare_bc.onmousedown = cropScript_initResize; - cropDiv_dotted.appendChild(smallSquare_bc); - - smallSquare_lc = document.createElement('IMG'); - smallSquare_lc.src = 'images/small_square.gif'; - smallSquare_lc.style.position = 'absolute'; - smallSquare_lc.style.left = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_lc.style.top = (Math.floor(crop_imageHeight/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_lc.style.cursor = 'e-resize'; - smallSquare_lc.id = 'w-resize'; - smallSquare_lc.onmousedown = cropScript_initResize; - cropDiv_dotted.appendChild(smallSquare_lc); - - smallSquare_rc = document.createElement('IMG'); - smallSquare_rc.src = 'images/small_square.gif'; - smallSquare_rc.style.position = 'absolute'; - smallSquare_rc.style.left = (crop_imageWidth - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_rc.style.top = (Math.floor(crop_imageHeight/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_rc.style.cursor = 'e-resize'; - smallSquare_rc.id = 'e-resize'; - smallSquare_rc.onmousedown = cropScript_initResize; - cropDiv_dotted.appendChild(smallSquare_rc); - - crop_imageDiv.appendChild(cropDiv_dotted); -} - -function cropScript_initMove(e) -{ - if(document.all)e=event; - - if (e.target) source = e.target; - else if (e.srcElement) source = e.srcElement; - if (source.nodeType == 3) // defeat Safari bug - source = source.parentNode; - - if(source.id && source.id.indexOf('resize')>=0)return; - - imageDiv_currentLeft = cropDiv_dotted.style.left.replace('px','')/1; - imageDiv_currentTop = cropDiv_dotted.style.top.replace('px','')/1; - imageDiv_currentWidth = cropDiv_dotted.style.width.replace('px','')/1; - imageDiv_currentHeight = cropDiv_dotted.style.height.replace('px','')/1; - cropEvent_eventX = e.clientX; - cropEvent_eventY = e.clientY; - - crop_moveCounter = 0; - cropScript_timerMove(); - return false; -} - -function cropScript_timerMove() -{ - if(crop_moveCounter>=0 && crop_moveCounter<10){ - crop_moveCounter++; - setTimeout('cropScript_timerMove()',1); - return; - } - -} - -function cropScript_initResize(e) -{ - if(document.all)e = event; - - cropDiv_dotted.style.cursor = 'default'; - crop_currentResizeType = this.id; - - cropEvent_eventX = e.clientX; - cropEvent_eventY = e.clientY; - crop_resizeCounter = 0; - imageDiv_currentWidth = cropDiv_dotted.style.width.replace('px','')/1; - imageDiv_currentHeight = cropDiv_dotted.style.height.replace('px','')/1; - imageDiv_currentLeft = cropDiv_dotted.style.left.replace('px','')/1; - imageDiv_currentTop = cropDiv_dotted.style.top.replace('px','')/1; - - - cropWidthRatio = cropDiv_dotted.offsetWidth / cropDiv_dotted.offsetHeight; - if(crop_script_fixedRatio)cropWidthRatio = crop_script_fixedRatio; - - if(document.all){ - var div = cropDiv_dotted.getElementsByTagName('DIV')[0]; - div.style.display='none'; - } - - cropScript_timerResize(); - return false; - -} - -function cropScript_timerResize() -{ - if(crop_resizeCounter>=0 && crop_resizeCounter<10){ - crop_resizeCounter = crop_resizeCounter + 1; - setTimeout('cropScript_timerResize()',1); - return; - } - - -} - -function cropScript_executeCrop(buttonObj) -{ - crop_startProgressBar(); - buttonObj.style.visibility='hidden'; - var ajaxIndex = cropScriptAjaxObjects.length; - cropScriptAjaxObjects[ajaxIndex] = new sack(); - var url = crop_script_server_file + '?image_path=' + document.getElementById('image_path').value - + '&image_url=' + document.getElementById('image_url').value - + '&x=' + document.getElementById('input_crop_x').value - + '&y=' + document.getElementById('input_crop_y').value - + '&width=' + document.getElementById('input_crop_width').value - + '&height=' + document.getElementById('input_crop_height').value - + '&percentSize=' + document.getElementById('crop_percent_size').value; - - - cropScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - cropScriptAjaxObjects[ajaxIndex].onCompletion = function(){ cropScript_cropCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found - cropScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -function cropScript_cropCompleted(ajaxIndex,buttonObj) -{ - buttonObj.style.visibility=''; - eval(cropScriptAjaxObjects[ajaxIndex].response) - cropScriptAjaxObjects[ajaxIndex] = false; - crop_hideProgressBar(); -} - - -function crop_cancelEvent(e) -{ - if(document.all)e = event; - if (e.target) source = e.target; - else if (e.srcElement) source = e.srcElement; - if (source.nodeType == 3) // defeat Safari bug - source = source.parentNode; - - if(source.tagName && source.tagName.toLowerCase()=='input')return true; - return false; -} - -function cropScript_saveCrop(buttonObj) -{ - crop_startProgressBar(); - buttonObj.style.visibility='hidden'; - var ajaxIndex = cropScriptAjaxObjects.length; - cropScriptAjaxObjects[ajaxIndex] = new sack(); - var url = crop_script_server_file + '?image_path=' + document.getElementById('image_path').value - + '&image_url=' + document.getElementById('image_url').value - + '&x=' + document.getElementById('input_crop_x').value - + '&y=' + document.getElementById('input_crop_y').value - + '&width=' + document.getElementById('input_crop_width').value - + '&height=' + document.getElementById('input_crop_height').value - + '&percentSize=' + document.getElementById('crop_percent_size').value - + '&save=1'; - - cropScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - cropScriptAjaxObjects[ajaxIndex].onCompletion = function(){ cropScript_cropCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found - cropScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -function cropScript_cancelCrop(buttonObj) -{ - crop_startProgressBar(); - buttonObj.style.visibility='hidden'; - var ajaxIndex = cropScriptAjaxObjects.length; - cropScriptAjaxObjects[ajaxIndex] = new sack(); - var url = crop_script_server_file + '?image_path=' + document.getElementById('image_path').value - + '&image_url=' + document.getElementById('image_url').value - + '&x=' + document.getElementById('input_crop_x').value - + '&y=' + document.getElementById('input_crop_y').value - + '&width=' + document.getElementById('input_crop_width').value - + '&height=' + document.getElementById('input_crop_height').value - + '&percentSize=' + document.getElementById('crop_percent_size').value - + '&cancel=1'; - - cropScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - cropScriptAjaxObjects[ajaxIndex].onCompletion = function(){ cropScript_cropCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found - cropScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -function crop_delpreview(){ - var ajaxIndex = cropScriptAjaxObjects.length; - cropScriptAjaxObjects[ajaxIndex] = new sack(); - var url = crop_script_server_file + '?image_path=' + document.getElementById('fimage_path').value - + '&image_url=' + document.getElementById('fimage_url').value - + '&delprev=1'; - - cropScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - cropScriptAjaxObjects[ajaxIndex].onCompletion = function(){ - eval(cropScriptAjaxObjects[ajaxIndex].response) - cropScriptAjaxObjects[ajaxIndex] = false; - crop_hideProgressBar(); - }; // Specify function that will be executed after file has been found - cropScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -var mouseMoveEventInProgress = false; -function cropScript_mouseMove(e) -{ - - if(mouseMoveEventInProgress)return; - if(crop_moveCounter<10 && crop_resizeCounter<10)return; - if(document.all)mouseMoveEventInProgress = true; - if(document.all)e = event; - - - - - if(crop_resizeCounter==10){ - - - if(crop_currentResizeType=='e-resize' || crop_currentResizeType=='ne-resize' || crop_currentResizeType == 'se-resize'){ - cropDiv_dotted.style.width = Math.max(crop_minimumWidthHeight,(imageDiv_currentWidth + e.clientX - cropEvent_eventX)) + 'px'; - } - if(crop_currentResizeType=='s-resize' || crop_currentResizeType=='sw-resize' || crop_currentResizeType == 'se-resize'){ - cropDiv_dotted.style.height = Math.max(crop_minimumWidthHeight,(imageDiv_currentHeight + e.clientY - cropEvent_eventY)) + 'px'; - } - - if(crop_currentResizeType=='w-resize' || crop_currentResizeType=='sw-resize' || crop_currentResizeType=='nw-resize'){ - var tmpTop = cropDiv_dotted.style.left.replace('px','')/1; - var newTop = Math.max(0,(imageDiv_currentLeft + e.clientX - cropEvent_eventX)); - if((newTop + crop_minimumWidthHeight)> (cropDiv_dotted.style.left.replace('px','')/1 + cropDiv_dotted.style.width.replace('px','')/1)){ - newTop = (cropDiv_dotted.style.left.replace('px','')/1 + cropDiv_dotted.style.width.replace('px','')/1) - crop_minimumWidthHeight; - } - cropDiv_dotted.style.left = newTop + 'px'; - cropDiv_dotted.style.width = (cropDiv_dotted.style.width.replace('px','')/1 + tmpTop - cropDiv_dotted.style.left.replace('px','')/1) + 'px'; - } - - if(crop_currentResizeType=='n-resize' || crop_currentResizeType=='nw-resize' || crop_currentResizeType=='ne-resize'){ - var tmpTop = cropDiv_dotted.style.top.replace('px','')/1; - var newTop = Math.max(0,(imageDiv_currentTop + e.clientY - cropEvent_eventY)); - if((newTop + crop_minimumWidthHeight)> (cropDiv_dotted.style.top.replace('px','')/1 + cropDiv_dotted.style.height.replace('px','')/1)){ - newTop = (cropDiv_dotted.style.top.replace('px','')/1 + cropDiv_dotted.style.height.replace('px','')/1) - crop_minimumWidthHeight; - } - cropDiv_dotted.style.top = newTop + 'px'; - cropDiv_dotted.style.height = (cropDiv_dotted.style.height.replace('px','')/1 + tmpTop - cropDiv_dotted.style.top.replace('px','')/1) + 'px'; - } - - if((cropDiv_dotted.offsetHeight + (cropToolBorderWidth*2) + cropDiv_dotted.style.top.replace('px','')/1) > crop_imageHeight) - cropDiv_dotted.style.height = (crop_imageHeight - cropDiv_dotted.style.top.replace('px','')/1 - (cropToolBorderWidth*2)) + 'px'; - - if((cropDiv_dotted.offsetWidth + (cropToolBorderWidth*2) + cropDiv_dotted.style.left.replace('px','')/1) > crop_imageWidth) - cropDiv_dotted.style.width = (crop_imageWidth - cropDiv_dotted.style.left.replace('px','')/1 - (cropToolBorderWidth*2)) + 'px'; - - - - if(e.ctrlKey || crop_script_alwaysPreserveAspectRatio)preserveAspectRatio=true; else preserveAspectRatio = false; - - if(preserveAspectRatio){ - var tmpRatio = cropDiv_dotted.offsetWidth / cropDiv_dotted.offsetHeight; - if(tmpRatio crop_imageHeight){ - var ratioToAdjust = (crop_imageHeight-cropDiv_dotted.style.top.replace('px','')/1)/(cropDiv_dotted.offsetHeight + (cropToolBorderWidth*2)); - if(Math.round((cropDiv_dotted.style.width.replace('px','') * ratioToAdjust) + cropToolBorderWidth)>=crop_minimumWidthHeight){ - cropDiv_dotted.style.height = Math.round((cropDiv_dotted.style.height.replace('px','') * ratioToAdjust) + cropToolBorderWidth) + 'px'; - cropDiv_dotted.style.width = Math.round((cropDiv_dotted.style.width.replace('px','') * ratioToAdjust) + cropToolBorderWidth) + 'px'; - }else{ - cropDiv_dotted.style.top = (crop_imageHeight-cropDiv_dotted.style.height.replace('px','')) + 'px'; - } - - } - - if((cropDiv_dotted.offsetWidth + (cropToolBorderWidth*2) + cropDiv_dotted.style.left.replace('px','')/1) > crop_imageWidth){ - var ratioToAdjust = (crop_imageWidth-cropDiv_dotted.style.left.replace('px','')/1)/(cropDiv_dotted.offsetWidth + (cropToolBorderWidth*2)); - if(Math.round((cropDiv_dotted.style.height.replace('px','') * ratioToAdjust) + cropToolBorderWidth)>=crop_minimumWidthHeight){ - cropDiv_dotted.style.height = Math.round((cropDiv_dotted.style.height.replace('px','') * ratioToAdjust) + cropToolBorderWidth) + 'px'; - cropDiv_dotted.style.width = Math.round((cropDiv_dotted.style.width.replace('px','') * ratioToAdjust) + cropToolBorderWidth) + 'px'; - }else{ - cropDiv_dotted.style.left = (crop_imageWidth-cropDiv_dotted.style.width.replace('px','')) + 'px'; - } - - } - - - } - if(!crop_script_fixedRatio && !e.ctrlKey)cropWidthRatio = cropDiv_dotted.offsetWidth / cropDiv_dotted.offsetHeight; - - - } - - if(crop_moveCounter==10){ - var tmpLeft = imageDiv_currentLeft + e.clientX - cropEvent_eventX; - if(tmpLeft<0)tmpLeft=0; - if((tmpLeft + imageDiv_currentWidth + (cropToolBorderWidth*2))>crop_imageWidth)tmpLeft = crop_imageWidth - imageDiv_currentWidth - (cropToolBorderWidth*2); - cropDiv_dotted.style.left = tmpLeft + 'px'; - var tmpTop = imageDiv_currentTop + e.clientY - cropEvent_eventY; - if(tmpTop<0)tmpTop=0; - if((tmpTop + imageDiv_currentHeight + (cropToolBorderWidth*2))>crop_imageHeight)tmpTop = crop_imageHeight - imageDiv_currentHeight - (cropToolBorderWidth*2); - cropDiv_dotted.style.top = tmpTop + 'px'; - - } - - repositionSmallSquares(); - resizeTransparentSquares(); - if(updateFormValuesAsYouDrag)cropScript_updateFormValues(); - mouseMoveEventInProgress = false; - - -} - -function repositionSmallSquares() -{ - smallSquare_tc.style.left = (Math.floor((cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) /2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_bc.style.left = (Math.floor((cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) /2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_tr.style.left = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_rc.style.left = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_br.style.left = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - - smallSquare_br.style.top = (cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_bc.style.top = (cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_bl.style.top = (cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_lc.style.top = (Math.floor((cropDiv_dotted.style.height.replace('px','')/1 + cropToolBorderWidth)/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - smallSquare_rc.style.top = (Math.floor((cropDiv_dotted.style.height.replace('px','')/1 + cropToolBorderWidth)/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; - -} - -function resizeTransparentSquares() -{ - - cropDiv_left.style.width = cropDiv_dotted.style.left; - cropDiv_right.style.width = Math.max(0,crop_imageWidth - (cropToolBorderWidth*2) - (cropDiv_dotted.style.width.replace('px','')/1 + cropDiv_dotted.style.left.replace('px','')/1)) + 'px'; - cropDiv_right.style.left = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2) + cropDiv_dotted.style.left.replace('px','')/1) + 'px'; - cropDiv_bottom.style.height = Math.max(0,crop_imageHeight - (cropToolBorderWidth*2) - (cropDiv_dotted.style.height.replace('px','')/1 + cropDiv_dotted.style.top.replace('px','')/1)) + 'px'; - cropDiv_bottom.style.top = (cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2) + cropDiv_dotted.style.top.replace('px','')/1) + 'px'; - - cropDiv_top.style.height = cropDiv_dotted.style.top; - - cropDiv_bottom.style.left = cropDiv_dotted.style.left; - cropDiv_bottom.style.width = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) + 'px' ; - cropDiv_top.style.left = cropDiv_dotted.style.left; - cropDiv_top.style.width = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) + 'px' ; - - if(cropDiv_left.style.width=='0px')cropDiv_left.style.visibility='hidden';else cropDiv_left.style.visibility='visible'; - if(cropDiv_right.style.width=='0px')cropDiv_right.style.visibility='hidden';else cropDiv_right.style.visibility='visible'; - if(cropDiv_bottom.style.width=='0px')cropDiv_bottom.style.visibility='hidden';else cropDiv_bottom.style.visibility='visible'; - -} - -function cropScript_updateFormValues() -{ - document.getElementById('input_crop_x').value = Math.round(cropDiv_dotted.style.left.replace('px','')/1 * (crop_originalImageWidth/crop_imageWidth)); - document.getElementById('input_crop_y').value = Math.round(cropDiv_dotted.style.top.replace('px','')/1 * (crop_originalImageHeight/crop_imageHeight)); - document.getElementById('input_crop_width').value = Math.round((cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) * (crop_originalImageWidth/crop_imageWidth)); - document.getElementById('input_crop_height').value = Math.round((cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2)) * (crop_originalImageHeight/crop_imageHeight)); - - -} - -function cropScript_stopResizeMove() -{ - crop_resizeCounter = -1; - crop_moveCounter = -1; - cropDiv_dotted.style.cursor = 'move'; - cropScript_updateFormValues(); - if(document.all){ - var div = cropDiv_dotted.getElementsByTagName('DIV')[0]; - div.style.display='block'; - } -} - -function cropScript_setCropSizeByInput() -{ - var obj_x = document.getElementById('input_crop_x'); - var obj_y = document.getElementById('input_crop_y'); - var obj_width = document.getElementById('input_crop_width'); - var obj_height = document.getElementById('input_crop_height'); - - obj_x.value = obj_x.value.replace(/[^0-9]/gi,''); - obj_y.value = obj_y.value.replace(/[^0-9]/gi,''); - obj_width.value = obj_width.value.replace(/[^0-9]/gi,''); - obj_height.value = obj_height.value.replace(/[^0-9]/gi,''); - - - - if(obj_x.value.length==0)obj_x.value=0; - if(obj_y.value.length==0)obj_y.value=0; - if(obj_width.value.length==0)obj_width.value=crop_originalImageWidth; - if(obj_height.value.length==0)obj_height.value=crop_originalImageHeight; - - - if(obj_x.value>(crop_originalImageWidth-crop_minimumWidthHeight))obj_x.value = crop_originalImageWidth-crop_minimumWidthHeight; - if(obj_y.value>(crop_originalImageHeight-crop_minimumWidthHeight))obj_y.value = crop_originalImageHeight-crop_minimumWidthHeight; - - if(obj_width.value/1 > crop_originalImageWidth)obj_width.value = crop_originalImageWidth - obj_x.value/1; - if(obj_height.value/1 > crop_originalImageHeight)obj_height.value = crop_originalImageHeight - obj_y.value/1; - - if(obj_x.value/1 + obj_width.value/1 > crop_originalImageWidth)obj_width.value = crop_originalImageWidth - obj_x.value; - if(obj_y.value/1 + obj_height.value/1 > crop_originalImageHeight)obj_height.value = crop_originalImageHeight - obj_y.value; - - - - cropDiv_dotted.style.left = Math.round(obj_x.value/1 * (crop_imageWidth / crop_originalImageWidth)) + 'px'; - cropDiv_dotted.style.top = Math.round(obj_y.value/1 * (crop_imageHeight / crop_originalImageHeight)) + 'px'; - cropDiv_dotted.style.width = Math.round((obj_width.value/1 - (cropToolBorderWidth*2)) * (crop_imageWidth / crop_originalImageWidth)) + 'px'; - cropDiv_dotted.style.height = Math.round((obj_height.value/1 - (cropToolBorderWidth*2)) * (crop_imageHeight / crop_originalImageHeight)) + 'px'; - - - repositionSmallSquares(); - resizeTransparentSquares(); - -} - - - -function cropScript_setBasicEvents() -{ - document.documentElement.ondragstart = crop_cancelEvent; - document.documentElement.onselectstart = crop_cancelEvent; - document.documentElement.onmousemove = cropScript_mouseMove; - document.documentElement.onmouseup = cropScript_stopResizeMove; - - document.getElementById('input_crop_x').onblur = cropScript_setCropSizeByInput; - document.getElementById('input_crop_y').onblur = cropScript_setCropSizeByInput; - document.getElementById('input_crop_width').onblur = cropScript_setCropSizeByInput; - document.getElementById('input_crop_height').onblur = cropScript_setCropSizeByInput; - document.getElementById('crop_percent_size').onblur = cropScript_validatePercent; - -} - -function cropScript_validatePercent() -{ - this.value=this.value.replace(/[^0-9]/gi,''); - if(this.value.length==0)this.value='1'; - if(this.value/1>crop_maximumPercent)this.value='100'; - if(this.value/1 div.parentNode.clientWidth)left = 0 - div.clientWidth; - div.style.left = left + 'px'; - - setTimeout('crop_progressBarMove()',20); - -} - -function crop_initFixedRatio() -{ - if(crop_script_fixedRatio>1){ - document.getElementById('input_crop_height').value = Math.round(document.getElementById('input_crop_width').value) / crop_script_fixedRatio; - - }else{ - document.getElementById('input_crop_width').value = Math.round(document.getElementById('input_crop_height').value) / crop_script_fixedRatio; - - } - cropScript_setCropSizeByInput(); -} - -function init_imageCrop() -{ - //document.getElementById('label_dimension').innerHTML = crop_originalImageWidth + 'x' + crop_originalImageHeight; - cropScript_setBasicEvents(); - crop_createDivElements(); - crop_progressBar(); - cropScript_updateFormValues(); - if(crop_script_fixedRatio && crop_script_alwaysPreserveAspectRatio){ - crop_initFixedRatio(); - } -} - -function crop_removeDivElements(){ - crop_imageDiv = document.getElementById('imageContainer'); - - var removeNode = document.getElementById('cropDiv_left'); - if (removeNode)crop_imageDiv.removeChild(removeNode); - var removeNode = document.getElementById('cropDiv_top'); - if (removeNode)crop_imageDiv.removeChild(removeNode); - var removeNode = document.getElementById('cropDiv_right'); - if (removeNode)crop_imageDiv.removeChild(removeNode); - var removeNode = document.getElementById('cropDiv_bottom'); - if (removeNode)crop_imageDiv.removeChild(removeNode); - var removeNode = document.getElementById('cropDiv_dotted'); - if (removeNode)crop_imageDiv.removeChild(removeNode); - - crop_delpreview(); +/************************************************************************************************************ +(C) www.dhtmlgoodies.com, April 2006 + +Update log: +August, 9th, 2006: Added a fix to the preserve aspect ratio feature ( Thanks to Urko Benito) +August, 11th, 2006: If fixed ratio is set, resize crop area initially + +This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. + +Terms of use: +You are free to use this script as long as the copyright message is kept intact. However, you may not +redistribute, sell or repost it without our permission. + +Thank you! + +www.dhtmlgoodies.com +Alf Magne Kalleland + +************************************************************************************************************/ + + + +var crop_script_alwaysPreserveAspectRatio = false; +var crop_script_fixedRatio = false; // Fixed aspect ratio(example of value: 1.5). Width of cropping area relative to height(1.5 means that the width is 150% of the height) +// Set this variable to false if you don't want a fixed aspect ratio + +var crop_script_browserIsOpera = navigator.userAgent.indexOf('Opera')>=0?true:false; +var cropDiv_left = false; +var cropDiv_top = false; +var cropDiv_right = false; +var cropDiv_bottom = false; +var cropDiv_dotted = false; + +var crop_currentResizeType = false; + +var cropEvent_posX; +var cropEvent_posY; + +var cropEvent_eventX; +var cropEvent_eventY; +var crop_resizeCounter = -1; +var crop_moveCounter = -1; + +var crop_imageDiv = false; +var imageDiv_currentWidth = false; +var imageDiv_currentHeight = false; +var imageDiv_currentLeft = false; +var imageDiv_currentTop = false; + +var smallSquare_tl; +var smallSquare_tc; +var smallSquare_tr; +var smallSquare_lc; +var smallSquare_rc; +var smallSquare_bl; +var smallSquare_bc; +var smallSquare_br; + +var offsetSmallSquares = Math.floor(smallSquareWidth/2); + +var cropScriptAjaxObjects = new Array(); +var preserveAspectRatio = false; + +var cropWidthRatio = false; // width of cropping area relative to height +function crop_createDivElements() +{ + + + + crop_imageDiv= document.getElementById('imageContainer'); + + cropDiv_left = document.createElement('DIV'); + cropDiv_left.className = 'crop_transparentDiv'; + cropDiv_left.style.visibility = 'visible'; + cropDiv_left.style.left = '0px'; + cropDiv_left.style.top = '0px'; + cropDiv_left.style.height = crop_imageHeight + 'px'; + cropDiv_left.style.width = '0px'; + cropDiv_left.innerHTML = ''; + cropDiv_left.id = 'cropDiv_left'; + crop_imageDiv.appendChild(cropDiv_left); + + cropDiv_top = document.createElement('DIV'); + cropDiv_top.className = 'crop_transparentDiv'; + cropDiv_top.style.visibility = 'visible'; + cropDiv_top.style.left = '0px'; + cropDiv_top.style.top = '0px'; + cropDiv_top.style.height = '0px'; + cropDiv_top.style.width = crop_imageWidth + 'px'; + cropDiv_top.innerHTML = ''; + cropDiv_top.id = 'cropDiv_top'; + crop_imageDiv.appendChild(cropDiv_top); + + cropDiv_right = document.createElement('DIV'); + cropDiv_right.className = 'crop_transparentDiv'; + cropDiv_right.style.visibility = 'visible'; + cropDiv_right.style.left = (crop_imageWidth) + 'px'; + cropDiv_right.style.top = '0px'; + cropDiv_right.style.height = crop_imageHeight + 'px'; + cropDiv_right.style.width = '0px'; + cropDiv_right.innerHTML = ''; + cropDiv_right.id = 'cropDiv_right'; + crop_imageDiv.appendChild(cropDiv_right); + + cropDiv_bottom = document.createElement('DIV'); + cropDiv_bottom.className = 'crop_transparentDiv'; + cropDiv_bottom.style.visibility = 'visible'; + cropDiv_bottom.style.left = '0px'; + cropDiv_bottom.style.top = (crop_imageHeight) + 'px'; + cropDiv_bottom.style.height = '0px'; + cropDiv_bottom.style.width = crop_imageWidth + 'px'; + cropDiv_bottom.innerHTML = ''; + cropDiv_bottom.id = 'cropDiv_bottom'; + crop_imageDiv.appendChild(cropDiv_bottom); + + cropDiv_dotted = document.createElement('DIV'); + cropDiv_dotted.className='crop_dottedDiv'; + cropDiv_dotted.style.left = '0px'; + cropDiv_dotted.style.top = '0px'; + cropDiv_dotted.style.width = (crop_imageWidth-(cropToolBorderWidth*2)) + 'px'; + cropDiv_dotted.style.height = (crop_imageHeight-(cropToolBorderWidth*2)) + 'px'; + cropDiv_dotted.innerHTML = '
'; + cropDiv_dotted.style.cursor = 'move'; + cropDiv_dotted.id = 'cropDiv_dotted'; + + if(crop_script_browserIsOpera){ + var div = cropDiv_dotted.getElementsByTagName('DIV')[0]; + div.style.backgroundColor='transparent'; + cropDiv_bottom.style.backgroundColor='transparent'; + cropDiv_right.style.backgroundColor='transparent'; + cropDiv_top.style.backgroundColor='transparent'; + cropDiv_left.style.backgroundColor='transparent'; + + } + + cropDiv_dotted.onmousedown = cropScript_initMove; + + smallSquare_tl = document.createElement('IMG'); + smallSquare_tl.src = 'images/small_square.gif'; + smallSquare_tl.style.position = 'absolute'; + smallSquare_tl.style.left = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_tl.style.top = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_tl.style.cursor = 'nw-resize'; + smallSquare_tl.id = 'nw-resize'; + smallSquare_tl.onmousedown = cropScript_initResize; + cropDiv_dotted.appendChild(smallSquare_tl); + + smallSquare_tr = document.createElement('IMG'); + smallSquare_tr.src = 'images/small_square.gif'; + smallSquare_tr.style.position = 'absolute'; + smallSquare_tr.style.left = (crop_imageWidth - offsetSmallSquares - (cropToolBorderWidth*2)) + 'px'; + smallSquare_tr.style.top = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_tr.style.cursor = 'ne-resize'; + smallSquare_tr.id = 'ne-resize'; + smallSquare_tr.onmousedown = cropScript_initResize; + cropDiv_dotted.appendChild(smallSquare_tr); + + smallSquare_bl = document.createElement('IMG'); + smallSquare_bl.src = 'images/small_square.gif'; + smallSquare_bl.style.position = 'absolute'; + smallSquare_bl.style.left = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_bl.style.top = (crop_imageHeight - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_bl.style.cursor = 'sw-resize'; + smallSquare_bl.id = 'sw-resize'; + smallSquare_bl.onmousedown = cropScript_initResize; + cropDiv_dotted.appendChild(smallSquare_bl); + + smallSquare_br = document.createElement('IMG'); + smallSquare_br.src = 'images/small_square.gif'; + smallSquare_br.style.position = 'absolute'; + smallSquare_br.style.left = (crop_imageWidth - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_br.style.top = (crop_imageHeight - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_br.style.cursor = 'se-resize'; + smallSquare_br.id = 'se-resize'; + smallSquare_br.onmousedown = cropScript_initResize; + cropDiv_dotted.appendChild(smallSquare_br); + + smallSquare_tc = document.createElement('IMG'); + smallSquare_tc.src = 'images/small_square.gif'; + smallSquare_tc.style.position = 'absolute'; + smallSquare_tc.style.left = (Math.floor(crop_imageWidth/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_tc.style.top = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_tc.style.cursor = 's-resize'; + smallSquare_tc.id = 'n-resize'; + smallSquare_tc.onmousedown = cropScript_initResize; + cropDiv_dotted.appendChild(smallSquare_tc); + + smallSquare_bc = document.createElement('IMG'); + smallSquare_bc.src = 'images/small_square.gif'; + smallSquare_bc.style.position = 'absolute'; + smallSquare_bc.style.left = (Math.floor(crop_imageWidth/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_bc.style.top = (crop_imageHeight - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_bc.style.cursor = 's-resize'; + smallSquare_bc.id = 's-resize'; + smallSquare_bc.onmousedown = cropScript_initResize; + cropDiv_dotted.appendChild(smallSquare_bc); + + smallSquare_lc = document.createElement('IMG'); + smallSquare_lc.src = 'images/small_square.gif'; + smallSquare_lc.style.position = 'absolute'; + smallSquare_lc.style.left = (-offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_lc.style.top = (Math.floor(crop_imageHeight/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_lc.style.cursor = 'e-resize'; + smallSquare_lc.id = 'w-resize'; + smallSquare_lc.onmousedown = cropScript_initResize; + cropDiv_dotted.appendChild(smallSquare_lc); + + smallSquare_rc = document.createElement('IMG'); + smallSquare_rc.src = 'images/small_square.gif'; + smallSquare_rc.style.position = 'absolute'; + smallSquare_rc.style.left = (crop_imageWidth - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_rc.style.top = (Math.floor(crop_imageHeight/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_rc.style.cursor = 'e-resize'; + smallSquare_rc.id = 'e-resize'; + smallSquare_rc.onmousedown = cropScript_initResize; + cropDiv_dotted.appendChild(smallSquare_rc); + + crop_imageDiv.appendChild(cropDiv_dotted); +} + +function cropScript_initMove(e) +{ + if(document.all)e=event; + + if (e.target) source = e.target; + else if (e.srcElement) source = e.srcElement; + if (source.nodeType == 3) // defeat Safari bug + source = source.parentNode; + + if(source.id && source.id.indexOf('resize')>=0)return; + + imageDiv_currentLeft = cropDiv_dotted.style.left.replace('px','')/1; + imageDiv_currentTop = cropDiv_dotted.style.top.replace('px','')/1; + imageDiv_currentWidth = cropDiv_dotted.style.width.replace('px','')/1; + imageDiv_currentHeight = cropDiv_dotted.style.height.replace('px','')/1; + cropEvent_eventX = e.clientX; + cropEvent_eventY = e.clientY; + + crop_moveCounter = 0; + cropScript_timerMove(); + return false; +} + +function cropScript_timerMove() +{ + if(crop_moveCounter>=0 && crop_moveCounter<10){ + crop_moveCounter++; + setTimeout('cropScript_timerMove()',1); + return; + } + +} + +function cropScript_initResize(e) +{ + if(document.all)e = event; + + cropDiv_dotted.style.cursor = 'default'; + crop_currentResizeType = this.id; + + cropEvent_eventX = e.clientX; + cropEvent_eventY = e.clientY; + crop_resizeCounter = 0; + imageDiv_currentWidth = cropDiv_dotted.style.width.replace('px','')/1; + imageDiv_currentHeight = cropDiv_dotted.style.height.replace('px','')/1; + imageDiv_currentLeft = cropDiv_dotted.style.left.replace('px','')/1; + imageDiv_currentTop = cropDiv_dotted.style.top.replace('px','')/1; + + + cropWidthRatio = cropDiv_dotted.offsetWidth / cropDiv_dotted.offsetHeight; + if(crop_script_fixedRatio)cropWidthRatio = crop_script_fixedRatio; + + if(document.all){ + var div = cropDiv_dotted.getElementsByTagName('DIV')[0]; + div.style.display='none'; + } + + cropScript_timerResize(); + return false; + +} + +function cropScript_timerResize() +{ + if(crop_resizeCounter>=0 && crop_resizeCounter<10){ + crop_resizeCounter = crop_resizeCounter + 1; + setTimeout('cropScript_timerResize()',1); + return; + } + + +} + +function cropScript_executeCrop(buttonObj) +{ + crop_startProgressBar(); + buttonObj.style.visibility='hidden'; + var ajaxIndex = cropScriptAjaxObjects.length; + cropScriptAjaxObjects[ajaxIndex] = new sack(); + var url = crop_script_server_file + '?image_path=' + document.getElementById('image_path').value + + '&image_url=' + document.getElementById('image_url').value + + '&x=' + document.getElementById('input_crop_x').value + + '&y=' + document.getElementById('input_crop_y').value + + '&width=' + document.getElementById('input_crop_width').value + + '&height=' + document.getElementById('input_crop_height').value + + '&percentSize=' + document.getElementById('crop_percent_size').value; + + + cropScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + cropScriptAjaxObjects[ajaxIndex].onCompletion = function(){ cropScript_cropCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found + cropScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +function cropScript_cropCompleted(ajaxIndex,buttonObj) +{ + buttonObj.style.visibility=''; + eval(cropScriptAjaxObjects[ajaxIndex].response); + cropScriptAjaxObjects[ajaxIndex] = false; + crop_hideProgressBar(); +} + + +function crop_cancelEvent(e) +{ + if(document.all)e = event; + if (e.target) source = e.target; + else if (e.srcElement) source = e.srcElement; + if (source.nodeType == 3) // defeat Safari bug + source = source.parentNode; + + if(source.tagName && source.tagName.toLowerCase()=='input')return true; + return false; +} + +function cropScript_saveCrop(buttonObj) +{ + crop_startProgressBar(); + buttonObj.style.visibility='hidden'; + var ajaxIndex = cropScriptAjaxObjects.length; + cropScriptAjaxObjects[ajaxIndex] = new sack(); + var url = crop_script_server_file + '?image_path=' + document.getElementById('image_path').value + + '&image_url=' + document.getElementById('image_url').value + + '&x=' + document.getElementById('input_crop_x').value + + '&y=' + document.getElementById('input_crop_y').value + + '&width=' + document.getElementById('input_crop_width').value + + '&height=' + document.getElementById('input_crop_height').value + + '&percentSize=' + document.getElementById('crop_percent_size').value + + '&save=1'; + + cropScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + cropScriptAjaxObjects[ajaxIndex].onCompletion = function(){ cropScript_cropCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found + cropScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +function cropScript_cancelCrop(buttonObj) +{ + crop_startProgressBar(); + buttonObj.style.visibility='hidden'; + var ajaxIndex = cropScriptAjaxObjects.length; + cropScriptAjaxObjects[ajaxIndex] = new sack(); + var url = crop_script_server_file + '?image_path=' + document.getElementById('image_path').value + + '&image_url=' + document.getElementById('image_url').value + + '&x=' + document.getElementById('input_crop_x').value + + '&y=' + document.getElementById('input_crop_y').value + + '&width=' + document.getElementById('input_crop_width').value + + '&height=' + document.getElementById('input_crop_height').value + + '&percentSize=' + document.getElementById('crop_percent_size').value + + '&cancel=1'; + + cropScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + cropScriptAjaxObjects[ajaxIndex].onCompletion = function(){ cropScript_cropCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found + cropScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +function crop_delpreview(){ + var ajaxIndex = cropScriptAjaxObjects.length; + cropScriptAjaxObjects[ajaxIndex] = new sack(); + var url = crop_script_server_file + '?image_path=' + document.getElementById('fimage_path').value + + '&image_url=' + document.getElementById('fimage_url').value + + '&delprev=1'; + + cropScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + cropScriptAjaxObjects[ajaxIndex].onCompletion = function(){ + eval(cropScriptAjaxObjects[ajaxIndex].response) + cropScriptAjaxObjects[ajaxIndex] = false; + crop_hideProgressBar(); + }; // Specify function that will be executed after file has been found + cropScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +var mouseMoveEventInProgress = false; +function cropScript_mouseMove(e) +{ + + if(mouseMoveEventInProgress)return; + if(crop_moveCounter<10 && crop_resizeCounter<10)return; + if(document.all)mouseMoveEventInProgress = true; + if(document.all)e = event; + + + + + if(crop_resizeCounter==10){ + + + if(crop_currentResizeType=='e-resize' || crop_currentResizeType=='ne-resize' || crop_currentResizeType == 'se-resize'){ + cropDiv_dotted.style.width = Math.max(crop_minimumWidthHeight,(imageDiv_currentWidth + e.clientX - cropEvent_eventX)) + 'px'; + } + if(crop_currentResizeType=='s-resize' || crop_currentResizeType=='sw-resize' || crop_currentResizeType == 'se-resize'){ + cropDiv_dotted.style.height = Math.max(crop_minimumWidthHeight,(imageDiv_currentHeight + e.clientY - cropEvent_eventY)) + 'px'; + } + + if(crop_currentResizeType=='w-resize' || crop_currentResizeType=='sw-resize' || crop_currentResizeType=='nw-resize'){ + var tmpTop = cropDiv_dotted.style.left.replace('px','')/1; + var newTop = Math.max(0,(imageDiv_currentLeft + e.clientX - cropEvent_eventX)); + if((newTop + crop_minimumWidthHeight)> (cropDiv_dotted.style.left.replace('px','')/1 + cropDiv_dotted.style.width.replace('px','')/1)){ + newTop = (cropDiv_dotted.style.left.replace('px','')/1 + cropDiv_dotted.style.width.replace('px','')/1) - crop_minimumWidthHeight; + } + cropDiv_dotted.style.left = newTop + 'px'; + cropDiv_dotted.style.width = (cropDiv_dotted.style.width.replace('px','')/1 + tmpTop - cropDiv_dotted.style.left.replace('px','')/1) + 'px'; + } + + if(crop_currentResizeType=='n-resize' || crop_currentResizeType=='nw-resize' || crop_currentResizeType=='ne-resize'){ + var tmpTop = cropDiv_dotted.style.top.replace('px','')/1; + var newTop = Math.max(0,(imageDiv_currentTop + e.clientY - cropEvent_eventY)); + if((newTop + crop_minimumWidthHeight)> (cropDiv_dotted.style.top.replace('px','')/1 + cropDiv_dotted.style.height.replace('px','')/1)){ + newTop = (cropDiv_dotted.style.top.replace('px','')/1 + cropDiv_dotted.style.height.replace('px','')/1) - crop_minimumWidthHeight; + } + cropDiv_dotted.style.top = newTop + 'px'; + cropDiv_dotted.style.height = (cropDiv_dotted.style.height.replace('px','')/1 + tmpTop - cropDiv_dotted.style.top.replace('px','')/1) + 'px'; + } + + if((cropDiv_dotted.offsetHeight + (cropToolBorderWidth*2) + cropDiv_dotted.style.top.replace('px','')/1) > crop_imageHeight) + cropDiv_dotted.style.height = (crop_imageHeight - cropDiv_dotted.style.top.replace('px','')/1 - (cropToolBorderWidth*2)) + 'px'; + + if((cropDiv_dotted.offsetWidth + (cropToolBorderWidth*2) + cropDiv_dotted.style.left.replace('px','')/1) > crop_imageWidth) + cropDiv_dotted.style.width = (crop_imageWidth - cropDiv_dotted.style.left.replace('px','')/1 - (cropToolBorderWidth*2)) + 'px'; + + + + if(e.ctrlKey || crop_script_alwaysPreserveAspectRatio)preserveAspectRatio=true; else preserveAspectRatio = false; + + if(preserveAspectRatio){ + var tmpRatio = cropDiv_dotted.offsetWidth / cropDiv_dotted.offsetHeight; + if(tmpRatio crop_imageHeight){ + var ratioToAdjust = (crop_imageHeight-cropDiv_dotted.style.top.replace('px','')/1)/(cropDiv_dotted.offsetHeight + (cropToolBorderWidth*2)); + if(Math.round((cropDiv_dotted.style.width.replace('px','') * ratioToAdjust) + cropToolBorderWidth)>=crop_minimumWidthHeight){ + cropDiv_dotted.style.height = Math.round((cropDiv_dotted.style.height.replace('px','') * ratioToAdjust) + cropToolBorderWidth) + 'px'; + cropDiv_dotted.style.width = Math.round((cropDiv_dotted.style.width.replace('px','') * ratioToAdjust) + cropToolBorderWidth) + 'px'; + }else{ + cropDiv_dotted.style.top = (crop_imageHeight-cropDiv_dotted.style.height.replace('px','')) + 'px'; + } + + } + + if((cropDiv_dotted.offsetWidth + (cropToolBorderWidth*2) + cropDiv_dotted.style.left.replace('px','')/1) > crop_imageWidth){ + var ratioToAdjust = (crop_imageWidth-cropDiv_dotted.style.left.replace('px','')/1)/(cropDiv_dotted.offsetWidth + (cropToolBorderWidth*2)); + if(Math.round((cropDiv_dotted.style.height.replace('px','') * ratioToAdjust) + cropToolBorderWidth)>=crop_minimumWidthHeight){ + cropDiv_dotted.style.height = Math.round((cropDiv_dotted.style.height.replace('px','') * ratioToAdjust) + cropToolBorderWidth) + 'px'; + cropDiv_dotted.style.width = Math.round((cropDiv_dotted.style.width.replace('px','') * ratioToAdjust) + cropToolBorderWidth) + 'px'; + }else{ + cropDiv_dotted.style.left = (crop_imageWidth-cropDiv_dotted.style.width.replace('px','')) + 'px'; + } + + } + + + } + if(!crop_script_fixedRatio && !e.ctrlKey)cropWidthRatio = cropDiv_dotted.offsetWidth / cropDiv_dotted.offsetHeight; + + + } + + if(crop_moveCounter==10){ + var tmpLeft = imageDiv_currentLeft + e.clientX - cropEvent_eventX; + if(tmpLeft<0)tmpLeft=0; + if((tmpLeft + imageDiv_currentWidth + (cropToolBorderWidth*2))>crop_imageWidth)tmpLeft = crop_imageWidth - imageDiv_currentWidth - (cropToolBorderWidth*2); + cropDiv_dotted.style.left = tmpLeft + 'px'; + var tmpTop = imageDiv_currentTop + e.clientY - cropEvent_eventY; + if(tmpTop<0)tmpTop=0; + if((tmpTop + imageDiv_currentHeight + (cropToolBorderWidth*2))>crop_imageHeight)tmpTop = crop_imageHeight - imageDiv_currentHeight - (cropToolBorderWidth*2); + cropDiv_dotted.style.top = tmpTop + 'px'; + + } + + repositionSmallSquares(); + resizeTransparentSquares(); + if(updateFormValuesAsYouDrag)cropScript_updateFormValues(); + mouseMoveEventInProgress = false; + + +} + +function repositionSmallSquares() +{ + smallSquare_tc.style.left = (Math.floor((cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) /2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_bc.style.left = (Math.floor((cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) /2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_tr.style.left = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_rc.style.left = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_br.style.left = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + + smallSquare_br.style.top = (cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_bc.style.top = (cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_bl.style.top = (cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_lc.style.top = (Math.floor((cropDiv_dotted.style.height.replace('px','')/1 + cropToolBorderWidth)/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + smallSquare_rc.style.top = (Math.floor((cropDiv_dotted.style.height.replace('px','')/1 + cropToolBorderWidth)/2) - offsetSmallSquares -(cropToolBorderWidth*2)) + 'px'; + +} + +function resizeTransparentSquares() +{ + + cropDiv_left.style.width = cropDiv_dotted.style.left; + cropDiv_right.style.width = Math.max(0,crop_imageWidth - (cropToolBorderWidth*2) - (cropDiv_dotted.style.width.replace('px','')/1 + cropDiv_dotted.style.left.replace('px','')/1)) + 'px'; + cropDiv_right.style.left = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2) + cropDiv_dotted.style.left.replace('px','')/1) + 'px'; + cropDiv_bottom.style.height = Math.max(0,crop_imageHeight - (cropToolBorderWidth*2) - (cropDiv_dotted.style.height.replace('px','')/1 + cropDiv_dotted.style.top.replace('px','')/1)) + 'px'; + cropDiv_bottom.style.top = (cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2) + cropDiv_dotted.style.top.replace('px','')/1) + 'px'; + + cropDiv_top.style.height = cropDiv_dotted.style.top; + + cropDiv_bottom.style.left = cropDiv_dotted.style.left; + cropDiv_bottom.style.width = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) + 'px' ; + cropDiv_top.style.left = cropDiv_dotted.style.left; + cropDiv_top.style.width = (cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) + 'px' ; + + if(cropDiv_left.style.width=='0px')cropDiv_left.style.visibility='hidden';else cropDiv_left.style.visibility='visible'; + if(cropDiv_right.style.width=='0px')cropDiv_right.style.visibility='hidden';else cropDiv_right.style.visibility='visible'; + if(cropDiv_bottom.style.width=='0px')cropDiv_bottom.style.visibility='hidden';else cropDiv_bottom.style.visibility='visible'; + +} + +function cropScript_updateFormValues() +{ + document.getElementById('input_crop_x').value = Math.round(cropDiv_dotted.style.left.replace('px','')/1 * (crop_originalImageWidth/crop_imageWidth)); + document.getElementById('input_crop_y').value = Math.round(cropDiv_dotted.style.top.replace('px','')/1 * (crop_originalImageHeight/crop_imageHeight)); + document.getElementById('input_crop_width').value = Math.round((cropDiv_dotted.style.width.replace('px','')/1 + (cropToolBorderWidth*2)) * (crop_originalImageWidth/crop_imageWidth)); + document.getElementById('input_crop_height').value = Math.round((cropDiv_dotted.style.height.replace('px','')/1 + (cropToolBorderWidth*2)) * (crop_originalImageHeight/crop_imageHeight)); + + +} + +function cropScript_stopResizeMove() +{ + crop_resizeCounter = -1; + crop_moveCounter = -1; + cropDiv_dotted.style.cursor = 'move'; + cropScript_updateFormValues(); + if(document.all){ + var div = cropDiv_dotted.getElementsByTagName('DIV')[0]; + div.style.display='block'; + } +} + +function cropScript_setCropSizeByInput() +{ + var obj_x = document.getElementById('input_crop_x'); + var obj_y = document.getElementById('input_crop_y'); + var obj_width = document.getElementById('input_crop_width'); + var obj_height = document.getElementById('input_crop_height'); + + obj_x.value = obj_x.value.replace(/[^0-9]/gi,''); + obj_y.value = obj_y.value.replace(/[^0-9]/gi,''); + obj_width.value = obj_width.value.replace(/[^0-9]/gi,''); + obj_height.value = obj_height.value.replace(/[^0-9]/gi,''); + + + + if(obj_x.value.length==0)obj_x.value=0; + if(obj_y.value.length==0)obj_y.value=0; + if(obj_width.value.length==0)obj_width.value=crop_originalImageWidth; + if(obj_height.value.length==0)obj_height.value=crop_originalImageHeight; + + + if(obj_x.value>(crop_originalImageWidth-crop_minimumWidthHeight))obj_x.value = crop_originalImageWidth-crop_minimumWidthHeight; + if(obj_y.value>(crop_originalImageHeight-crop_minimumWidthHeight))obj_y.value = crop_originalImageHeight-crop_minimumWidthHeight; + + if(obj_width.value/1 > crop_originalImageWidth)obj_width.value = crop_originalImageWidth - obj_x.value/1; + if(obj_height.value/1 > crop_originalImageHeight)obj_height.value = crop_originalImageHeight - obj_y.value/1; + + if(obj_x.value/1 + obj_width.value/1 > crop_originalImageWidth)obj_width.value = crop_originalImageWidth - obj_x.value; + if(obj_y.value/1 + obj_height.value/1 > crop_originalImageHeight)obj_height.value = crop_originalImageHeight - obj_y.value; + + + + cropDiv_dotted.style.left = Math.round(obj_x.value/1 * (crop_imageWidth / crop_originalImageWidth)) + 'px'; + cropDiv_dotted.style.top = Math.round(obj_y.value/1 * (crop_imageHeight / crop_originalImageHeight)) + 'px'; + cropDiv_dotted.style.width = Math.round((obj_width.value/1 - (cropToolBorderWidth*2)) * (crop_imageWidth / crop_originalImageWidth)) + 'px'; + cropDiv_dotted.style.height = Math.round((obj_height.value/1 - (cropToolBorderWidth*2)) * (crop_imageHeight / crop_originalImageHeight)) + 'px'; + + + repositionSmallSquares(); + resizeTransparentSquares(); + +} + + + +function cropScript_setBasicEvents() +{ + document.documentElement.ondragstart = crop_cancelEvent; + document.documentElement.onselectstart = crop_cancelEvent; + document.documentElement.onmousemove = cropScript_mouseMove; + document.documentElement.onmouseup = cropScript_stopResizeMove; + + document.getElementById('input_crop_x').onblur = cropScript_setCropSizeByInput; + document.getElementById('input_crop_y').onblur = cropScript_setCropSizeByInput; + document.getElementById('input_crop_width').onblur = cropScript_setCropSizeByInput; + document.getElementById('input_crop_height').onblur = cropScript_setCropSizeByInput; + document.getElementById('crop_percent_size').onblur = cropScript_validatePercent; + +} + +function cropScript_validatePercent() +{ + this.value=this.value.replace(/[^0-9]/gi,''); + if(this.value.length==0)this.value='1'; + if(this.value/1>crop_maximumPercent)this.value='100'; + if(this.value/1 div.parentNode.clientWidth)left = 0 - div.clientWidth; + div.style.left = left + 'px'; + + setTimeout('crop_progressBarMove()',20); + +} + +function crop_initFixedRatio() +{ + if(crop_script_fixedRatio>1){ + document.getElementById('input_crop_height').value = Math.round(document.getElementById('input_crop_width').value) / crop_script_fixedRatio; + + }else{ + document.getElementById('input_crop_width').value = Math.round(document.getElementById('input_crop_height').value) / crop_script_fixedRatio; + + } + cropScript_setCropSizeByInput(); +} + +function init_imageCrop() +{ + //document.getElementById('label_dimension').innerHTML = crop_originalImageWidth + 'x' + crop_originalImageHeight; + cropScript_setBasicEvents(); + crop_createDivElements(); + crop_progressBar(); + cropScript_updateFormValues(); + if(crop_script_fixedRatio && crop_script_alwaysPreserveAspectRatio){ + crop_initFixedRatio(); + } +} + +function crop_removeDivElements(){ + crop_imageDiv = document.getElementById('imageContainer'); + + var removeNode = document.getElementById('cropDiv_left'); + if (removeNode)crop_imageDiv.removeChild(removeNode); + var removeNode = document.getElementById('cropDiv_top'); + if (removeNode)crop_imageDiv.removeChild(removeNode); + var removeNode = document.getElementById('cropDiv_right'); + if (removeNode)crop_imageDiv.removeChild(removeNode); + var removeNode = document.getElementById('cropDiv_bottom'); + if (removeNode)crop_imageDiv.removeChild(removeNode); + var removeNode = document.getElementById('cropDiv_dotted'); + if (removeNode)crop_imageDiv.removeChild(removeNode); + + crop_delpreview(); } \ No newline at end of file diff --git a/htdocs/libraries/image-editor/plugins/filter/filter_image.js b/htdocs/libraries/image-editor/plugins/filter/filter_image.js index 8ed04d8606b7..efb28b326e96 100644 --- a/htdocs/libraries/image-editor/plugins/filter/filter_image.js +++ b/htdocs/libraries/image-editor/plugins/filter/filter_image.js @@ -1,167 +1,167 @@ -function selFilter(value,panelId,e){ - var div_arg1 = xoopsGetElementById('darg1'); - var div_arg2 = xoopsGetElementById('darg2'); - var div_arg3 = xoopsGetElementById('darg3'); - - var filter_desc = xoopsGetElementById('filterdesc'); - - var targ1 = xoopsGetElementById('targ1'); - var targ2 = xoopsGetElementById('targ2'); - var targ3 = xoopsGetElementById('targ3'); - - var arg1 = xoopsGetElementById('arg1'); - var arg2 = xoopsGetElementById('arg2'); - var arg3 = xoopsGetElementById('arg3'); - - var larg1 = xoopsGetElementById('larg1'); - var larg2 = xoopsGetElementById('larg2'); - var larg3 = xoopsGetElementById('larg3'); - - filter_desc.style.display = 'none'; - filter_desc.innerHTML = ''; - for (i=1;i<4;i++){ - eval('div_arg'+i).style.display = 'none'; - eval('targ'+i).innerHTML = ''; - eval('larg'+i).innerHTML = ''; - eval('arg'+i).value = ''; - } - - if (value != ''){ - for (i=0;i<=Filters.length-1;i++){ - if (Filters[i].value == value){ - var filter = Filters[i]; - } - } - - filter_desc.style.display = 'block'; - filter_desc.innerHTML = ''+filter['descr']+''; - - if (filter['args'].length > 0){ - for (i=0;i<=filter['args'].length-1;i++){ - var x = i+1; - eval('div_arg'+x).style.display = 'block'; - eval('targ'+x).innerHTML = filter['args'][i]['title']; - eval('larg'+x).innerHTML = ''+filter['args'][i]['descr']+''; - eval('arg'+x).value = filter['args'][i]['value']; - } - } - } - var div = xoopsGetElementById('xpPaneTopBar'+panelId); - updatePaneHeight(e,div); -} - -var filterScriptAjaxObjects = new Array(); - -function filter_preview(buttonObj){ - filter_startProgressBar(); - buttonObj.style.visibility='hidden'; - var ajaxIndex = filterScriptAjaxObjects.length; - filterScriptAjaxObjects[ajaxIndex] = new sack(); - var url = filter_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value - + '&image_url=' + xoopsGetElementById('fimage_url').value - + '&filter=' + xoopsGetElementById('filter').value - + '&arg1=' + xoopsGetElementById('arg1').value - + '&arg2=' + xoopsGetElementById('arg2').value - + '&arg3=' + xoopsGetElementById('arg3').value; - - filterScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - filterScriptAjaxObjects[ajaxIndex].onCompletion = function(){ filterCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found - filterScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -function filter_save(buttonObj) -{ - filter_startProgressBar(); - buttonObj.style.visibility='hidden'; - var ajaxIndex = filterScriptAjaxObjects.length; - filterScriptAjaxObjects[ajaxIndex] = new sack(); - var url = filter_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value - + '&image_url=' + xoopsGetElementById('fimage_url').value - + '&filter=' + xoopsGetElementById('filter').value - + '&arg1=' + xoopsGetElementById('arg1').value - + '&arg2=' + xoopsGetElementById('arg2').value - + '&arg3=' + xoopsGetElementById('arg3').value - + '&save=1'; - - filterScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - filterScriptAjaxObjects[ajaxIndex].onCompletion = function(){ filterCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found - filterScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -function filter_delpreview(){ - var ajaxIndex = filterScriptAjaxObjects.length; - filterScriptAjaxObjects[ajaxIndex] = new sack(); - var url = filter_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value - + '&image_url=' + xoopsGetElementById('fimage_url').value - + '&delprev=1'; - - filterScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - filterScriptAjaxObjects[ajaxIndex].onCompletion = function(){ - eval(filterScriptAjaxObjects[ajaxIndex].response) - filterScriptAjaxObjects[ajaxIndex] = false; - filter_hideProgressBar(); - }; // Specify function that will be executed after file has been found - filterScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -function filterCompleted(ajaxIndex,buttonObj) -{ - buttonObj.style.visibility=''; - eval(filterScriptAjaxObjects[ajaxIndex].response) - filterScriptAjaxObjects[ajaxIndex] = false; - filter_hideProgressBar(); -} - -function filter_progressBar() -{ - var div = document.getElementById('progressBar'); - - var subDiv = document.createElement('DIV'); - div.appendChild(subDiv); - subDiv.style.position = 'absolute'; - subDiv.className='progressBar_parentBox'; - subDiv.style.left = '0px'; - var progressBarSquare = document.createElement('DIV'); - progressBarSquare.className='progressBar_square'; - subDiv.appendChild(progressBarSquare); - var progressBarSquare = document.createElement('DIV'); - progressBarSquare.className='progressBar_square'; - subDiv.appendChild(progressBarSquare); - var progressBarSquare = document.createElement('DIV'); - progressBarSquare.className='progressBar_square'; - subDiv.appendChild(progressBarSquare); - filter_progressBarMove(); - filter_hideProgressBar(); - - var menu = xoopsGetElementById('dhtmlgoodies_xpPane'); - top = (window.innerHeight/2)-(div.clientHeight/2); - left = ((window.innerWidth/2)+(menu.clientWidth)/2)-(div.clientWidth/2); - - div.style.top = top+'px'; - div.style.left = left+'px'; -} - -function filter_hideProgressBar() -{ - document.getElementById('progressBar').style.visibility = 'hidden'; - -} - -function filter_startProgressBar() -{ - var div = document.getElementById('progressBar').getElementsByTagName('DIV')[0]; - div.style.left = '0px'; - document.getElementById('progressBar').style.visibility = 'visible'; -} - -function filter_progressBarMove() -{ - var div = document.getElementById('progressBar').getElementsByTagName('DIV')[0]; - var left = div.style.left.replace('px','')/1; - left = left + 1; - if(left > div.parentNode.clientWidth)left = 0 - div.clientWidth; - div.style.left = left + 'px'; - - setTimeout('filter_progressBarMove()',20); - +function selFilter(value,panelId,e){ + var div_arg1 = xoopsGetElementById('darg1'); + var div_arg2 = xoopsGetElementById('darg2'); + var div_arg3 = xoopsGetElementById('darg3'); + + var filter_desc = xoopsGetElementById('filterdesc'); + + var targ1 = xoopsGetElementById('targ1'); + var targ2 = xoopsGetElementById('targ2'); + var targ3 = xoopsGetElementById('targ3'); + + var arg1 = xoopsGetElementById('arg1'); + var arg2 = xoopsGetElementById('arg2'); + var arg3 = xoopsGetElementById('arg3'); + + var larg1 = xoopsGetElementById('larg1'); + var larg2 = xoopsGetElementById('larg2'); + var larg3 = xoopsGetElementById('larg3'); + + filter_desc.style.display = 'none'; + filter_desc.innerHTML = ''; + for (i=1;i<4;i++){ + eval('div_arg'+i).style.display = 'none'; + eval('targ'+i).innerHTML = ''; + eval('larg'+i).innerHTML = ''; + eval('arg'+i).value = ''; + } + + if (value != ''){ + for (i=0;i<=Filters.length-1;i++){ + if (Filters[i].value == value){ + var filter = Filters[i]; + } + } + + filter_desc.style.display = 'block'; + filter_desc.innerHTML = ''+filter['descr']+''; + + if (filter['args'].length > 0){ + for (i=0;i<=filter['args'].length-1;i++){ + var x = i+1; + eval('div_arg'+x).style.display = 'block'; + eval('targ'+x).innerHTML = filter['args'][i]['title']; + eval('larg'+x).innerHTML = ''+filter['args'][i]['descr']+''; + eval('arg'+x).value = filter['args'][i]['value']; + } + } + } + var div = xoopsGetElementById('xpPaneTopBar'+panelId); + updatePaneHeight(e,div); +} + +var filterScriptAjaxObjects = new Array(); + +function filter_preview(buttonObj){ + filter_startProgressBar(); + buttonObj.style.visibility='hidden'; + var ajaxIndex = filterScriptAjaxObjects.length; + filterScriptAjaxObjects[ajaxIndex] = new sack(); + var url = filter_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value + + '&image_url=' + xoopsGetElementById('fimage_url').value + + '&filter=' + xoopsGetElementById('filter').value + + '&arg1=' + xoopsGetElementById('arg1').value + + '&arg2=' + xoopsGetElementById('arg2').value + + '&arg3=' + xoopsGetElementById('arg3').value; + + filterScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + filterScriptAjaxObjects[ajaxIndex].onCompletion = function(){ filterCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found + filterScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +function filter_save(buttonObj) +{ + filter_startProgressBar(); + buttonObj.style.visibility='hidden'; + var ajaxIndex = filterScriptAjaxObjects.length; + filterScriptAjaxObjects[ajaxIndex] = new sack(); + var url = filter_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value + + '&image_url=' + xoopsGetElementById('fimage_url').value + + '&filter=' + xoopsGetElementById('filter').value + + '&arg1=' + xoopsGetElementById('arg1').value + + '&arg2=' + xoopsGetElementById('arg2').value + + '&arg3=' + xoopsGetElementById('arg3').value + + '&save=1'; + + filterScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + filterScriptAjaxObjects[ajaxIndex].onCompletion = function(){ filterCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found + filterScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +function filter_delpreview(){ + var ajaxIndex = filterScriptAjaxObjects.length; + filterScriptAjaxObjects[ajaxIndex] = new sack(); + var url = filter_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value + + '&image_url=' + xoopsGetElementById('fimage_url').value + + '&delprev=1'; + + filterScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + filterScriptAjaxObjects[ajaxIndex].onCompletion = function(){ + eval(filterScriptAjaxObjects[ajaxIndex].response); + filterScriptAjaxObjects[ajaxIndex] = false; + filter_hideProgressBar(); + }; // Specify function that will be executed after file has been found + filterScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +function filterCompleted(ajaxIndex,buttonObj) +{ + buttonObj.style.visibility=''; + eval(filterScriptAjaxObjects[ajaxIndex].response) + filterScriptAjaxObjects[ajaxIndex] = false; + filter_hideProgressBar(); +} + +function filter_progressBar() +{ + var div = document.getElementById('progressBar'); + + var subDiv = document.createElement('DIV'); + div.appendChild(subDiv); + subDiv.style.position = 'absolute'; + subDiv.className='progressBar_parentBox'; + subDiv.style.left = '0px'; + var progressBarSquare = document.createElement('DIV'); + progressBarSquare.className='progressBar_square'; + subDiv.appendChild(progressBarSquare); + var progressBarSquare = document.createElement('DIV'); + progressBarSquare.className='progressBar_square'; + subDiv.appendChild(progressBarSquare); + var progressBarSquare = document.createElement('DIV'); + progressBarSquare.className='progressBar_square'; + subDiv.appendChild(progressBarSquare); + filter_progressBarMove(); + filter_hideProgressBar(); + + var menu = xoopsGetElementById('dhtmlgoodies_xpPane'); + top = (window.innerHeight/2)-(div.clientHeight/2); + left = ((window.innerWidth/2)+(menu.clientWidth)/2)-(div.clientWidth/2); + + div.style.top = top+'px'; + div.style.left = left+'px'; +} + +function filter_hideProgressBar() +{ + document.getElementById('progressBar').style.visibility = 'hidden'; + +} + +function filter_startProgressBar() +{ + var div = document.getElementById('progressBar').getElementsByTagName('DIV')[0]; + div.style.left = '0px'; + document.getElementById('progressBar').style.visibility = 'visible'; +} + +function filter_progressBarMove() +{ + var div = document.getElementById('progressBar').getElementsByTagName('DIV')[0]; + var left = div.style.left.replace('px','')/1; + left = left + 1; + if(left > div.parentNode.clientWidth)left = 0 - div.clientWidth; + div.style.left = left + 'px'; + + setTimeout('filter_progressBarMove()',20); + } \ No newline at end of file diff --git a/htdocs/libraries/image-editor/plugins/resize/resize_image.js b/htdocs/libraries/image-editor/plugins/resize/resize_image.js index 2e266784a39d..6e0b536fefc8 100644 --- a/htdocs/libraries/image-editor/plugins/resize/resize_image.js +++ b/htdocs/libraries/image-editor/plugins/resize/resize_image.js @@ -1,111 +1,111 @@ -var resizeScriptAjaxObjects = new Array(); - -function resize_preview(buttonObj){ - resize_startProgressBar(); - buttonObj.style.visibility='hidden'; - var ajaxIndex = resizeScriptAjaxObjects.length; - resizeScriptAjaxObjects[ajaxIndex] = new sack(); - var url = resize_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value - + '&image_url=' + xoopsGetElementById('fimage_url').value - + '&width=' + xoopsGetElementById('resize_width').value - + '&height=' + xoopsGetElementById('resize_height').value; - - resizeScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - resizeScriptAjaxObjects[ajaxIndex].onCompletion = function(){ resizeCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found - resizeScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -function resize_save(buttonObj) -{ - resize_startProgressBar(); - buttonObj.style.visibility='hidden'; - var ajaxIndex = resizeScriptAjaxObjects.length; - resizeScriptAjaxObjects[ajaxIndex] = new sack(); - var url = resize_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value - + '&image_url=' + xoopsGetElementById('fimage_url').value - + '&width=' + xoopsGetElementById('resize_width').value - + '&height=' + xoopsGetElementById('resize_height').value - + '&save=1'; - - resizeScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - resizeScriptAjaxObjects[ajaxIndex].onCompletion = function(){ resizeCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found - resizeScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -function resize_delpreview(){ - var ajaxIndex = resizeScriptAjaxObjects.length; - resizeScriptAjaxObjects[ajaxIndex] = new sack(); - var url = resize_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value - + '&image_url=' + xoopsGetElementById('fimage_url').value - + '&delprev=1'; - - resizeScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get - resizeScriptAjaxObjects[ajaxIndex].onCompletion = function(){ - eval(resizeScriptAjaxObjects[ajaxIndex].response) - resizeScriptAjaxObjects[ajaxIndex] = false; - resize_hideProgressBar(); - }; // Specify function that will be executed after file has been found - resizeScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function -} - -function resizeCompleted(ajaxIndex,buttonObj) -{ - buttonObj.style.visibility=''; - eval(resizeScriptAjaxObjects[ajaxIndex].response) - resizeScriptAjaxObjects[ajaxIndex] = false; - resize_hideProgressBar(); -} - -function resize_progressBar() -{ - var div = document.getElementById('progressBar'); - - var subDiv = document.createElement('DIV'); - div.appendChild(subDiv); - subDiv.style.position = 'absolute'; - subDiv.className='progressBar_parentBox'; - subDiv.style.left = '0px'; - var progressBarSquare = document.createElement('DIV'); - progressBarSquare.className='progressBar_square'; - subDiv.appendChild(progressBarSquare); - var progressBarSquare = document.createElement('DIV'); - progressBarSquare.className='progressBar_square'; - subDiv.appendChild(progressBarSquare); - var progressBarSquare = document.createElement('DIV'); - progressBarSquare.className='progressBar_square'; - subDiv.appendChild(progressBarSquare); - resize_progressBarMove(); - resize_hideProgressBar(); - - var menu = xoopsGetElementById('dhtmlgoodies_xpPane'); - top = (window.innerHeight/2)-(div.clientHeight/2); - left = ((window.innerWidth/2)+(menu.clientWidth)/2)-(div.clientWidth/2); - - div.style.top = top+'px'; - div.style.left = left+'px'; -} - -function resize_hideProgressBar() -{ - document.getElementById('progressBar').style.visibility = 'hidden'; - -} - -function resize_startProgressBar() -{ - var div = document.getElementById('progressBar').getElementsByTagName('DIV')[0]; - div.style.left = '0px'; - document.getElementById('progressBar').style.visibility = 'visible'; -} - -function resize_progressBarMove() -{ - var div = document.getElementById('progressBar').getElementsByTagName('DIV')[0]; - var left = div.style.left.replace('px','')/1; - left = left + 1; - if(left > div.parentNode.clientWidth)left = 0 - div.clientWidth; - div.style.left = left + 'px'; - - setTimeout('resize_progressBarMove()',20); - +var resizeScriptAjaxObjects = new Array(); + +function resize_preview(buttonObj){ + resize_startProgressBar(); + buttonObj.style.visibility='hidden'; + var ajaxIndex = resizeScriptAjaxObjects.length; + resizeScriptAjaxObjects[ajaxIndex] = new sack(); + var url = resize_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value + + '&image_url=' + xoopsGetElementById('fimage_url').value + + '&width=' + xoopsGetElementById('resize_width').value + + '&height=' + xoopsGetElementById('resize_height').value; + + resizeScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + resizeScriptAjaxObjects[ajaxIndex].onCompletion = function(){ resizeCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found + resizeScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +function resize_save(buttonObj) +{ + resize_startProgressBar(); + buttonObj.style.visibility='hidden'; + var ajaxIndex = resizeScriptAjaxObjects.length; + resizeScriptAjaxObjects[ajaxIndex] = new sack(); + var url = resize_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value + + '&image_url=' + xoopsGetElementById('fimage_url').value + + '&width=' + xoopsGetElementById('resize_width').value + + '&height=' + xoopsGetElementById('resize_height').value + + '&save=1'; + + resizeScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + resizeScriptAjaxObjects[ajaxIndex].onCompletion = function(){ resizeCompleted(ajaxIndex,buttonObj); }; // Specify function that will be executed after file has been found + resizeScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +function resize_delpreview(){ + var ajaxIndex = resizeScriptAjaxObjects.length; + resizeScriptAjaxObjects[ajaxIndex] = new sack(); + var url = resize_script_server_file + '?image_path=' + xoopsGetElementById('fimage_path').value + + '&image_url=' + xoopsGetElementById('fimage_url').value + + '&delprev=1'; + + resizeScriptAjaxObjects[ajaxIndex].requestFile = url; // Specifying which file to get + resizeScriptAjaxObjects[ajaxIndex].onCompletion = function(){ + eval(resizeScriptAjaxObjects[ajaxIndex].response) + resizeScriptAjaxObjects[ajaxIndex] = false; + resize_hideProgressBar(); + }; // Specify function that will be executed after file has been found + resizeScriptAjaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function +} + +function resizeCompleted(ajaxIndex,buttonObj) +{ + buttonObj.style.visibility=''; + eval(resizeScriptAjaxObjects[ajaxIndex].response); + resizeScriptAjaxObjects[ajaxIndex] = false; + resize_hideProgressBar(); +} + +function resize_progressBar() +{ + var div = document.getElementById('progressBar'); + + var subDiv = document.createElement('DIV'); + div.appendChild(subDiv); + subDiv.style.position = 'absolute'; + subDiv.className='progressBar_parentBox'; + subDiv.style.left = '0px'; + var progressBarSquare = document.createElement('DIV'); + progressBarSquare.className='progressBar_square'; + subDiv.appendChild(progressBarSquare); + var progressBarSquare = document.createElement('DIV'); + progressBarSquare.className='progressBar_square'; + subDiv.appendChild(progressBarSquare); + var progressBarSquare = document.createElement('DIV'); + progressBarSquare.className='progressBar_square'; + subDiv.appendChild(progressBarSquare); + resize_progressBarMove(); + resize_hideProgressBar(); + + var menu = xoopsGetElementById('dhtmlgoodies_xpPane'); + top = (window.innerHeight/2)-(div.clientHeight/2); + left = ((window.innerWidth/2)+(menu.clientWidth)/2)-(div.clientWidth/2); + + div.style.top = top+'px'; + div.style.left = left+'px'; +} + +function resize_hideProgressBar() +{ + document.getElementById('progressBar').style.visibility = 'hidden'; + +} + +function resize_startProgressBar() +{ + var div = document.getElementById('progressBar').getElementsByTagName('DIV')[0]; + div.style.left = '0px'; + document.getElementById('progressBar').style.visibility = 'visible'; +} + +function resize_progressBarMove() +{ + var div = document.getElementById('progressBar').getElementsByTagName('DIV')[0]; + var left = div.style.left.replace('px','')/1; + left = left + 1; + if(left > div.parentNode.clientWidth)left = 0 - div.clientWidth; + div.style.left = left + 'px'; + + setTimeout('resize_progressBarMove()',20); + } \ No newline at end of file From 52a585ea9306a11ab9ecd09d22f60238c4cb67b6 Mon Sep 17 00:00:00 2001 From: Steve Kenow Date: Sun, 20 Aug 2023 07:46:54 -0500 Subject: [PATCH 9/9] One more instance of a missing argument for strncnp --- htdocs/libraries/image-editor/image-edit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/libraries/image-editor/image-edit.php b/htdocs/libraries/image-editor/image-edit.php index 8a6ee0b3f3be..79634e1213ec 100644 --- a/htdocs/libraries/image-editor/image-edit.php +++ b/htdocs/libraries/image-editor/image-edit.php @@ -75,7 +75,7 @@ if (!empty($op) && $op == 'cancel') { /* make sure the file is in the temp folder and prevent arbitrary deletes of any file */ $valid_path = ICMS_IMANAGER_FOLDER_PATH . '/temp'; - if (!empty($image_path) && strncmp(realpath($image_path), strlen($valid_path)) == 0) { + if (!empty($image_path) && strncmp(realpath($image_path), $image_path, strlen($valid_path)) == 0) { $image_path = realpath($image_path); } else { $image_path = NULL;