1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-21 05:02:02 +02:00

Old PHPThumb class removed. (Replaced by Intervention)

This commit is contained in:
Cameron 2020-12-06 11:33:09 -08:00
parent d564c5399c
commit b4596dda47
13 changed files with 57 additions and 3135 deletions

View File

@ -98,7 +98,7 @@ if(vartrue($_GET['action']) == 'nav' && e_AJAX_REQUEST) //XXX Doesn't work corre
}
require_once(e_HANDLER.'phpthumb/ThumbLib.inc.php'); // For resizing on import.
$e_sub_cat = 'image';
@ -268,7 +268,7 @@ class media_cat_ui extends e_admin_ui
if(!count($this->fields['media_cat_owner']['writeParms']))
{
e107::getMessage()->addInfo("Category creation not available.");
return;
return null;
}
return $this->getUI()->getCreate();
@ -471,32 +471,13 @@ class media_form_ui extends e_admin_form_ui
* @param int
* @param int
*/
public function resizeImage($oldpath,$img_import_w,$img_import_h)
public function resizeImage($oldpath,$w,$h)
{
$mes = e107::getMessage();
try
if(e107::getMedia()->resizeImage($oldpath, $oldpath. ['w'=>$w, 'h'=>$h]))
{
$thumb = PhpThumbFactory::create($oldpath);
$thumb->setOptions(array('correctPermissions' => true));
return true;
}
catch (Exception $e)
{
$mes->addError($e->getMessage());
return FALSE;
// return $this;
}
/* if($WM) // TODO Add watermark prefs for alpha and position.
{
$thumb->resize($img_import_w,$img_import_h)->addWatermark($watermark, 'rightBottom', 30, 0, 0)->save($oldpath);
}
else*/
{
if($thumb->resize($img_import_w,$img_import_h)->save($oldpath))
{
return TRUE;
}
}
}
@ -530,7 +511,7 @@ class media_form_ui extends e_admin_form_ui
$mes->addSuccess(LAN_IMA_004.": ".basename($path));
$mes->addSuccess(print_a($info,true));
$dim = intval($info['img-width'])." x ".intval($info['img-height']);
$sql2->db_Update("core_media","media_dimensions = '".$dim."', media_size = '".intval($info['fsize'])."' WHERE media_id = ".intval($row['media_id'])."");
$sql2->update("core_media","media_dimensions = '".$dim."', media_size = '".intval($info['fsize'])."' WHERE media_id = ".intval($row['media_id'])."");
}
else
{
@ -3258,12 +3239,7 @@ class media_admin_ui extends e_admin_ui
<div class='buttons-bar center form-inline'>
".IMALAN_123." ".$frm->selectbox('batch_category',$this->cats, $tp->filter($_POST['batch_category']));
// $waterMarkPath = e_THEME.e107::getPref('sitetheme')."/images/watermark.png"; // Now performed site-wide dynamically.
// if(is_readable($waterMarkPath))
{
// $text .= $frm->checkbox_label("Add Watermark", 'batch_import_watermark',1);
}
$text .= "
</div>
@ -3387,18 +3363,7 @@ class media_admin_ui extends e_admin_ui
list($img_import_w,$img_import_h) = explode("x",e107::getPref('img_import_resize'));
if(vartrue($_POST['batch_import_watermark']))
{
$WM = TRUE;
$watermarkPath = e_THEME.e107::getPref('sitetheme')."/images/watermark.png";
$watermark = PhpThumbFactory::create($watermarkPath);
}
else
{
$WM = FALSE;
}
// list($img_import_w,$img_import_h) = explode("x",e107::getPref('img_import_resize'));
// Disable resize-on-import and watermark for now.
$img_import_w = 2816;

View File

@ -735,7 +735,7 @@ class e107
* Note: will always return false if called before prepare_request() method!
*
* @param string $key
* @return boolean
* @return boolean|array
*/
public static function getE107($key = null)
{
@ -1024,7 +1024,7 @@ class e107
* @param string $name core|core_backup|emote|menu|search|notify
* @param bool $load
* @param bool $refresh
* @return e_core_pref
* @return e_core_pref|e_plugin_pref
*/
public static function getConfig($name = 'core', $load = true, $refresh=false)
{
@ -1295,7 +1295,7 @@ class e107
/**
* Retrieve text parser singleton object
*
* @return e_parse
* @return e_parse|array
*/
public static function getParser()
{
@ -1475,9 +1475,12 @@ class e107
* Retrieves PhpThumbFactory object
*
* @param $src
* @deprecated - use Intervention class instead @see
* @example use Intervention\Image\ImageManagerStatic as Image;
* @example $img = Image::make($this->_src_path);.
* @return bool|GdThumb
*/
public static function getThumb($src)
/*public static function getThumb($src)
{
require_once(e_HANDLER.'phpthumb/ThumbLib.inc.php');
try
@ -1489,7 +1492,7 @@ class e107
return false;
}
}
}*/
/**

View File

@ -305,7 +305,7 @@ class e_thumbnail
/*
protected function sendImageOld() // for reference. - can be removed at a later date.
{
@ -333,8 +333,9 @@ class e_thumbnail
$this->sendCachedImage($cache_filename,$thumbnfo);
require_once(e_HANDLER.'phpthumb/ThumbLib.inc.php');
if(!$thumb = e107::getThumb($this->_src_path))
if(!$thumb = PhpThumbFactory::create($this->_src_path))
{
if(getperms('0'))
{
@ -384,17 +385,17 @@ class e_thumbnail
}
/* if($this->_debug === true)
if($this->_debug === true)
{
// echo "time: ".round((microtime(true) - $start),4);
var_dump($thumb);
return false;
}*/
}
// Watermark Option - See admin->MediaManager->prefs for details.
if(($this->_watermark['activate'] < $options['w']
/ if(($this->_watermark['activate'] < $options['w']
|| $this->_watermark['activate'] < $options['aw']
|| $this->_watermark['activate'] < $options['h']
|| $this->_watermark['activate'] < $options['ah']
@ -424,6 +425,7 @@ class e_thumbnail
return $this;
}
*/
/**
* When caching is enabled, send the cached image with headers and then exit the script.

View File

@ -14,6 +14,8 @@
if (!defined('e107_INIT')) { exit; }
//TODO LANS
use Intervention\Image\ImageManagerStatic as Intervension;
class e_media
{
protected $imagelist = array();
@ -363,7 +365,7 @@ class e_media
$sql = e107::getDb();
$sql->select('core_media_cat',"media_cat_category", "media_cat_owner = '".$owner."' ");
while($row = $sql->db_Fetch())
while($row = $sql->fetch())
{
$categories[] = "'".$row['media_cat_category']."'";
}
@ -629,7 +631,7 @@ class e_media
$sql->gen("SELECT * FROM `#core_media` WHERE media_category = '_common' OR media_category = '".$cat."' ORDER BY media_category,media_datestamp DESC ");
$text .= "<div style='font-size:120%;font-weight:bold;text-align:right;margin-right:10px'><a title='".LAN_CLOSE."' style='text-decoration:none;color:white' href='#' onclick=\"expandit('{$formid}'); return false;\" >x</a></div>";
while ($row = $sql->db_Fetch())
while ($row = $sql->fetch())
{
$image = $row['media_url'];
$diz = $row['media_name']." : ". $row['media_dimensions'];
@ -666,9 +668,8 @@ class e_media
$action = varset($option['action'],'nav');
$url = e_ADMIN_ABS."image.php?mode=main&amp;action=".$action."&amp;iframe=1".$cat."&amp;from=0";
return $url;
return e_ADMIN_ABS."image.php?mode=main&amp;action=".$action."&amp;iframe=1".$cat."&amp;from=0";
}
@ -1154,7 +1155,7 @@ class e_media
$text = str_replace('[x]',$dir,IMALAN_112);
$mes->add($text, E_MESSAGE_ERROR);
return FALSE;
};
}
}
return $dir;
}
@ -1260,7 +1261,7 @@ class e_media
return FALSE;
}
$info = e107::getFile()->get_file_info($path,true);
$info = e107::getFile()->get_file_info($path);
@ -1363,7 +1364,7 @@ class e_media
$this->log("Couldn't move file from ".realpath($oldpath)." to ".e_MEDIA.$newpath);
$mes->add("Couldn't move file from ".$oldpath." to ".$newpath, E_MESSAGE_ERROR);
return false;
};
}
if($category === '_icon') // convert to _icon_16, _icon_32 etc.
{
@ -1472,13 +1473,11 @@ class e_media
// e-dialog-save
$style = varset($data['style'],'');
$class = varset($data['class'],'');
$style = varset($data['style']);
$class = varset($data['class']);
$dataPreview = !empty($data['previewHtml']) ? base64_encode($data['previewHtml']) : '';
$linkTag = "<a data-toggle='context' class='e-media-select ".$select." ".$class."' ".$close." data-id='".$data['id']."' data-width='".$data['width']."' data-height='".$data['height']."' data-src='".$data['previewUrl']."' data-type='".$data['type']."' data-bbcode='".$data['bbcode']."' data-target='".$data['tagid']."' data-path='".$data['saveValue']."' data-preview='".$data['previewUrl']."' data-preview-html='".$dataPreview."' title=\"".$data['title']."\" style='".$style."' href='#' >";
return $linkTag;
return "<a data-toggle='context' class='e-media-select ".$select." ".$class."' ".$close." data-id='".$data['id']."' data-width='".$data['width']."' data-height='".$data['height']."' data-src='".$data['previewUrl']."' data-type='".$data['type']."' data-bbcode='".$data['bbcode']."' data-target='".$data['tagid']."' data-path='".$data['saveValue']."' data-preview='".$data['previewUrl']."' data-preview-html='".$dataPreview."' title=\"".$data['title']."\" style='".$style."' href='#' >";
}
@ -1939,19 +1938,21 @@ class e_media
return $destFilePath;
}
require_once(e_HANDLER.'phpthumb/ThumbLib.inc.php');
try
{
$thumb = PhpThumbFactory::create($src);
$thumb->setOptions(array('correctPermissions' => true, 'resizeUp' => false, 'jpegQuality' => $quality));
$thumb->resize($maxWidth, $maxHeight);
$thumb->save($destFilePath);
$thumb = Intervension::make($src);
$thumb->resize(vartrue($maxWidth, null), vartrue($maxHeight, null), function ($constraint)
{
$constraint->aspectRatio();
$constraint->upsize();
});
$thumb->save($destFilePath, $quality);
return $destFilePath;
}
catch (Exception $e)
{
$error = array('thumbnailer'=> $e->getMessage(), 'src'=>$src, 'dest'=>$dest, 'savePath'=>$destFilePath, 'backtrace'=>'e_media::resizeImage');;
$error = array('thumbnailer'=> $e->getMessage(), 'src'=>$src, 'dest'=>$dest, 'savePath'=>$destFilePath, 'backtrace'=>'e_media::resizeImage');
e107::getMessage()->addDebug(print_a($error,true));
e107::getLog()->add("RESIZE ERROR",$error,E_LOG_INFORMATIVE,'RESIZE');
return false;
@ -1959,6 +1960,7 @@ class e_media
}
@ -2252,10 +2254,19 @@ class e_media
if(!empty($_REQUEST['resize']))
{
$thumb = e107::getThumb($filePath);
$thumb = Intervension::make($filePath);
$w = (int) $_REQUEST['resize']['w'];
$h = (int) $_REQUEST['resize']['h'];
$thumb->adaptiveResize($w,$h)->save($filePath);
$thumb->resize(vartrue($w, null), vartrue($h, null), function ($constraint)
{
$constraint->aspectRatio();
$constraint->upsize();
});
$thumb->save($filePath);
}
if(!empty($_REQUEST['rename']))

File diff suppressed because it is too large Load Diff

View File

@ -1,247 +0,0 @@
<?php
/**
* PhpThumb Library Definition File
*
* This file contains the definitions for the PhpThumb class.
*
* PHP Version 5 with GD 2.0+
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
* Copyright (c) 2009, Ian Selby/Gen X Design
*
* Author(s): Ian Selby <ian@gen-x-design.com>
*
* Licensed under the MIT License
* Redistributions of files must retain the above copyright notice.
*
* @author Ian Selby <ian@gen-x-design.com>
* @copyright Copyright (c) 2009 Gen X Design
* @link http://phpthumb.gxdlabs.com
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @version 3.0
* @package PhpThumb
* @filesource
*/
/**
* PhpThumb Object
*
* This singleton object is essentially a function library that helps with core validation
* and loading of the core classes and plugins. There isn't really any need to access it directly,
* unless you're developing a plugin and need to take advantage of any of the functionality contained
* within.
*
* If you're not familiar with singleton patterns, here's how you get an instance of this class (since you
* can't create one via the new keyword):
* <code>$pt = PhpThumb::getInstance();</code>
*
* It's that simple! Outside of that, there's no need to modify anything within this class, unless you're doing
* some crazy customization... then knock yourself out! :)
*
* @package PhpThumb
* @subpackage Core
*/
class PhpThumb
{
/**
* Instance of self
*
* @var object PhpThumb
*/
protected static $_instance;
/**
* The plugin registry
*
* This is where all plugins to be loaded are stored. Data about the plugin is
* provided, and currently consists of:
* - loaded: true/false
* - implementation: gd/imagick/both
*
* @var array
*/
protected $_registry;
/**
* What implementations are available
*
* This stores what implementations are available based on the loaded
* extensions in PHP, NOT whether or not the class files are present.
*
* @var array
*/
protected $_implementations;
/**
* Returns an instance of self
*
* This is the usual singleton function that returns / instantiates the object
*
* @return PhpThumb
*/
public static function getInstance ()
{
if(!(self::$_instance instanceof self))
{
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Class constructor
*
* Initializes all the variables, and does some preliminary validation / checking of stuff
*
*/
private function __construct ()
{
$this->_registry = array();
$this->_implementations = array('gd' => false, 'imagick' => false);
$this->getImplementations();
}
/**
* Finds out what implementations are available
*
* This function loops over $this->_implementations and validates that the required extensions are loaded.
*
* I had planned on attempting to load them dynamically via dl(), but that would provide more overhead than I
* was comfortable with (and would probably fail 99% of the time anyway)
*
*/
private function getImplementations ()
{
foreach($this->_implementations as $extension => $loaded)
{
if($loaded)
{
continue;
}
if(extension_loaded($extension))
{
$this->_implementations[$extension] = true;
}
}
}
/**
* Returns whether or not $implementation is valid (available)
*
* If 'all' is passed, true is only returned if ALL implementations are available.
*
* You can also pass 'n/a', which always returns true
*
* @return bool
* @param string $implementation
*/
public function isValidImplementation ($implementation)
{
if ($implementation == 'n/a')
{
return true;
}
if ($implementation == 'all')
{
foreach ($this->_implementations as $imp => $value)
{
if ($value == false)
{
return false;
}
}
return true;
}
if (array_key_exists($implementation, $this->_implementations))
{
return $this->_implementations[$implementation];
}
return false;
}
/**
* Registers a plugin in the registry
*
* Adds a plugin to the registry if it isn't already loaded, and if the provided
* implementation is valid. Note that you can pass the following special keywords
* for implementation:
* - all - Requires that all implementations be available
* - n/a - Doesn't require any implementation
*
* When a plugin is added to the registry, it's added as a key on $this->_registry with the value
* being an array containing the following keys:
* - loaded - whether or not the plugin has been "loaded" into the core class
* - implementation - what implementation this plugin is valid for
*
* @return bool
* @param string $pluginName
* @param string $implementation
*/
public function registerPlugin ($pluginName, $implementation)
{
if (!array_key_exists($pluginName, $this->_registry) && $this->isValidImplementation($implementation))
{
$this->_registry[$pluginName] = array('loaded' => false, 'implementation' => $implementation);
return true;
}
return false;
}
/**
* Loads all the plugins in $pluginPath
*
* All this function does is include all files inside the $pluginPath directory. The plugins themselves
* will not be added to the registry unless you've properly added the code to do so inside your plugin file.
*
* @param string $pluginPath
*/
public function loadPlugins ($pluginPath)
{
// strip the trailing slash if present
if (substr($pluginPath, strlen($pluginPath) - 1, 1) == '/')
{
$pluginPath = substr($pluginPath, 0, strlen($pluginPath) - 1);
}
if ($handle = opendir($pluginPath))
{
while (false !== ($file = readdir($handle)))
{
if ($file == '.' || $file == '..' || $file == '.svn')
{
continue;
}
include_once($pluginPath . '/' . $file);
}
}
}
/**
* Returns the plugin registry for the supplied implementation
*
* @return array
* @param string $implementation
*/
public function getPluginRegistry ($implementation)
{
$returnArray = array();
foreach ($this->_registry as $plugin => $meta)
{
if ($meta['implementation'] == 'n/a' || $meta['implementation'] == $implementation)
{
$returnArray[$plugin] = $meta;
}
}
return $returnArray;
}
}

View File

@ -1,13 +0,0 @@
# PHP Thumb
PHP Thumb is a light-weight image manipulation library
aimed at thumbnail generation. It features the ability to
resize by width, height, and percentage, create custom crops,
or square crops from the center, and rotate the image. You can
also easily add custom functionality to the library through plugins.
It also features the ability to perform multiple manipulations per
instance (also known as chaining), without the need to save and
re-initialize the class with every manipulation.
More information and documentation is available at the project's
homepage: [http://phpthumb.gxdlabs.com](http://phpthumb.gxdlabs.com)

View File

@ -1,323 +0,0 @@
<?php
/**
* PhpThumb Base Class Definition File
*
* This file contains the definition for the ThumbBase object
*
* PHP Version 5 with GD 2.0+
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
* Copyright (c) 2009, Ian Selby/Gen X Design
*
* Author(s): Ian Selby <ian@gen-x-design.com>
*
* Licensed under the MIT License
* Redistributions of files must retain the above copyright notice.
*
* @author Ian Selby <ian@gen-x-design.com>
* @copyright Copyright (c) 2009 Gen X Design
* @link http://phpthumb.gxdlabs.com
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @version 3.0
* @package PhpThumb
* @filesource
*/
/**
* ThumbBase Class Definition
*
* This is the base class that all implementations must extend. It contains the
* core variables and functionality common to all implementations, as well as the functions that
* allow plugins to augment those classes.
*
* @package PhpThumb
* @subpackage Core
*/
abstract class ThumbBase
{
/**
* All imported objects
*
* An array of imported plugin objects
*
* @var array
*/
protected $imported;
/**
* All imported object functions
*
* An array of all methods added to this class by imported plugin objects
*
* @var array
*/
protected $importedFunctions;
/**
* The last error message raised
*
* @var string
*/
protected $errorMessage;
/**
* Whether or not the current instance has any errors
*
* @var bool
*/
protected $hasError;
/**
* The name of the file we're manipulating
*
* This must include the path to the file (absolute paths recommended)
*
* @var string
*/
protected $fileName;
/**
* What the file format is (mime-type)
*
* @var string
*/
protected $format;
/**
* Whether or not the image is hosted remotely
*
* @var bool
*/
protected $remoteImage;
/**
* Whether or not the current image is an actual file, or the raw file data
*
* By "raw file data" it's meant that we're actually passing the result of something
* like file_get_contents() or perhaps from a database blob
*
* @var bool
*/
protected $isDataStream;
/**
* Class constructor
*
* @return ThumbBase
*/
public function __construct ($fileName, $isDataStream = false)
{
$this->imported = array();
$this->importedFunctions = array();
$this->errorMessage = null;
$this->hasError = false;
$this->fileName = $fileName;
$this->remoteImage = false;
$this->isDataStream = $isDataStream;
$this->fileExistsAndReadable();
}
/**
* Imports plugins in $registry to the class
*
* @param array $registry
*/
public function importPlugins ($registry)
{
foreach ($registry as $plugin => $meta)
{
$this->imports($plugin);
}
}
/**
* Imports a plugin
*
* This is where all the plugins magic happens! This function "loads" the plugin functions, making them available as
* methods on the class.
*
* @param string $object The name of the object to import / "load"
*/
protected function imports ($object)
{
// the new object to import
$newImport = new $object();
// the name of the new object (class name)
$importName = get_class($newImport);
// the new functions to import
$importFunctions = get_class_methods($newImport);
// add the object to the registry
array_push($this->imported, array($importName, $newImport));
// add the methods to the registry
foreach ($importFunctions as $key => $functionName)
{
$this->importedFunctions[$functionName] = &$newImport;
}
}
/**
* Checks to see if $this->fileName exists and is readable
*
*/
protected function fileExistsAndReadable ()
{
if ($this->isDataStream === true)
{
return;
}
if (preg_match('/https?:\/\//', $this->fileName) !== 0)
{
$this->remoteImage = true;
return;
}
if (!file_exists($this->fileName))
{
$this->triggerError('Image file not found: ' . $this->fileName);
}
elseif (!is_readable($this->fileName))
{
$this->triggerError('Image file not readable: ' . $this->fileName);
}
}
/**
* Sets $this->errorMessage to $errorMessage and throws an exception
*
* Also sets $this->hasError to true, so even if the exceptions are caught, we don't
* attempt to proceed with any other functions
*
* @param string $errorMessage
*/
protected function triggerError ($errorMessage)
{
$this->hasError = true;
$this->errorMessage = $errorMessage;
throw new Exception ($errorMessage);
}
/**
* Calls plugin / imported functions
*
* This is also where a fair amount of plugins magaic happens. This magic method is called whenever an "undefined" class
* method is called in code, and we use that to call an imported function.
*
* You should NEVER EVER EVER invoke this function manually. The universe will implode if you do... seriously ;)
*
* @param string $method
* @param array $args
*/
public function __call ($method, $args)
{
if( array_key_exists($method, $this->importedFunctions))
{
$args[] =& $this;
return call_user_func_array(array($this->importedFunctions[$method], $method), $args);
}
throw new BadMethodCallException ('Call to undefined method/class function: ' . $method);
}
/**
* Returns $imported.
* @see ThumbBase::$imported
* @return array
*/
public function getImported ()
{
return $this->imported;
}
/**
* Returns $importedFunctions.
* @see ThumbBase::$importedFunctions
* @return array
*/
public function getImportedFunctions ()
{
return $this->importedFunctions;
}
/**
* Returns $errorMessage.
*
* @see ThumbBase::$errorMessage
*/
public function getErrorMessage ()
{
return $this->errorMessage;
}
/**
* Sets $errorMessage.
*
* @param object $errorMessage
* @see ThumbBase::$errorMessage
*/
public function setErrorMessage ($errorMessage)
{
$this->errorMessage = $errorMessage;
}
/**
* Returns $fileName.
*
* @see ThumbBase::$fileName
*/
public function getFileName ()
{
return $this->fileName;
}
/**
* Sets $fileName.
*
* @param object $fileName
* @see ThumbBase::$fileName
*/
public function setFileName ($fileName)
{
$this->fileName = $fileName;
}
/**
* Returns $format.
*
* @see ThumbBase::$format
*/
public function getFormat ()
{
return $this->format;
}
/**
* Sets $format.
*
* @param object $format
* @see ThumbBase::$format
*/
public function setFormat ($format)
{
$this->format = $format;
}
/**
* Returns $hasError.
*
* @see ThumbBase::$hasError
*/
public function getHasError ()
{
return $this->hasError;
}
/**
* Sets $hasError.
*
* @param object $hasError
* @see ThumbBase::$hasError
*/
public function setHasError ($hasError)
{
$this->hasError = $hasError;
}
}

View File

@ -1,146 +0,0 @@
<?php
/**
* PhpThumb Library Definition File
*
* This file contains the definitions for the PhpThumbFactory class.
* It also includes the other required base class files.
*
* If you've got some auto-loading magic going on elsewhere in your code, feel free to
* remove the include_once statements at the beginning of this file... just make sure that
* these files get included one way or another in your code.
*
* PHP Version 5 with GD 2.0+
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
* Copyright (c) 2009, Ian Selby/Gen X Design
*
* Author(s): Ian Selby <ian@gen-x-design.com>
*
* Licensed under the MIT License
* Redistributions of files must retain the above copyright notice.
*
* @author Ian Selby <ian@gen-x-design.com>
* @copyright Copyright (c) 2009 Gen X Design
* @link http://phpthumb.gxdlabs.com
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @version 3.0
* @package PhpThumb
* @filesource
*/
// define some useful constants
define('THUMBLIB_BASE_PATH', dirname(__FILE__));
define('THUMBLIB_PLUGIN_PATH', THUMBLIB_BASE_PATH . '/thumb_plugins/');
define('DEFAULT_THUMBLIB_IMPLEMENTATION', 'gd');
/**
* Include the PhpThumb Class
*/
require_once THUMBLIB_BASE_PATH . '/PhpThumb.inc.php';
/**
* Include the ThumbBase Class
*/
require_once THUMBLIB_BASE_PATH . '/ThumbBase.inc.php';
/**
* Include the GdThumb Class
*/
require_once THUMBLIB_BASE_PATH . '/GdThumb.inc.php';
/**
* PhpThumbFactory Object
*
* This class is responsible for making sure everything is set up and initialized properly,
* and returning the appropriate thumbnail class instance. It is the only recommended way
* of using this library, and if you try and circumvent it, the sky will fall on your head :)
*
* Basic use is easy enough. First, make sure all the settings meet your needs and environment...
* these are the static variables defined at the beginning of the class.
*
* Once that's all set, usage is pretty easy. You can simply do something like:
* <code>$thumb = PhpThumbFactory::create('/path/to/file.png');</code>
*
* Refer to the documentation for the create function for more information
*
* @package PhpThumb
* @subpackage Core
*/
class PhpThumbFactory
{
/**
* Which implemenation of the class should be used by default
*
* Currently, valid options are:
* - imagick
* - gd
*
* These are defined in the implementation map variable, inside the create function
*
* @var string
*/
public static $defaultImplemenation = DEFAULT_THUMBLIB_IMPLEMENTATION;
/**
* Where the plugins can be loaded from
*
* Note, it's important that this path is properly defined. It is very likely that you'll
* have to change this, as the assumption here is based on a relative path.
*
* @var string
*/
public static $pluginPath = THUMBLIB_PLUGIN_PATH;
/**
* Factory Function
*
* This function returns the correct thumbnail object, augmented with any appropriate plugins.
* It does so by doing the following:
* - Getting an instance of PhpThumb
* - Loading plugins
* - Validating the default implemenation
* - Returning the desired default implementation if possible
* - Returning the GD implemenation if the default isn't available
* - Throwing an exception if no required libraries are present
*
* @return GdThumb
* @uses PhpThumb
* @param string $filename The path and file to load [optional]
*/
public static function create ($filename = null, $options = array(), $isDataStream = false)
{
// map our implementation to their class names
$implementationMap = array
(
'imagick' => 'ImagickThumb',
'gd' => 'GdThumb'
);
// grab an instance of PhpThumb
$pt = PhpThumb::getInstance();
// load the plugins
$pt->loadPlugins(self::$pluginPath);
$toReturn = null;
$implementation = self::$defaultImplemenation;
// attempt to load the default implementation
if ($pt->isValidImplementation(self::$defaultImplemenation))
{
$imp = $implementationMap[self::$defaultImplemenation];
$toReturn = new $imp($filename, $options, $isDataStream);
}
// load the gd implementation if default failed
else if ($pt->isValidImplementation('gd'))
{
$imp = $implementationMap['gd'];
$implementation = 'gd';
$toReturn = new $imp($filename, $options, $isDataStream);
}
// throw an exception if we can't load
else
{
throw new Exception('You must have either the GD or iMagick extension loaded to use this library');
}
$registry = $pt->getPluginRegistry($implementation);
$toReturn->importPlugins($registry);
return $toReturn;
}
}

View File

@ -1,184 +0,0 @@
<?php
/**
* GD Reflection Lib Plugin Definition File
*
* This file contains the plugin definition for the GD Reflection Lib for PHP Thumb
*
* PHP Version 5 with GD 2.0+
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
* Copyright (c) 2009, Ian Selby/Gen X Design
*
* Author(s): Ian Selby <ian@gen-x-design.com>
*
* Licensed under the MIT License
* Redistributions of files must retain the above copyright notice.
*
* @author Ian Selby <ian@gen-x-design.com>
* @copyright Copyright (c) 2009 Gen X Design
* @link http://phpthumb.gxdlabs.com
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @version 3.0
* @package PhpThumb
* @filesource
*/
/**
* GD Reflection Lib Plugin
*
* This plugin allows you to create those fun Apple(tm)-style reflections in your images
*
* @package PhpThumb
* @subpackage Plugins
*/
class GdReflectionLib
{
/**
* Instance of GdThumb passed to this class
*
* @var GdThumb
*/
protected $parentInstance;
protected $currentDimensions;
protected $workingImage;
protected $newImage;
protected $options;
public function createReflection ($percent, $reflection, $white, $border, $borderColor, &$that)
{
// bring stuff from the parent class into this class...
$this->parentInstance = $that;
$this->currentDimensions = $this->parentInstance->getCurrentDimensions();
$this->workingImage = $this->parentInstance->getWorkingImage();
$this->newImage = $this->parentInstance->getOldImage();
$this->options = $this->parentInstance->getOptions();
$width = $this->currentDimensions['width'];
$height = $this->currentDimensions['height'];
$reflectionHeight = intval($height * ($reflection / 100));
$newHeight = $height + $reflectionHeight;
$reflectedPart = $height * ($percent / 100);
$this->workingImage = imagecreatetruecolor($width, $newHeight);
imagealphablending($this->workingImage, true);
$colorToPaint = imagecolorallocatealpha($this->workingImage,255,255,255,0);
imagefilledrectangle($this->workingImage,0,0,$width,$newHeight,$colorToPaint);
imagecopyresampled
(
$this->workingImage,
$this->newImage,
0,
0,
0,
$reflectedPart,
$width,
$reflectionHeight,
$width,
($height - $reflectedPart)
);
$this->imageFlipVertical();
imagecopy($this->workingImage, $this->newImage, 0, 0, 0, 0, $width, $height);
imagealphablending($this->workingImage, true);
for ($i = 0; $i < $reflectionHeight; $i++)
{
$colorToPaint = imagecolorallocatealpha($this->workingImage, 255, 255, 255, ($i/$reflectionHeight*-1+1)*$white);
imagefilledrectangle($this->workingImage, 0, $height + $i, $width, $height + $i, $colorToPaint);
}
if($border == true)
{
$rgb = $this->hex2rgb($borderColor, false);
$colorToPaint = imagecolorallocate($this->workingImage, $rgb[0], $rgb[1], $rgb[2]);
imageline($this->workingImage, 0, 0, $width, 0, $colorToPaint); //top line
imageline($this->workingImage, 0, $height, $width, $height, $colorToPaint); //bottom line
imageline($this->workingImage, 0, 0, 0, $height, $colorToPaint); //left line
imageline($this->workingImage, $width-1, 0, $width-1, $height, $colorToPaint); //right line
}
if ($this->parentInstance->getFormat() == 'PNG')
{
$colorTransparent = imagecolorallocatealpha
(
$this->workingImage,
$this->options['alphaMaskColor'][0],
$this->options['alphaMaskColor'][1],
$this->options['alphaMaskColor'][2],
0
);
imagefill($this->workingImage, 0, 0, $colorTransparent);
imagesavealpha($this->workingImage, true);
}
$this->parentInstance->setOldImage($this->workingImage);
$this->currentDimensions['width'] = $width;
$this->currentDimensions['height'] = $newHeight;
$this->parentInstance->setCurrentDimensions($this->currentDimensions);
return $that;
}
/**
* Flips the image vertically
*
*/
protected function imageFlipVertical ()
{
$x_i = imagesx($this->workingImage);
$y_i = imagesy($this->workingImage);
for ($x = 0; $x < $x_i; $x++)
{
for ($y = 0; $y < $y_i; $y++)
{
imagecopy($this->workingImage, $this->workingImage, $x, $y_i - $y - 1, $x, $y, 1, 1);
}
}
}
/**
* Converts a hex color to rgb tuples
*
* @return mixed
* @param string $hex
* @param bool $asString
*/
protected function hex2rgb ($hex, $asString = false)
{
// strip off any leading #
if (0 === strpos($hex, '#'))
{
$hex = substr($hex, 1);
}
elseif (0 === strpos($hex, '&H'))
{
$hex = substr($hex, 2);
}
// break into hex 3-tuple
$cutpoint = ceil(strlen($hex) / 2)-1;
$rgb = explode(':', wordwrap($hex, $cutpoint, ':', $cutpoint), 3);
// convert each tuple to decimal
$rgb[0] = (isset($rgb[0]) ? hexdec($rgb[0]) : 0);
$rgb[1] = (isset($rgb[1]) ? hexdec($rgb[1]) : 0);
$rgb[2] = (isset($rgb[2]) ? hexdec($rgb[2]) : 0);
return ($asString ? "{$rgb[0]} {$rgb[1]} {$rgb[2]}" : $rgb);
}
}
$pt = PhpThumb::getInstance();
$pt->registerPlugin('GdReflectionLib', 'gd');

View File

@ -1,100 +0,0 @@
<?php
/**
* GD Watermark Lib Plugin Definition File
*
* This file contains the plugin definition for GD Watermark
* Usage:
* <?php
* require_once 'path/to/ThumbLib.inc.php';
* $pic = PhpThumbFactory::create('path/to/pic/destination');
* $watermark = PhpThumbFactory::create('path/to/watermark/destination');
*
* //overlays the $pic-image with the $watermark-image on the right bottom corner, no offset
* $pic->addWatermark($watermark, 'rightBottom', 50, 0, 0);
* $pic->show(); //or $pic->save('path/to/new/pic/destination');
* ?>
*
* PHP Version 5 with GD 2.0+
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
* Copyright (c) 2009, Ian Selby/Gen X Design
*
* Author(s): Ian Selby <ian@gen-x-design.com>
*
* Licensed under the MIT License
* Redistributions of files must retain the above copyright notice.
*
* @author Thomas Dullnig <thomas.dullnig@sevenspire.com>
* @copyright Copyright (c) 2009-2010 SEVENSPIRE
* @link http://www.sevenspire.com
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @version 1.0
* @package PhpThumb
* @filesource
*/
/**
* GD Watermark Lib Plugin
*
* Overlays an image with another image to create a watermark-effect
*
* @package PhpThumb
* @subpackage Plugins
*/
class GdWatermark
{
/**
* Function copied from: http://www.php.net/manual/en/function.imagecopymerge.php#92787
* Does the same as "imagecopymerge" but preserves the alpha-channel
*/
protected function imageCopyMergeAlpha(&$dst_im, &$src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){
$cut = imagecreatetruecolor($src_w, $src_h);
imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct);
}
/**
* Adds a watermark to the current image and overlays it on the given position.
* @param object $wm a GdThumb-Object
* @param object $pos Can be: left/west, right/east, center for the x-axis and top/north/upper, bottom/lower/south, center for the y-axis
* Examples:
* - leftTop/leftop/topleft/topLeft same as westNorth same as westupper same as leftnorth or any other combination
* - center --> centers both the x- and y-axis
* - leftCenter --> set x-axis to the left corner of the image and centers the y-axis
* @param object $opacity
* - set the opacity of the watermark in percent, 0 = total transparent, 100 = total opaque
* @param object $offsetX
* - add an offset on the x-axis. can be negative to set an offset to the left
* @param object $offsetY
* - add an offset on the y-axis. can be negative to set an offset to the top
* @param object $that
* - the current GdThumb-Object
* @return the manipulated GdThumb-Object for chaining
*/
public function addWatermark($wm, $pos, $opacity, $offsetX, $offsetY, $that) // dont use &wm etc.
{
$picDim = $that->getCurrentDimensions();
$wmDim = $wm->getCurrentDimensions();
$wmPosX = $offsetX;
$wmPosY = $offsetY;
if(preg_match('/right|east/i', $pos)){$wmPosX += $picDim['width'] - $wmDim['width'];}
else if(!preg_match('/left|west/i', $pos)){$wmPosX += intval($picDim['width']/2 - $wmDim['width']/2);}
if(preg_match('/bottom|lower|south/i', $pos)){$wmPosY += $picDim['height'] - $wmDim['height'];}
else if(!preg_match('/upper|top|north/i', $pos)){$wmPosY += intval($picDim['height']/2 - $wmDim['height']/2);}
$workingImage = $that->getWorkingImage();
$wmImage = ($wm->getWorkingImage() ? $wm->getWorkingImage() : $wm->getOldImage());
$this->imageCopyMergeAlpha($workingImage, $wmImage, $wmPosX, $wmPosY, 0, 0, $wmDim['width'], $wmDim['height'], $opacity);
$that->setWorkingImage($workingImage);
return $that;
}
}
$pt = PhpThumb::getInstance();
$pt->registerPlugin('GdWatermark', 'gd');

View File

@ -1,451 +0,0 @@
<?php
/**
* GD Watermark Lib Plugin Definition File
*
* This file contains the plugin definition for GD Watermark
* Usage:
* <?php
* require_once 'path/to/ThumbLib.inc.php';
* $pic = PhpThumbFactory::create('path/to/pic/destination');
* $watermark = PhpThumbFactory::create('path/to/watermark/destination');
*
* //overlays the $pic-image with the $watermark-image on the right bottom corner, no offset
* $pic->addWatermark($watermark, 'rightBottom', 50, 0, 0);
* $pic->show(); //or $pic->save('path/to/new/pic/destination');
* ?>
*
* PHP Version 5 with GD 2.0+
* PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
* Copyright (c) 2009, Ian Selby/Gen X Design
*
* Author(s): Ian Selby <ian@gen-x-design.com>
*
* Licensed under the MIT License
* Redistributions of files must retain the above copyright notice.
*
* @author Cameron @ e107inc
* @copyright e107 Inc.
* @link http://www.e107.org
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @version 1.0
* @package PhpThumb
* @filesource
*/
/**
* GD Watermark Lib Plugin
*
* Overlays an image with another image to create a watermark-effect
*
* @package PhpThumb
* @subpackage Plugins
*/
class GdWatermarkTTF
{
protected $parentInstance;
protected $currentDimensions;
protected $workingImage;
protected $newImage;
protected $options;
protected $parms;
private function DebugMessage($val)
{
// echo $val."<br />";
}
private function shadow_text($im, $size, $angle, $x, $y, $font, $text,$opacity=100)
{
$col = $this->hex2rgb($this->parms['color']);
$scol = $this->hex2rgb($this->parms['shadowcolor']);
$shadowcolor = imagecolorallocatealpha($im, $scol[0], $scol[1], $scol[2], $opacity);
$white = imagecolorallocatealpha($im, $col[0], $col[1], $col[2], $opacity);
// imagefilter($shadowcolor, IMG_FILTER_GAUSSIAN_BLUR);
imagefilter($shadowcolor, IMG_FILTER_SELECTIVE_BLUR);
imagettftext($im, $size, 0, $x + 1, $y + 1, $shadowcolor, $font, $text);
imagettftext($im, $size, 0, $x -1, $y + 1, $shadowcolor, $font, $text);
imagettftext($im, $size, 0, $x + 0, $y + 0, $white, $font, $text);
}
private function hex2rgb($hex) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
$rgb = array($r, $g, $b);
//return implode(",", $rgb); // returns the rgb values separated by commas
return $rgb; // returns an array with the rgb values
}
// Taken from http://phpthumb.sourceforge.net/index.php?source=phpthumb.filters.php
// public function WatermarkText($text, $size=12, $alignment='BR', $hex_color='000000', $ttffont='', $opacity=100, $margin=5, $angle=0, $bg_color=false, $bg_opacity=0, $fillextend='', &$that)
public function WatermarkText($parms, &$that)
{
$this->parms = $parms;
$text = $parms['text'];
$size = $parms['size'];
$alignment = $parms['pos'];
$hex_color = $parms['color'];
$ttffont = $parms['font'];
$opacity = (isset($parms['opacity'])) ? $parms['opacity'] : 100;
$margin = $parms['margin']; // 30; // (isset($parms[6])) ? $parms[6] : 25;
$angle = 0; // $parms['angle'];
$bg_color = false;
$bg_opacity = 0;
$fillextend = '';
$this->parentInstance = $that;
$this->currentDimensions = $this->parentInstance->getCurrentDimensions();
$this->workingImage = $this->parentInstance->getWorkingImage();
$this->newImage = $this->parentInstance->getOldImage();
$this->options = $this->parentInstance->getOptions();
$gdimg = $this->workingImage;
// text watermark requested
if (!$text) {
return false;
}
ImageAlphaBlending($gdimg, true);
if (preg_match('#^([0-9\\.\\-]*)x([0-9\\.\\-]*)(@[LCR])?$#i', $alignment, $matches)) {
$originOffsetX = intval($matches[1]);
$originOffsetY = intval($matches[2]);
$alignment = (@$matches[4] ? $matches[4] : 'L');
$margin = 0;
} else {
$originOffsetX = 0;
$originOffsetY = 0;
}
$metaTextArray = array(
'^Fb' => $this->phpThumbObject->getimagesizeinfo['filesize'],
'^Fk' => round($this->phpThumbObject->getimagesizeinfo['filesize'] / 1024),
'^Fm' => round($this->phpThumbObject->getimagesizeinfo['filesize'] / 1048576),
'^X' => $this->currentDimensions['width'], //$this->phpThumbObject->getimagesizeinfo[0],
'^Y' => $this->currentDimensions['height'], // $this->phpThumbObject->getimagesizeinfo[1],
'^x' => ImageSX($gdimg),
'^y' => ImageSY($gdimg),
'^^' => '^',
);
$this->DebugMessage("Margin: ".$margin);
$this->DebugMessage("Dimensions: ".$this->currentDimensions['width']." X ".$this->currentDimensions['height']);
$text = strtr($text, $metaTextArray);
$text = str_replace("\r\n", "\n", $text);
$text = str_replace("\r", "\n", $text);
$textlines = explode("\n", $text);
$this->DebugMessage('Processing '.count($textlines).' lines of text', __FILE__, __LINE__);
if (@is_readable($ttffont) && is_file($ttffont)) {
$opacity = 100 - intval(max(min($opacity, 100), 0));
// $letter_color_text = imagecolorallocate($gdimg,0,0,0);
$letter_color_text = imagecolorallocatealpha($gdimg,0,0,0,$opacity);
// $letter_color_text = ImageHexColorAllocate($gdimg, $hex_color, false, $opacity * 1.27);
$this->DebugMessage('Using TTF font "'.$ttffont.'"', __FILE__, __LINE__);
$TTFbox = ImageTTFbBox($size, $angle, $ttffont, $text);
$min_x = min($TTFbox[0], $TTFbox[2], $TTFbox[4], $TTFbox[6]);
$max_x = max($TTFbox[0], $TTFbox[2], $TTFbox[4], $TTFbox[6]);
//$text_width = round($max_x - $min_x + ($size * 0.5));
$text_width = round($max_x - $min_x);
$min_y = min($TTFbox[1], $TTFbox[3], $TTFbox[5], $TTFbox[7]);
$max_y = max($TTFbox[1], $TTFbox[3], $TTFbox[5], $TTFbox[7]);
//$text_height = round($max_y - $min_y + ($size * 0.5));
$text_height = round($max_y - $min_y);
$TTFboxChar = ImageTTFbBox($size, $angle, $ttffont, 'jH');
$char_min_y = min($TTFboxChar[1], $TTFboxChar[3], $TTFboxChar[5], $TTFboxChar[7]);
$char_max_y = max($TTFboxChar[1], $TTFboxChar[3], $TTFboxChar[5], $TTFboxChar[7]);
$char_height = round($char_max_y - $char_min_y);
if ($alignment == '*') {
$text_origin_y = $char_height + $margin;
while (($text_origin_y - $text_height) < ImageSY($gdimg)) {
$text_origin_x = $margin;
while ($text_origin_x < ImageSX($gdimg)) {
ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
$text_origin_x += ($text_width + $margin);
}
$text_origin_y += ($text_height + $margin);
}
} else {
// this block for background color only
switch ($alignment) {
case '*':
// handled separately
break;
case 'T':
$text_origin_x = ($originOffsetX ? $originOffsetX - round($text_width / 2) : round((ImageSX($gdimg) - $text_width) / 2));
$text_origin_y = $char_height + $margin + $originOffsetY;
break;
case 'B':
$text_origin_x = ($originOffsetX ? $originOffsetX - round($text_width / 2) : round((ImageSX($gdimg) - $text_width) / 2));
$text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin + $originOffsetY;
break;
case 'L':
$text_origin_x = $margin + $originOffsetX;
$text_origin_y = ($originOffsetY ? $originOffsetY : round((ImageSY($gdimg) - $text_height) / 2) + $char_height);
break;
case 'R':
$text_origin_x = ($originOffsetX ? $originOffsetX - $text_width : ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin);
$text_origin_y = ($originOffsetY ? $originOffsetY : round((ImageSY($gdimg) - $text_height) / 2) + $char_height);
break;
case 'C':
$text_origin_x = ($originOffsetX ? $originOffsetX - round($text_width / 2) : round((ImageSX($gdimg) - $text_width) / 2));
$text_origin_y = ($originOffsetY ? $originOffsetY : round((ImageSY($gdimg) - $text_height) / 2) + $char_height);
break;
case 'TL':
$text_origin_x = $margin + $originOffsetX;
$text_origin_y = $char_height + $margin + $originOffsetY;
break;
case 'TR':
$text_origin_x = ($originOffsetX ? $originOffsetX - $text_width : ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin);
$text_origin_y = $char_height + $margin + $originOffsetY;
break;
case 'BL':
$text_origin_x = $margin + $originOffsetX;
$text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin + $originOffsetY;
break;
case 'BR':
default:
$text_origin_x = ($originOffsetX ? $originOffsetX - $text_width : ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin);
$text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin + $originOffsetY;
break;
}
//ImageRectangle($gdimg, $text_origin_x + $min_x, $text_origin_y + $TTFbox[1], $text_origin_x + $min_x + $text_width, $text_origin_y + $TTFbox[1] - $text_height, $letter_color_text);
/* if (phpthumb_functions::IsHexColor($bg_color)) {
$text_background_alpha = round(127 * ((100 - min(max(0, $bg_opacity), 100)) / 100));
$text_color_background = phpthumb_functions::ImageHexColorAllocate($gdimg, $bg_color, false, $text_background_alpha);
} else {
$text_color_background = phpthumb_functions::ImageHexColorAllocate($gdimg, 'FFFFFF', false, 127);
}
*/
$text_color_background = imagecolorallocatealpha($gdimg,0,0,0,0);
$x1 = $text_origin_x + $min_x;
$y1 = $text_origin_y + $TTFbox[1];
$x2 = $text_origin_x + $min_x + $text_width;
$y2 = $text_origin_y + $TTFbox[1] - $text_height;
$x_TL = preg_match('#x#i', $fillextend) ? 0 : min($x1, $x2);
$y_TL = preg_match('#y#i', $fillextend) ? 0 : min($y1, $y2);
$x_BR = preg_match('#x#i', $fillextend) ? ImageSX($gdimg) : max($x1, $x2);
$y_BR = preg_match('#y#i', $fillextend) ? ImageSY($gdimg) : max($y1, $y2);
//while ($y_BR > ImageSY($gdimg)) {
// $y_TL--;
// $y_BR--;
// $text_origin_y--;
//}
$this->DebugMessage('WatermarkText() calling ImageFilledRectangle($gdimg, '.$x_TL.', '.$y_TL.', '.$x_BR.', '.$y_BR.', $text_color_background)', __FILE__, __LINE__);
// ImageFilledRectangle($gdimg, $x_TL, $y_TL, $x_BR, $y_BR, $text_color_background);
// end block for background color only
$y_offset = 0;
foreach ($textlines as $dummy => $line) {
$TTFboxLine = ImageTTFbBox($size, $angle, $ttffont, $line);
$min_x_line = min($TTFboxLine[0], $TTFboxLine[2], $TTFboxLine[4], $TTFboxLine[6]);
$max_x_line = max($TTFboxLine[0], $TTFboxLine[2], $TTFboxLine[4], $TTFboxLine[6]);
//$text_width = round($max_x - $min_x + ($size * 0.5));
$text_width_line = round($max_x_line - $min_x_line);
$min_y_line = min($TTFboxLine[1], $TTFboxLine[3], $TTFboxLine[5], $TTFboxLine[7]);
$max_y_line = max($TTFboxLine[1], $TTFboxLine[3], $TTFboxLine[5], $TTFboxLine[7]);
//$text_height = round($max_y - $min_y + ($size * 0.5));
$text_height_line = round($max_y_line - $min_y_line);
switch ($alignment) {
// $text_origin_y set above, just re-set $text_origin_x here as needed
case 'L':
case 'TL':
case 'BL':
// no change neccesary
break;
case 'C':
case 'T':
case 'B':
$text_origin_x = ($originOffsetX ? $originOffsetX - round($text_width_line / 2) : round((ImageSX($gdimg) - $text_width_line) / 2));
break;
case 'R':
case 'TR':
case 'BR':
$text_origin_x = ($originOffsetX ? $originOffsetX - $text_width_line : ImageSX($gdimg) - $text_width_line + $TTFbox[0] - $min_x + round($size * 0.25) - $margin);
break;
}
//ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
$this->DebugMessage('WatermarkText() calling ImageTTFtext($gdimg, '.$size.', '.$angle.', '.$text_origin_x.', '.($text_origin_y + $y_offset).', $letter_color_text, '.$ttffont.', '.$line.')', __FILE__, __LINE__);
$this->shadow_text($gdimg, $size, $angle, $text_origin_x, $text_origin_y + $y_offset, $ttffont, $line,$opacity);
// ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y + $y_offset, $letter_color_text, $ttffont, $line);
$y_offset += $char_height;
}
}
return $that;
// return true;
} else { //TODO FIX and Test.
$size = min(5, max(1, $size));
$this->DebugMessage('Using built-in font (size='.$size.') for text watermark'.($ttffont ? ' because $ttffont !is_readable('.$ttffont.')' : ''), __FILE__, __LINE__);
$text_width = 0;
$text_height = 0;
foreach ($textlines as $dummy => $line) {
$text_width = max($text_width, ImageFontWidth($size) * strlen($line));
$text_height += ImageFontHeight($size);
}
if ($img_watermark = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
ImageAlphaBlending($img_watermark, false);
if (phpthumb_functions::IsHexColor($bg_color)) {
$text_background_alpha = round(127 * ((100 - min(max(0, $bg_opacity), 100)) / 100));
$text_color_background = phpthumb_functions::ImageHexColorAllocate($img_watermark, $bg_color, false, $text_background_alpha);
} else {
$text_color_background = phpthumb_functions::ImageHexColorAllocate($img_watermark, 'FFFFFF', false, 127);
}
$this->DebugMessage('WatermarkText() calling ImageFilledRectangle($img_watermark, 0, 0, '.ImageSX($img_watermark).', '.ImageSY($img_watermark).', $text_color_background)', __FILE__, __LINE__);
ImageFilledRectangle($img_watermark, 0, 0, ImageSX($img_watermark), ImageSY($img_watermark), $text_color_background);
if ($angle && function_exists('ImageRotate')) {
// using $img_watermark_mask is pointless if ImageRotate function isn't available
if ($img_watermark_mask = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
$mask_color_background = ImageColorAllocate($img_watermark_mask, 0, 0, 0);
ImageAlphaBlending($img_watermark_mask, false);
ImageFilledRectangle($img_watermark_mask, 0, 0, ImageSX($img_watermark_mask), ImageSY($img_watermark_mask), $mask_color_background);
$mask_color_watermark = ImageColorAllocate($img_watermark_mask, 255, 255, 255);
}
}
$text_color_watermark = phpthumb_functions::ImageHexColorAllocate($img_watermark, $hex_color);
foreach ($textlines as $key => $line) {
switch ($alignment) {
case 'C':
$x_offset = round(($text_width - (ImageFontWidth($size) * strlen($line))) / 2);
$originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
$originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
break;
case 'T':
$x_offset = round(($text_width - (ImageFontWidth($size) * strlen($line))) / 2);
$originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
$originOffsetY = $margin;
break;
case 'B':
$x_offset = round(($text_width - (ImageFontWidth($size) * strlen($line))) / 2);
$originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
$originOffsetY = ImageSY($gdimg) - ImageSY($img_watermark) - $margin;
break;
case 'L':
$x_offset = 0;
$originOffsetX = $margin;
$originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
break;
case 'TL':
$x_offset = 0;
$originOffsetX = $margin;
$originOffsetY = $margin;
break;
case 'BL':
$x_offset = 0;
$originOffsetX = $margin;
$originOffsetY = ImageSY($gdimg) - ImageSY($img_watermark) - $margin;
break;
case 'R':
$x_offset = $text_width - (ImageFontWidth($size) * strlen($line));
$originOffsetX = ImageSX($gdimg) - ImageSX($img_watermark) - $margin;
$originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
break;
case 'TR':
$x_offset = $text_width - (ImageFontWidth($size) * strlen($line));
$originOffsetX = ImageSX($gdimg) - ImageSX($img_watermark) - $margin;
$originOffsetY = $margin;
break;
case 'BR':
default:
$x_offset = $text_width - (ImageFontWidth($size) * strlen($line));
$originOffsetX = ImageSX($gdimg) - ImageSX($img_watermark) - $margin;
$originOffsetY = ImageSY($gdimg) - ImageSY($img_watermark) - $margin;
break;
}
$this->DebugMessage('WatermarkText() calling ImageString($img_watermark, '.$size.', '.$x_offset.', '.($key * ImageFontHeight($size)).', '.$line.', $text_color_watermark)', __FILE__, __LINE__);
ImageString($img_watermark, $size, $x_offset, $key * ImageFontHeight($size), $line, $text_color_watermark);
if ($angle && $img_watermark_mask) {
$this->DebugMessage('WatermarkText() calling ImageString($img_watermark_mask, '.$size.', '.$x_offset.', '.($key * ImageFontHeight($size)).', '.$text.', $mask_color_watermark)', __FILE__, __LINE__);
ImageString($img_watermark_mask, $size, $x_offset, $key * ImageFontHeight($size), $text, $mask_color_watermark);
}
}
if ($angle && $img_watermark_mask) {
$img_watermark = ImageRotate($img_watermark, $angle, $text_color_background);
$img_watermark_mask = ImageRotate($img_watermark_mask, $angle, $mask_color_background);
phpthumb_filters::ApplyMask($img_watermark_mask, $img_watermark);
}
//phpthumb_filters::WatermarkOverlay($gdimg, $img_watermark, $alignment, $opacity, $margin);
$this->DebugMessage('WatermarkText() calling phpthumb_filters::WatermarkOverlay($gdimg, $img_watermark, '.($originOffsetX.'x'.$originOffsetY).', '.$opacity.', 0)', __FILE__, __LINE__);
phpthumb_filters::WatermarkOverlay($gdimg, $img_watermark, $originOffsetX.'x'.$originOffsetY, $opacity, 0);
ImageDestroy($img_watermark);
return true;
}
}
return false;
}
}
$pt = PhpThumb::getInstance();
$pt->registerPlugin('GdWatermarkTTF', 'gd');

View File

@ -285,15 +285,7 @@ class e107Test extends \Codeception\Test\Unit
}*/
public function testGetThumb()
{
$tmp = e107::getThumb(e_PLUGIN."gallery/images/horse.jpg");
$className = get_class($tmp);
$this->assertEquals('GdThumb', $className);
}
public function testGetUserSession()