Applied fixes from StyleCI
This commit is contained in:

committed by
StyleCI Bot

parent
be5df5334f
commit
d637c2b23f
@@ -25,24 +25,27 @@ For licensing, see LICENSE.md or http://ckeditor.com/license
|
||||
</thead>
|
||||
<?php
|
||||
|
||||
if (!empty($_POST))
|
||||
{
|
||||
foreach ( $_POST as $key => $value )
|
||||
{
|
||||
if ( ( !is_string($value) && !is_numeric($value) ) || !is_string($key) )
|
||||
continue;
|
||||
if (!empty($_POST)) {
|
||||
foreach ($_POST as $key => $value) {
|
||||
if ((!is_string($value) && !is_numeric($value)) || !is_string($key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( get_magic_quotes_gpc() )
|
||||
$value = htmlspecialchars( stripslashes((string)$value) );
|
||||
else
|
||||
$value = htmlspecialchars( (string)$value );
|
||||
?>
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = htmlspecialchars(stripslashes((string) $value));
|
||||
} else {
|
||||
$value = htmlspecialchars((string) $value);
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<th style="vertical-align: top"><?php echo htmlspecialchars( (string)$key ); ?></th>
|
||||
<td><pre class="samples"><?php echo $value; ?></pre></td>
|
||||
<th style="vertical-align: top"><?php echo htmlspecialchars((string) $key);
|
||||
?></th>
|
||||
<td><pre class="samples"><?php echo $value;
|
||||
?></pre></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
@@ -13,4 +13,4 @@
|
||||
For licensing, see LICENSE.md or http://ckeditor.com/license
|
||||
-------------------------------------------------------------------------------------------
|
||||
|
||||
</pre><div style="display:none"></body> */ include "assets/posteddata.php"; ?>
|
||||
</pre><div style="display:none"></body> */ include 'assets/posteddata.php';
|
||||
|
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Filemanager PHP connector
|
||||
* This file should at least declare auth() function
|
||||
* and instantiate the Filemanager as '$fm'
|
||||
* and instantiate the Filemanager as '$fm'.
|
||||
*
|
||||
* IMPORTANT : by default Read and Write access is granted to everyone
|
||||
* Copy/paste this file to 'user.config.php' file to implement your own auth() function
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
|
||||
// Laravel init
|
||||
require getcwd() . '/../../../../bootstrap/autoload.php';
|
||||
$app = require_once getcwd() . '/../../../../bootstrap/app.php';
|
||||
require getcwd().'/../../../../bootstrap/autoload.php';
|
||||
$app = require_once getcwd().'/../../../../bootstrap/app.php';
|
||||
|
||||
$kernel = $app->make('Illuminate\Contracts\Http\Kernel');
|
||||
|
||||
@@ -31,58 +31,44 @@ $app['session']->driver()->setId($id);
|
||||
$app['session']->driver()->start();
|
||||
|
||||
// Folder path
|
||||
$folderPath = $app->basePath() . '/public/'.config('filemanager.folder_path');
|
||||
$folderPath = $app->basePath().'/public/'.config('filemanager.folder_path');
|
||||
|
||||
// Check if user in authentified
|
||||
if(!$app['auth']->check())
|
||||
{
|
||||
$laravelAuth = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if user has all access
|
||||
if($app['auth']->user()->accessMediasAll())
|
||||
{
|
||||
$laravelAuth = true;
|
||||
}
|
||||
elseif(method_exists($app['auth']->user(), 'accessMediasFolder'))
|
||||
{
|
||||
// Check if user has access to one folder
|
||||
if($app['auth']->user()->accessMediasFolder())
|
||||
{
|
||||
// Folder name with user id
|
||||
$folderPath .= 'user' . $app['auth']->id();
|
||||
// Create folder if doesn't exist
|
||||
if (!is_dir($folderPath))
|
||||
{
|
||||
mkdir($folderPath);
|
||||
}
|
||||
$laravelAuth = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$laravelAuth = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!$app['auth']->check()) {
|
||||
$laravelAuth = false;
|
||||
}
|
||||
} else {
|
||||
// Check if user has all access
|
||||
if ($app['auth']->user()->accessMediasAll()) {
|
||||
$laravelAuth = true;
|
||||
} elseif (method_exists($app['auth']->user(), 'accessMediasFolder')) {
|
||||
// Check if user has access to one folder
|
||||
if ($app['auth']->user()->accessMediasFolder()) {
|
||||
// Folder name with user id
|
||||
$folderPath .= 'user'.$app['auth']->id();
|
||||
// Create folder if doesn't exist
|
||||
if (!is_dir($folderPath)) {
|
||||
mkdir($folderPath);
|
||||
}
|
||||
$laravelAuth = true;
|
||||
} else {
|
||||
$laravelAuth = false;
|
||||
}
|
||||
} else {
|
||||
$laravelAuth = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is authorized
|
||||
* Check if user is authorized.
|
||||
*
|
||||
*
|
||||
* @return boolean true if access granted, false if no access
|
||||
* @return bool true if access granted, false if no access
|
||||
*/
|
||||
function auth()
|
||||
function auth()
|
||||
{
|
||||
return $GLOBALS['laravelAuth'];
|
||||
return $GLOBALS['laravelAuth'];
|
||||
}
|
||||
|
||||
$fm = new Filemanager();
|
||||
|
||||
$fm->setFileRoot($folderPath);
|
||||
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
// only for debug
|
||||
// error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
|
||||
// ini_set('display_errors', '1');
|
||||
/**
|
||||
* Filemanager PHP connector
|
||||
* Filemanager PHP connector.
|
||||
*
|
||||
* filemanager.php
|
||||
* use for ckeditor filemanager plug-in by Core Five - http://labs.corefive.com/Projects/FileManager/
|
||||
@@ -13,64 +14,64 @@
|
||||
* @author Simon Georget <simon (at) linea21 (dot) com>
|
||||
* @copyright Authors
|
||||
*/
|
||||
|
||||
require_once('filemanager.class.php');
|
||||
require_once 'filemanager.class.php';
|
||||
|
||||
// for php 5.2 compatibility
|
||||
if (!function_exists('array_replace_recursive')) {
|
||||
function array_replace_recursive($array, $array1) {
|
||||
function recurse($array, $array1) {
|
||||
foreach($array1 as $key => $value) {
|
||||
// create new key in $array, if it is empty or not an array
|
||||
if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key]))) {
|
||||
$array[$key] = array();
|
||||
}
|
||||
function array_replace_recursive($array, $array1)
|
||||
{
|
||||
function recurse($array, $array1)
|
||||
{
|
||||
foreach ($array1 as $key => $value) {
|
||||
// create new key in $array, if it is empty or not an array
|
||||
if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key]))) {
|
||||
$array[$key] = [];
|
||||
}
|
||||
|
||||
// overwrite the value in the base array
|
||||
if (is_array($value)) {
|
||||
$value = recurse($array[$key], $value);
|
||||
}
|
||||
$array[$key] = $value;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
// overwrite the value in the base array
|
||||
if (is_array($value)) {
|
||||
$value = recurse($array[$key], $value);
|
||||
}
|
||||
$array[$key] = $value;
|
||||
}
|
||||
|
||||
// handle the arguments, merge one by one
|
||||
$args = func_get_args();
|
||||
$array = $args[0];
|
||||
if (!is_array($array)) {
|
||||
return $array;
|
||||
}
|
||||
for ($i = 1; $i < count($args); $i++) {
|
||||
if (is_array($args[$i])) {
|
||||
$array = recurse($array, $args[$i]);
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
// handle the arguments, merge one by one
|
||||
$args = func_get_args();
|
||||
$array = $args[0];
|
||||
if (!is_array($array)) {
|
||||
return $array;
|
||||
}
|
||||
for ($i = 1; $i < count($args); $i++) {
|
||||
if (is_array($args[$i])) {
|
||||
$array = recurse($array, $args[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
// if user file is defined we include it, else we include the default file
|
||||
(file_exists('user.config.php')) ? include_once('user.config.php') : include_once('default.config.php');
|
||||
(file_exists('user.config.php')) ? include_once('user.config.php') : include_once 'default.config.php';
|
||||
|
||||
// auth() function is already defined
|
||||
// and Filemanager is instantiated as $fm
|
||||
|
||||
$response = '';
|
||||
|
||||
if(!auth()) {
|
||||
$fm->error($fm->lang('AUTHORIZATION_REQUIRED'));
|
||||
if (!auth()) {
|
||||
$fm->error($fm->lang('AUTHORIZATION_REQUIRED'));
|
||||
}
|
||||
|
||||
if(!isset($_GET)) {
|
||||
$fm->error($fm->lang('INVALID_ACTION'));
|
||||
if (!isset($_GET)) {
|
||||
$fm->error($fm->lang('INVALID_ACTION'));
|
||||
} else {
|
||||
if (isset($_GET['mode']) && $_GET['mode'] != '') {
|
||||
switch ($_GET['mode']) {
|
||||
|
||||
if(isset($_GET['mode']) && $_GET['mode']!='') {
|
||||
|
||||
switch($_GET['mode']) {
|
||||
|
||||
default:
|
||||
|
||||
$fm->error($fm->lang('MODE_ERROR'));
|
||||
@@ -78,105 +79,101 @@ if(!isset($_GET)) {
|
||||
|
||||
case 'getinfo':
|
||||
|
||||
if($fm->getvar('path')) {
|
||||
$response = $fm->getinfo();
|
||||
if ($fm->getvar('path')) {
|
||||
$response = $fm->getinfo();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'getfolder':
|
||||
|
||||
if($fm->getvar('path')) {
|
||||
$response = $fm->getfolder();
|
||||
|
||||
if ($fm->getvar('path')) {
|
||||
$response = $fm->getfolder();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'rename':
|
||||
|
||||
if($fm->getvar('old') && $fm->getvar('new')) {
|
||||
$response = $fm->rename();
|
||||
if ($fm->getvar('old') && $fm->getvar('new')) {
|
||||
$response = $fm->rename();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'move':
|
||||
// allow "../"
|
||||
if($fm->getvar('old') && $fm->getvar('new') && $fm->getvar('root')) {
|
||||
$response = $fm->move();
|
||||
if ($fm->getvar('old') && $fm->getvar('new') && $fm->getvar('root')) {
|
||||
$response = $fm->move();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'editfile':
|
||||
|
||||
if($fm->getvar('path')) {
|
||||
$response = $fm->editfile();
|
||||
|
||||
if ($fm->getvar('path')) {
|
||||
$response = $fm->editfile();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'delete':
|
||||
|
||||
if($fm->getvar('path')) {
|
||||
$response = $fm->delete();
|
||||
if ($fm->getvar('path')) {
|
||||
$response = $fm->delete();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'addfolder':
|
||||
|
||||
if($fm->getvar('path') && $fm->getvar('name')) {
|
||||
$response = $fm->addfolder();
|
||||
if ($fm->getvar('path') && $fm->getvar('name')) {
|
||||
$response = $fm->addfolder();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'download':
|
||||
if($fm->getvar('path')) {
|
||||
$fm->download();
|
||||
if ($fm->getvar('path')) {
|
||||
$fm->download();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'preview':
|
||||
if($fm->getvar('path')) {
|
||||
if(isset($_GET['thumbnail'])) {
|
||||
$thumbnail = true;
|
||||
} else {
|
||||
$thumbnail = false;
|
||||
}
|
||||
$fm->preview($thumbnail);
|
||||
if ($fm->getvar('path')) {
|
||||
if (isset($_GET['thumbnail'])) {
|
||||
$thumbnail = true;
|
||||
} else {
|
||||
$thumbnail = false;
|
||||
}
|
||||
$fm->preview($thumbnail);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} elseif (isset($_POST['mode']) && $_POST['mode'] != '') {
|
||||
switch ($_POST['mode']) {
|
||||
|
||||
} else if(isset($_POST['mode']) && $_POST['mode']!='') {
|
||||
|
||||
switch($_POST['mode']) {
|
||||
|
||||
default:
|
||||
|
||||
$fm->error($fm->lang('MODE_ERROR'));
|
||||
break;
|
||||
|
||||
|
||||
case 'add':
|
||||
|
||||
if($fm->postvar('currentpath')) {
|
||||
$fm->add();
|
||||
if ($fm->postvar('currentpath')) {
|
||||
$fm->add();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'replace':
|
||||
|
||||
if($fm->postvar('newfilepath')) {
|
||||
$fm->replace();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'savefile':
|
||||
|
||||
if($fm->postvar('content', false) && $fm->postvar('path')) {
|
||||
$response = $fm->savefile();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'replace':
|
||||
|
||||
}
|
||||
if ($fm->postvar('newfilepath')) {
|
||||
$fm->replace();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'savefile':
|
||||
|
||||
if ($fm->postvar('content', false) && $fm->postvar('path')) {
|
||||
$response = $fm->savefile();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
die();
|
||||
?>
|
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
/**
|
||||
*/
|
||||
?>
|
||||
<form style="font-family: Verdana, Tahoma; font-size: 11px">
|
||||
<input type="hidden" name="demo" value="<?php echo $activeDemo->name; ?>" />
|
||||
<div style="background-color: #f0f0f0; padding: 5px;">
|
||||
<input type="submit" value="refresh" />
|
||||
<?php
|
||||
foreach ($activeDemo->fields as $field)
|
||||
$field->render();
|
||||
foreach ($activeDemo->fields as $field) {
|
||||
$field->render();
|
||||
}
|
||||
?>
|
||||
<br />
|
||||
<span style="font-family: Verdana, Tahoma; font-size: 11px">
|
||||
@@ -18,49 +18,51 @@
|
||||
|
||||
<div style="background-color: #d0d0d0; padding: 5px; text-align: right; float: right; width: 300px;">
|
||||
<?php
|
||||
$top_form['output']->render();
|
||||
echo "<br />\n";
|
||||
echo ' Palette options (only for <em>png8</em> and <em>gif</em> output):<br />';
|
||||
$top_form['ncolors']->render();
|
||||
echo "<br />\n";
|
||||
$top_form['dither']->render();
|
||||
$top_form['match_palette']->render();
|
||||
$top_form['output']->render();
|
||||
echo "<br />\n";
|
||||
echo ' Palette options (only for <em>png8</em> and <em>gif</em> output):<br />';
|
||||
$top_form['ncolors']->render();
|
||||
echo "<br />\n";
|
||||
$top_form['dither']->render();
|
||||
$top_form['match_palette']->render();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
$activeDemo->text();
|
||||
$activeDemo->text();
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
$images_in_row = 2;
|
||||
$in_row = 0;
|
||||
$images = array();
|
||||
$di = new DirectoryIterator(dirname(__FILE__) . '/images/');
|
||||
foreach ($di as $file)
|
||||
if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0)
|
||||
$images[] = $file->getFilename();
|
||||
|
||||
asort($images);
|
||||
foreach ($images as $image_file)
|
||||
{
|
||||
echo '<div class="images">';
|
||||
echo '<img src="images/' . $image_file . '" />';
|
||||
$img_url = 'image.php?image=' . $image_file . '&output=' . $top_form['output']->value .
|
||||
'&colors=' . $top_form['ncolors']->value . '&dither=' . $top_form['dither']->value .
|
||||
'&match_palette=' . $top_form['match_palette']->value . '&demo=' . $activeDemo->name;
|
||||
foreach ($activeDemo->fields as $field)
|
||||
$img_url .= '&' . $field->getURLValue();
|
||||
|
||||
echo ' ';
|
||||
echo '<a href="' . $img_url . '">';
|
||||
echo '<img src="' . $img_url . '" />';
|
||||
echo '</a>';
|
||||
echo "</div>\n";
|
||||
}
|
||||
$images_in_row = 2;
|
||||
$in_row = 0;
|
||||
$images = [];
|
||||
$di = new DirectoryIterator(dirname(__FILE__).'/images/');
|
||||
foreach ($di as $file) {
|
||||
if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0) {
|
||||
$images[] = $file->getFilename();
|
||||
}
|
||||
}
|
||||
|
||||
asort($images);
|
||||
foreach ($images as $image_file) {
|
||||
echo '<div class="images">';
|
||||
echo '<img src="images/'.$image_file.'" />';
|
||||
$img_url = 'image.php?image='.$image_file.'&output='.$top_form['output']->value.
|
||||
'&colors='.$top_form['ncolors']->value.'&dither='.$top_form['dither']->value.
|
||||
'&match_palette='.$top_form['match_palette']->value.'&demo='.$activeDemo->name;
|
||||
foreach ($activeDemo->fields as $field) {
|
||||
$img_url .= '&'.$field->getURLValue();
|
||||
}
|
||||
|
||||
echo ' ';
|
||||
echo '<a href="'.$img_url.'">';
|
||||
echo '<img src="'.$img_url.'" />';
|
||||
echo '</a>';
|
||||
echo "</div>\n";
|
||||
}
|
||||
?>
|
||||
<div style="clear: both"></div>
|
||||
|
||||
|
@@ -1,19 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_addNoise extends Demo
|
||||
{
|
||||
public $order = 9350;
|
||||
/**
|
||||
*/
|
||||
class Demo_addNoise extends Demo
|
||||
{
|
||||
public $order = 9350;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new IntField('amount', 300));
|
||||
$this->addField(new SelectField('type', array('salt&pepper','mono','color'), 'mono'));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->addNoise($this->fields['amount']->value, $this->fields['type']->value);
|
||||
}
|
||||
}
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new IntField('amount', 300));
|
||||
$this->addField(new SelectField('type', ['salt&pepper', 'mono', 'color'], 'mono'));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->addNoise($this->fields['amount']->value, $this->fields['type']->value);
|
||||
}
|
||||
}
|
||||
|
@@ -1,45 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_applyConvolution extends Demo
|
||||
{
|
||||
public $order = 2025;
|
||||
|
||||
protected $base_matrix = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1));
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new Field('matrix', '2 0 0, 0 -1 0, 0 0 -1', '3x3 float matrix; separate rows with a comma, and columns with a space'));
|
||||
$this->addField(new FloatField('div', 1));
|
||||
$this->addField(new FloatField('offset', 220));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$mstr = $this->fval('matrix');
|
||||
$rows = explode(',', $mstr);
|
||||
|
||||
$matrix = array();
|
||||
foreach ($this->base_matrix as $idx => $base_row)
|
||||
{
|
||||
$build_row = array();
|
||||
if (isset($rows[$idx]))
|
||||
{
|
||||
$row = trim($rows[$idx]);
|
||||
$cols = explode(' ', $row);
|
||||
for ($c = 0; $c < 3; $c++)
|
||||
if (isset($cols[$c]))
|
||||
$build_row[] = floatval(trim($cols[$c]));
|
||||
else
|
||||
$build_row[] = $base_row[$c];
|
||||
}
|
||||
else
|
||||
$build_row = $base_row;
|
||||
|
||||
$matrix[] = $build_row;
|
||||
}
|
||||
|
||||
return $image->applyConvolution($matrix, $this->fval('div'), $this->fval('offset'));
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_applyConvolution extends Demo
|
||||
{
|
||||
public $order = 2025;
|
||||
|
||||
protected $base_matrix = [[2, 0, 0], [0, -1, 0], [0, 0, -1]];
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new Field('matrix', '2 0 0, 0 -1 0, 0 0 -1', '3x3 float matrix; separate rows with a comma, and columns with a space'));
|
||||
$this->addField(new FloatField('div', 1));
|
||||
$this->addField(new FloatField('offset', 220));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$mstr = $this->fval('matrix');
|
||||
$rows = explode(',', $mstr);
|
||||
|
||||
$matrix = [];
|
||||
foreach ($this->base_matrix as $idx => $base_row) {
|
||||
$build_row = [];
|
||||
if (isset($rows[$idx])) {
|
||||
$row = trim($rows[$idx]);
|
||||
$cols = explode(' ', $row);
|
||||
for ($c = 0; $c < 3; $c++) {
|
||||
if (isset($cols[$c])) {
|
||||
$build_row[] = floatval(trim($cols[$c]));
|
||||
} else {
|
||||
$build_row[] = $base_row[$c];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$build_row = $base_row;
|
||||
}
|
||||
|
||||
$matrix[] = $build_row;
|
||||
}
|
||||
|
||||
return $image->applyConvolution($matrix, $this->fval('div'), $this->fval('offset'));
|
||||
}
|
||||
}
|
||||
|
@@ -1,39 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_applyFilter extends Demo
|
||||
{
|
||||
public $order = 2000;
|
||||
/**
|
||||
*/
|
||||
class Demo_applyFilter extends Demo
|
||||
{
|
||||
public $order = 2000;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new SelectField('filter', 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'
|
||||
))
|
||||
);
|
||||
$this->addField(new IntField('arg1', null));
|
||||
$this->addField(new IntField('arg2', null));
|
||||
$this->addField(new IntField('arg3', null));
|
||||
}
|
||||
|
||||
function execute($image)
|
||||
{
|
||||
$filter = constant($this->fields['filter']->value);
|
||||
$arg1 = $this->fields['arg1']->value;
|
||||
$arg2 = $this->fields['arg2']->value;
|
||||
$arg3 = $this->fields['arg3']->value;
|
||||
|
||||
return $image->applyFilter($filter, $arg1, $arg2, $arg3);
|
||||
}
|
||||
}
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new SelectField('filter', [
|
||||
'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',
|
||||
])
|
||||
);
|
||||
$this->addField(new IntField('arg1', null));
|
||||
$this->addField(new IntField('arg2', null));
|
||||
$this->addField(new IntField('arg3', null));
|
||||
}
|
||||
|
||||
public function execute($image)
|
||||
{
|
||||
$filter = constant($this->fields['filter']->value);
|
||||
$arg1 = $this->fields['arg1']->value;
|
||||
$arg2 = $this->fields['arg2']->value;
|
||||
$arg3 = $this->fields['arg3']->value;
|
||||
|
||||
return $image->applyFilter($filter, $arg1, $arg2, $arg3);
|
||||
}
|
||||
}
|
||||
|
@@ -1,32 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_applyMask extends Demo
|
||||
{
|
||||
public $order = 600;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new FileSelectField('mask', 'masks'));
|
||||
$this->addField(new CoordinateField('left', 10));
|
||||
$this->addField(new CoordinateField('top', '30%'));
|
||||
|
||||
if (!$this->request->get('mask'))
|
||||
$this->request->set('mask', 'mask-circle.gif');
|
||||
}
|
||||
|
||||
function execute($image)
|
||||
{
|
||||
$mask = WideImage::load(DEMO_PATH . 'masks/' . $this->fields['mask']->value);
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
|
||||
return $image->applyMask($mask, $left, $top);
|
||||
}
|
||||
|
||||
function getFormat()
|
||||
{
|
||||
return 'png';
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_applyMask extends Demo
|
||||
{
|
||||
public $order = 600;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new FileSelectField('mask', 'masks'));
|
||||
$this->addField(new CoordinateField('left', 10));
|
||||
$this->addField(new CoordinateField('top', '30%'));
|
||||
|
||||
if (!$this->request->get('mask')) {
|
||||
$this->request->set('mask', 'mask-circle.gif');
|
||||
}
|
||||
}
|
||||
|
||||
public function execute($image)
|
||||
{
|
||||
$mask = WideImage::load(DEMO_PATH.'masks/'.$this->fields['mask']->value);
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
|
||||
return $image->applyMask($mask, $left, $top);
|
||||
}
|
||||
|
||||
public function getFormat()
|
||||
{
|
||||
return 'png';
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_asGrayscale extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
return $img->asGrayscale();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_asGrayscale extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
public function execute($img, $request)
|
||||
{
|
||||
return $img->asGrayscale();
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_asNegative extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
return $img->asNegative();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_asNegative extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
public function execute($img, $request)
|
||||
{
|
||||
return $img->asNegative();
|
||||
}
|
||||
}
|
||||
|
@@ -1,26 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_autoCrop extends Demo
|
||||
{
|
||||
public $order = 1050;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new IntField('margin', 0));
|
||||
$this->addField(new IntField('rgb_threshold', 0));
|
||||
$this->addField(new IntField('pixel_cutoff', 1));
|
||||
$this->addField(new IntField('base_color', null, 'Index of the color'));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$margin = $this->fields['margin']->value;
|
||||
$rgb_threshold = $this->fields['rgb_threshold']->value;
|
||||
$pixel_cutoff = $this->fields['pixel_cutoff']->value;
|
||||
$base_color = $this->fields['base_color']->value;
|
||||
|
||||
return $image->autoCrop($margin, $rgb_threshold, $pixel_cutoff, $base_color);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_autoCrop extends Demo
|
||||
{
|
||||
public $order = 1050;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new IntField('margin', 0));
|
||||
$this->addField(new IntField('rgb_threshold', 0));
|
||||
$this->addField(new IntField('pixel_cutoff', 1));
|
||||
$this->addField(new IntField('base_color', null, 'Index of the color'));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$margin = $this->fields['margin']->value;
|
||||
$rgb_threshold = $this->fields['rgb_threshold']->value;
|
||||
$pixel_cutoff = $this->fields['pixel_cutoff']->value;
|
||||
$base_color = $this->fields['base_color']->value;
|
||||
|
||||
return $image->autoCrop($margin, $rgb_threshold, $pixel_cutoff, $base_color);
|
||||
}
|
||||
}
|
||||
|
@@ -1,19 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_correctGamma extends Demo
|
||||
{
|
||||
public $order = 2050;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new FloatField('in_gamma', 1.1));
|
||||
$this->addField(new FloatField('out_gamma', 3.7));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->correctGamma($this->fval('in_gamma'), $this->fval('out_gamma'));
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_correctGamma extends Demo
|
||||
{
|
||||
public $order = 2050;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new FloatField('in_gamma', 1.1));
|
||||
$this->addField(new FloatField('out_gamma', 3.7));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->correctGamma($this->fval('in_gamma'), $this->fval('out_gamma'));
|
||||
}
|
||||
}
|
||||
|
@@ -1,26 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_crop extends Demo
|
||||
{
|
||||
public $order = 1000;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('left', 10));
|
||||
$this->addField(new CoordinateField('top', 20));
|
||||
$this->addField(new CoordinateField('width', 120));
|
||||
$this->addField(new CoordinateField('height', 60));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
$width = $this->fields['width']->value;
|
||||
$height = $this->fields['height']->value;
|
||||
|
||||
return $image->crop($left, $top, $width, $height);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_crop extends Demo
|
||||
{
|
||||
public $order = 1000;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('left', 10));
|
||||
$this->addField(new CoordinateField('top', 20));
|
||||
$this->addField(new CoordinateField('width', 120));
|
||||
$this->addField(new CoordinateField('height', 60));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
$width = $this->fields['width']->value;
|
||||
$height = $this->fields['height']->value;
|
||||
|
||||
return $image->crop($left, $top, $width, $height);
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_flip extends Demo
|
||||
{
|
||||
public $order = 1200;
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->flip();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_flip extends Demo
|
||||
{
|
||||
public $order = 1200;
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->flip();
|
||||
}
|
||||
}
|
||||
|
@@ -1,54 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_getCanvas extends Demo
|
||||
{
|
||||
public $order = 1300;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new Field('text', 'Hello world!'));
|
||||
$this->addField(new CoordinateField('x', 'middle'));
|
||||
$this->addField(new CoordinateField('y', 'bottom-5'));
|
||||
$this->addField(new IntField('angle', 5));
|
||||
$this->addField(new FileSelectField('font', 'fonts', array('show' => false, 'pattern' => '/(.*)\.ttf$/', 'default' => 'VeraSe.ttf')));
|
||||
$this->addField(new IntField('size', 18));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$text = $this->fields['text']->value;
|
||||
$x = $this->fields['x']->value;
|
||||
$y = $this->fields['y']->value;
|
||||
$angle = $this->fields['angle']->value;
|
||||
$font = $this->fields['font']->value;
|
||||
$font_size = $this->fields['size']->value;
|
||||
|
||||
$canvas = $image->getCanvas();
|
||||
|
||||
$canvas->filledRectangle(10, 10, 80, 40, $image->allocateColor(255, 127, 255));
|
||||
$canvas->line(60, 80, 30, 100, $image->allocateColor(255, 0, 0));
|
||||
|
||||
$font_file = DEMO_PATH . 'fonts/' . $font;
|
||||
|
||||
$canvas->useFont($font_file, $font_size, $image->allocateColor(0, 0, 0));
|
||||
$canvas->writeText("$x+1", "$y+1", $text, $angle);
|
||||
|
||||
$canvas->useFont($font_file, $font_size, $image->allocateColor(200, 220, 255));
|
||||
$canvas->writeText($x, $y, $text, $angle);
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
function et($name)
|
||||
{
|
||||
return htmlentities($this->fval($name));
|
||||
}
|
||||
|
||||
function text()
|
||||
{
|
||||
echo "This demo executes:
|
||||
/**
|
||||
*/
|
||||
class Demo_getCanvas extends Demo
|
||||
{
|
||||
public $order = 1300;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new Field('text', 'Hello world!'));
|
||||
$this->addField(new CoordinateField('x', 'middle'));
|
||||
$this->addField(new CoordinateField('y', 'bottom-5'));
|
||||
$this->addField(new IntField('angle', 5));
|
||||
$this->addField(new FileSelectField('font', 'fonts', ['show' => false, 'pattern' => '/(.*)\.ttf$/', 'default' => 'VeraSe.ttf']));
|
||||
$this->addField(new IntField('size', 18));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$text = $this->fields['text']->value;
|
||||
$x = $this->fields['x']->value;
|
||||
$y = $this->fields['y']->value;
|
||||
$angle = $this->fields['angle']->value;
|
||||
$font = $this->fields['font']->value;
|
||||
$font_size = $this->fields['size']->value;
|
||||
|
||||
$canvas = $image->getCanvas();
|
||||
|
||||
$canvas->filledRectangle(10, 10, 80, 40, $image->allocateColor(255, 127, 255));
|
||||
$canvas->line(60, 80, 30, 100, $image->allocateColor(255, 0, 0));
|
||||
|
||||
$font_file = DEMO_PATH.'fonts/'.$font;
|
||||
|
||||
$canvas->useFont($font_file, $font_size, $image->allocateColor(0, 0, 0));
|
||||
$canvas->writeText("$x+1", "$y+1", $text, $angle);
|
||||
|
||||
$canvas->useFont($font_file, $font_size, $image->allocateColor(200, 220, 255));
|
||||
$canvas->writeText($x, $y, $text, $angle);
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
public function et($name)
|
||||
{
|
||||
return htmlentities($this->fval($name));
|
||||
}
|
||||
|
||||
public function text()
|
||||
{
|
||||
echo "This demo executes:
|
||||
<pre>
|
||||
\$canvas->filledRectangle(10, 10, 80, 40, \$img->allocateColor(255, 127, 255));
|
||||
\$canvas->line(60, 80, 30, 100, \$img->allocateColor(255, 0, 0));
|
||||
@@ -59,5 +58,5 @@
|
||||
\$canvas->useFont('{$this->et('font')}', '{$this->et('size')}', \$image->allocateColor(200, 220, 255));
|
||||
\$canvas->writeText('{$this->et('x')}', '{$this->et('y')}', '{$this->et('text')}', {$this->et('angle')});
|
||||
</pre>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,28 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_getChannels extends Demo
|
||||
{
|
||||
public $order = 500;
|
||||
|
||||
protected $channels = array('red', 'green', 'blue', 'alpha');
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new CheckboxField('red', true));
|
||||
$this->addField(new CheckboxField('green', false));
|
||||
$this->addField(new CheckboxField('blue', true));
|
||||
$this->addField(new CheckboxField('alpha', false));
|
||||
}
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
$on = array();
|
||||
foreach ($this->channels as $name)
|
||||
if ($this->fields[$name]->value)
|
||||
$on[] = $name;
|
||||
|
||||
return $img->getChannels($on);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_getChannels extends Demo
|
||||
{
|
||||
public $order = 500;
|
||||
|
||||
protected $channels = ['red', 'green', 'blue', 'alpha'];
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new CheckboxField('red', true));
|
||||
$this->addField(new CheckboxField('green', false));
|
||||
$this->addField(new CheckboxField('blue', true));
|
||||
$this->addField(new CheckboxField('alpha', false));
|
||||
}
|
||||
|
||||
public function execute($img, $request)
|
||||
{
|
||||
$on = [];
|
||||
foreach ($this->channels as $name) {
|
||||
if ($this->fields[$name]->value) {
|
||||
$on[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $img->getChannels($on);
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_getMask extends Demo
|
||||
{
|
||||
public $order = 550;
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
return $img->getMask();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_getMask extends Demo
|
||||
{
|
||||
public $order = 550;
|
||||
|
||||
public function execute($img, $request)
|
||||
{
|
||||
return $img->getMask();
|
||||
}
|
||||
}
|
||||
|
@@ -1,31 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_merge extends Demo
|
||||
{
|
||||
public $order = 800;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new FileSelectField('overlay', 'images', array('default' => '6-logo.gif')));
|
||||
$this->addField(new CoordinateField('left', 'right-10'));
|
||||
$this->addField(new CoordinateField('top', 'bottom-15%'));
|
||||
$this->addField(new IntField('opacity', 50));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$overlay = WideImage::load(DEMO_PATH . 'images/' . $this->fields['overlay']->value);
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
$opacity = $this->fields['opacity']->value;
|
||||
|
||||
return $image->merge($overlay, $left, $top, $opacity);
|
||||
}
|
||||
|
||||
function text()
|
||||
{
|
||||
echo "For alpha images, set opacity=100, otherwise alpha channel won't work.";
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_merge extends Demo
|
||||
{
|
||||
public $order = 800;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new FileSelectField('overlay', 'images', ['default' => '6-logo.gif']));
|
||||
$this->addField(new CoordinateField('left', 'right-10'));
|
||||
$this->addField(new CoordinateField('top', 'bottom-15%'));
|
||||
$this->addField(new IntField('opacity', 50));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$overlay = WideImage::load(DEMO_PATH.'images/'.$this->fields['overlay']->value);
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
$opacity = $this->fields['opacity']->value;
|
||||
|
||||
return $image->merge($overlay, $left, $top, $opacity);
|
||||
}
|
||||
|
||||
public function text()
|
||||
{
|
||||
echo "For alpha images, set opacity=100, otherwise alpha channel won't work.";
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_mirror extends Demo
|
||||
{
|
||||
public $order = 1150;
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->mirror();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_mirror extends Demo
|
||||
{
|
||||
public $order = 1150;
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->mirror();
|
||||
}
|
||||
}
|
||||
|
@@ -1,26 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_resize extends Demo
|
||||
{
|
||||
public $order = 900;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('width', 120));
|
||||
$this->addField(new CoordinateField('height', null));
|
||||
$this->addField(new SelectField('fit', array('inside', 'fill', 'outside')));
|
||||
$this->addField(new SelectField('scale', array('any', 'down', 'up')));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$width = $this->fields['width']->value;
|
||||
$height = $this->fields['height']->value;
|
||||
$fit = $this->fields['fit']->value;
|
||||
$scale = $this->fields['scale']->value;
|
||||
|
||||
return $image->resize($width, $height, $fit, $scale);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_resize extends Demo
|
||||
{
|
||||
public $order = 900;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('width', 120));
|
||||
$this->addField(new CoordinateField('height', null));
|
||||
$this->addField(new SelectField('fit', ['inside', 'fill', 'outside']));
|
||||
$this->addField(new SelectField('scale', ['any', 'down', 'up']));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$width = $this->fields['width']->value;
|
||||
$height = $this->fields['height']->value;
|
||||
$fit = $this->fields['fit']->value;
|
||||
$scale = $this->fields['scale']->value;
|
||||
|
||||
return $image->resize($width, $height, $fit, $scale);
|
||||
}
|
||||
}
|
||||
|
@@ -1,32 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_resizeCanvas extends Demo
|
||||
{
|
||||
public $order = 910;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('width', '100%+30'));
|
||||
$this->addField(new CoordinateField('height', 200));
|
||||
$this->addField(new CoordinateField('left', '2'));
|
||||
$this->addField(new CoordinateField('top', 'bottom-10'));
|
||||
$this->addField(new ColorField('color', 'ffffff'));
|
||||
$this->addField(new SelectField('scale', array('any', 'down', 'up'), 'any'));
|
||||
$this->addField(new CheckboxField('merge', false, "Merge or copy over"));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$width = $this->fields['width']->value;
|
||||
$height = $this->fields['height']->value;
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
$color = $this->fields['color']->value;
|
||||
$scale = $this->fields['scale']->value;
|
||||
$merge = $this->fields['merge']->value;
|
||||
|
||||
return $image->resizeCanvas($width, $height, $left, $top, $color ? hexdec($color) : null, $scale, $merge);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_resizeCanvas extends Demo
|
||||
{
|
||||
public $order = 910;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('width', '100%+30'));
|
||||
$this->addField(new CoordinateField('height', 200));
|
||||
$this->addField(new CoordinateField('left', '2'));
|
||||
$this->addField(new CoordinateField('top', 'bottom-10'));
|
||||
$this->addField(new ColorField('color', 'ffffff'));
|
||||
$this->addField(new SelectField('scale', ['any', 'down', 'up'], 'any'));
|
||||
$this->addField(new CheckboxField('merge', false, 'Merge or copy over'));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$width = $this->fields['width']->value;
|
||||
$height = $this->fields['height']->value;
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
$color = $this->fields['color']->value;
|
||||
$scale = $this->fields['scale']->value;
|
||||
$merge = $this->fields['merge']->value;
|
||||
|
||||
return $image->resizeCanvas($width, $height, $left, $top, $color ? hexdec($color) : null, $scale, $merge);
|
||||
}
|
||||
}
|
||||
|
@@ -1,22 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_rotate extends Demo
|
||||
{
|
||||
public $order = 1100;
|
||||
/**
|
||||
*/
|
||||
class Demo_rotate extends Demo
|
||||
{
|
||||
public $order = 1100;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new AngleField('angle', 25));
|
||||
$this->addField(new ColorField('color', ''));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$angle = $this->fields['angle']->value;
|
||||
$color = $this->fields['color']->value;
|
||||
|
||||
return $image->rotate($angle, $color ? hexdec($color) : null);
|
||||
}
|
||||
}
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new AngleField('angle', 25));
|
||||
$this->addField(new ColorField('color', ''));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$angle = $this->fields['angle']->value;
|
||||
$color = $this->fields['color']->value;
|
||||
|
||||
return $image->rotate($angle, $color ? hexdec($color) : null);
|
||||
}
|
||||
}
|
||||
|
@@ -1,42 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_roundCorners extends Demo
|
||||
{
|
||||
public $order = 1075;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new IntField('radius', 30));
|
||||
$this->addField(new ColorField('color', 'ffffff'));
|
||||
$this->addField(new IntField('smoothness', 2));
|
||||
|
||||
$this->addField(new CheckboxField('top-left', true));
|
||||
$this->addField(new CheckboxField('top-right', true));
|
||||
$this->addField(new CheckboxField('bottom-right', true));
|
||||
$this->addField(new CheckboxField('bottom-left', true));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$color = $this->fields['color']->value;
|
||||
$radius = $this->fields['radius']->value;
|
||||
$smoothness = $this->fields['smoothness']->value;
|
||||
|
||||
$corners = 0;
|
||||
if ($this->fval('top-left'))
|
||||
$corners += WideImage::SIDE_TOP_LEFT;
|
||||
|
||||
if ($this->fval('top-right'))
|
||||
$corners += WideImage::SIDE_TOP_RIGHT;
|
||||
|
||||
if ($this->fval('bottom-right'))
|
||||
$corners += WideImage::SIDE_BOTTOM_RIGHT;
|
||||
|
||||
if ($this->fval('bottom-left'))
|
||||
$corners += WideImage::SIDE_BOTTOM_LEFT;
|
||||
|
||||
return $image->roundCorners($radius, $color ? hexdec($color) : null, $smoothness, $corners);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_roundCorners extends Demo
|
||||
{
|
||||
public $order = 1075;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new IntField('radius', 30));
|
||||
$this->addField(new ColorField('color', 'ffffff'));
|
||||
$this->addField(new IntField('smoothness', 2));
|
||||
|
||||
$this->addField(new CheckboxField('top-left', true));
|
||||
$this->addField(new CheckboxField('top-right', true));
|
||||
$this->addField(new CheckboxField('bottom-right', true));
|
||||
$this->addField(new CheckboxField('bottom-left', true));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$color = $this->fields['color']->value;
|
||||
$radius = $this->fields['radius']->value;
|
||||
$smoothness = $this->fields['smoothness']->value;
|
||||
|
||||
$corners = 0;
|
||||
if ($this->fval('top-left')) {
|
||||
$corners += WideImage::SIDE_TOP_LEFT;
|
||||
}
|
||||
|
||||
if ($this->fval('top-right')) {
|
||||
$corners += WideImage::SIDE_TOP_RIGHT;
|
||||
}
|
||||
|
||||
if ($this->fval('bottom-right')) {
|
||||
$corners += WideImage::SIDE_BOTTOM_RIGHT;
|
||||
}
|
||||
|
||||
if ($this->fval('bottom-left')) {
|
||||
$corners += WideImage::SIDE_BOTTOM_LEFT;
|
||||
}
|
||||
|
||||
return $image->roundCorners($radius, $color ? hexdec($color) : null, $smoothness, $corners);
|
||||
}
|
||||
}
|
||||
|
@@ -1,20 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_unsharp extends Demo
|
||||
{
|
||||
public $order = 1350;
|
||||
/**
|
||||
*/
|
||||
class Demo_unsharp extends Demo
|
||||
{
|
||||
public $order = 1350;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new IntField('amount', 300));
|
||||
$this->addField(new IntField('radius', 3));
|
||||
$this->addField(new IntField('threshold', 2));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->unsharp($this->fields['amount']->value, $this->fields['radius']->value, $this->fields['threshold']->value);
|
||||
}
|
||||
}
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new IntField('amount', 300));
|
||||
$this->addField(new IntField('radius', 3));
|
||||
$this->addField(new IntField('threshold', 2));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->unsharp($this->fields['amount']->value, $this->fields['radius']->value, $this->fields['threshold']->value);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
include('../lib/WideImage.php');
|
||||
|
||||
include '../lib/WideImage.php';
|
||||
|
||||
$img = WideImage::createTrueColorImage(400, 200);
|
||||
$canvas = $img->getCanvas();
|
||||
@@ -31,40 +32,39 @@ $text = '#j';
|
||||
// First we create our bounding box
|
||||
$bbox = imageftbbox($font_size, $angle, $font, $text);
|
||||
|
||||
|
||||
function normalize_bbox($bbox)
|
||||
{
|
||||
return array(
|
||||
'up-left' => array('x' => $bbox[6], 'y' => $bbox[7]),
|
||||
'up-right' => array('x' => $bbox[4], 'y' => $bbox[5]),
|
||||
'down-left' => array('x' => $bbox[0], 'y' => $bbox[1]),
|
||||
'down-right' => array('x' => $bbox[2], 'y' => $bbox[3]),
|
||||
);
|
||||
return [
|
||||
'up-left' => ['x' => $bbox[6], 'y' => $bbox[7]],
|
||||
'up-right' => ['x' => $bbox[4], 'y' => $bbox[5]],
|
||||
'down-left' => ['x' => $bbox[0], 'y' => $bbox[1]],
|
||||
'down-right' => ['x' => $bbox[2], 'y' => $bbox[3]],
|
||||
];
|
||||
}
|
||||
|
||||
function outer_box($box)
|
||||
{
|
||||
return array(
|
||||
'left' => min($box['up-left']['x'], $box['up-right']['x'], $box['down-left']['x'], $box['down-right']['x']),
|
||||
'top' => min($box['up-left']['y'], $box['up-right']['y'], $box['down-left']['y'], $box['down-right']['y']),
|
||||
'right' => max($box['up-left']['x'], $box['up-right']['x'], $box['down-left']['x'], $box['down-right']['x']),
|
||||
'bottom' => max($box['up-left']['y'], $box['up-right']['y'], $box['down-left']['y'], $box['down-right']['y'])
|
||||
);
|
||||
return [
|
||||
'left' => min($box['up-left']['x'], $box['up-right']['x'], $box['down-left']['x'], $box['down-right']['x']),
|
||||
'top' => min($box['up-left']['y'], $box['up-right']['y'], $box['down-left']['y'], $box['down-right']['y']),
|
||||
'right' => max($box['up-left']['x'], $box['up-right']['x'], $box['down-left']['x'], $box['down-right']['x']),
|
||||
'bottom' => max($box['up-left']['y'], $box['up-right']['y'], $box['down-left']['y'], $box['down-right']['y']),
|
||||
];
|
||||
}
|
||||
|
||||
$box = normalize_bbox($bbox);
|
||||
|
||||
// This is our cordinates for X and Y
|
||||
#$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
|
||||
#$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
|
||||
#$x = 300;
|
||||
#$y = 175;
|
||||
//$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
|
||||
//$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
|
||||
//$x = 300;
|
||||
//$y = 175;
|
||||
|
||||
$obox = outer_box(normalize_bbox(imageftbbox($font_size, $angle, $font, '')));
|
||||
$obox = outer_box(normalize_bbox(imageftbbox($font_size, $angle, $font, $text)));
|
||||
|
||||
#$x = imagesx($im) - $obox['right'] - 1;
|
||||
#$y = imagesy($im) - $obox['bottom'] - 1;
|
||||
//$x = imagesx($im) - $obox['right'] - 1;
|
||||
//$y = imagesy($im) - $obox['bottom'] - 1;
|
||||
$x = 0;
|
||||
$y = 0;
|
||||
|
||||
@@ -72,9 +72,8 @@ $gc = imagecolorallocate($im, 255, 200, 200);
|
||||
imageline($im, imagesx($im) / 2, 0, imagesx($im) / 2, imagesy($im), $gc);
|
||||
imageline($im, 0, imagesy($im) / 2, imagesx($im), imagesy($im) / 2, $gc);
|
||||
|
||||
|
||||
imagefttext($im, $font_size, $angle, $x, $y, $black, $font, $text);
|
||||
#imagefttext($im, $font_size, $angle, $x, $y, $black, $font, 'aj');
|
||||
//imagefttext($im, $font_size, $angle, $x, $y, $black, $font, 'aj');
|
||||
|
||||
$c = imagecolorallocate($im, 0, 255, 0);
|
||||
imageline($im, $box['up-left']['x'] + $x, $box['up-left']['y'] + $y, $box['up-right']['x'] + $x, $box['up-right']['y'] + $y, $c);
|
||||
@@ -91,7 +90,6 @@ imageline($im, $obox['left'] + $x, $obox['bottom'] + $y, $obox['left'] + $x, $ob
|
||||
|
||||
imagefilledellipse($im, $x, $y, 3, 3, imagecolorallocate($im, 255, 0, 0));
|
||||
|
||||
|
||||
// Output to browser
|
||||
header('Content-type: image/png');
|
||||
|
||||
|
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class AngleField extends IntField
|
||||
{
|
||||
function __construct($name, $default, $hint = 'In degrees clockwise, negative values accepted')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class AngleField extends IntField
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'In degrees clockwise, negative values accepted')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
}
|
||||
|
@@ -1,22 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class CheckboxField extends Field
|
||||
{
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default ? '1' : null) === '1';
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
if ($this->value)
|
||||
$chk = 'checked="checked"';
|
||||
else
|
||||
$chk = '';
|
||||
|
||||
echo '<input type="hidden" name="' . $name . '" id="' . $id . '_val" value="' . ($this->value ? '1' : '') . '" />';
|
||||
echo '<input type="checkbox" ' . $chk . ' name="' . $name . '_cb" id="' . $id . '" value="1" onclick="document.getElementById(\'' . $id . '_val\').value = Number(this.checked);" />';
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class CheckboxField extends Field
|
||||
{
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default ? '1' : null) === '1';
|
||||
}
|
||||
|
||||
public function renderBody($name, $id)
|
||||
{
|
||||
if ($this->value) {
|
||||
$chk = 'checked="checked"';
|
||||
} else {
|
||||
$chk = '';
|
||||
}
|
||||
|
||||
echo '<input type="hidden" name="'.$name.'" id="'.$id.'_val" value="'.($this->value ? '1' : '').'" />';
|
||||
echo '<input type="checkbox" '.$chk.' name="'.$name.'_cb" id="'.$id.'" value="1" onclick="document.getElementById(\''.$id.'_val\').value = Number(this.checked);" />';
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class CheckboxSetField extends Field
|
||||
{
|
||||
public $options;
|
||||
public $request;
|
||||
|
||||
function __construct($name, $options)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = array();
|
||||
if (is_array($request->get($this->name)))
|
||||
foreach ($request->get($this->name) as $val)
|
||||
if (in_array($val, $this->options))
|
||||
$this->value[] = $val;
|
||||
}
|
||||
|
||||
function render()
|
||||
{
|
||||
$request = $this->request;
|
||||
foreach ($this->options as $option)
|
||||
{
|
||||
if (is_array($request->get($this->name)) && in_array($option, $request->get($this->name)))
|
||||
$chk = 'checked="checked"';
|
||||
else
|
||||
$chk = '';
|
||||
/**
|
||||
*/
|
||||
class CheckboxSetField extends Field
|
||||
{
|
||||
public $options;
|
||||
public $request;
|
||||
|
||||
$name = $this->name . '[]';
|
||||
$id = $this->name . '_' . $option;
|
||||
echo '<input type="checkbox" ' . $chk . ' name="' . $name . '" id="' . $id . '" value="' . $option . '" />';
|
||||
echo '<label for="' . $id . '">' . $option . '</label> ';
|
||||
}
|
||||
}
|
||||
|
||||
function getURLValue()
|
||||
{
|
||||
$v = '';
|
||||
foreach ($this->value as $value)
|
||||
$v .= $this->name . '[]=' . $value . '&';
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct($name, $options)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = [];
|
||||
if (is_array($request->get($this->name))) {
|
||||
foreach ($request->get($this->name) as $val) {
|
||||
if (in_array($val, $this->options)) {
|
||||
$this->value[] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$request = $this->request;
|
||||
foreach ($this->options as $option) {
|
||||
if (is_array($request->get($this->name)) && in_array($option, $request->get($this->name))) {
|
||||
$chk = 'checked="checked"';
|
||||
} else {
|
||||
$chk = '';
|
||||
}
|
||||
|
||||
$name = $this->name.'[]';
|
||||
$id = $this->name.'_'.$option;
|
||||
echo '<input type="checkbox" '.$chk.' name="'.$name.'" id="'.$id.'" value="'.$option.'" />';
|
||||
echo '<label for="'.$id.'">'.$option.'</label> ';
|
||||
}
|
||||
}
|
||||
|
||||
public function getURLValue()
|
||||
{
|
||||
$v = '';
|
||||
foreach ($this->value as $value) {
|
||||
$v .= $this->name.'[]='.$value.'&';
|
||||
}
|
||||
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
@@ -1,25 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class ColorField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'RRGGBB hex, leave blank for transparent background')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$c = $request->getColor($this->name, $this->default);
|
||||
if ($c === '')
|
||||
$this->value = null;
|
||||
else
|
||||
$this->value = str_pad(dechex(hexdec($c)), 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class ColorField extends Field
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'RRGGBB hex, leave blank for transparent background')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$c = $request->getColor($this->name, $this->default);
|
||||
if ($c === '') {
|
||||
$this->value = null;
|
||||
} else {
|
||||
$this->value = str_pad(dechex(hexdec($c)), 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class CoordinateField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'Smart coordinate')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->getCoordinate($this->name, $this->default);
|
||||
if ($this->value > 1000)
|
||||
$this->value = 1000;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class CoordinateField extends Field
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'Smart coordinate')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->getCoordinate($this->name, $this->default);
|
||||
if ($this->value > 1000) {
|
||||
$this->value = 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,63 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo
|
||||
{
|
||||
public $name;
|
||||
public $format = null;
|
||||
public $fields = array();
|
||||
public $order = 1000;
|
||||
|
||||
function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
}
|
||||
|
||||
static function create($name)
|
||||
{
|
||||
$file = DEMO_PATH . '/demos/' . $name . '.php';
|
||||
if (!file_exists($file))
|
||||
throw new Exception("Invalid demo: {$name}");
|
||||
include $file;
|
||||
$className = 'Demo_' . $name;
|
||||
$demo = new $className($name);
|
||||
$demo->request = Request::getInstance();
|
||||
$demo->init();
|
||||
foreach ($demo->fields as $field)
|
||||
{
|
||||
$field->request = Request::getInstance();
|
||||
$field->init(Request::getInstance());
|
||||
}
|
||||
return $demo;
|
||||
}
|
||||
|
||||
function getFormat()
|
||||
{
|
||||
return 'as input';
|
||||
}
|
||||
|
||||
function addField($field)
|
||||
{
|
||||
$this->fields[$field->name] = $field;
|
||||
}
|
||||
|
||||
function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function text()
|
||||
{
|
||||
}
|
||||
|
||||
function fval($name)
|
||||
{
|
||||
return $this->fields[$name]->value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class Demo
|
||||
{
|
||||
public $name;
|
||||
public $format = null;
|
||||
public $fields = [];
|
||||
public $order = 1000;
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
public static function create($name)
|
||||
{
|
||||
$file = DEMO_PATH.'/demos/'.$name.'.php';
|
||||
if (!file_exists($file)) {
|
||||
throw new Exception("Invalid demo: {$name}");
|
||||
}
|
||||
include $file;
|
||||
$className = 'Demo_'.$name;
|
||||
$demo = new $className($name);
|
||||
$demo->request = Request::getInstance();
|
||||
$demo->init();
|
||||
foreach ($demo->fields as $field) {
|
||||
$field->request = Request::getInstance();
|
||||
$field->init(Request::getInstance());
|
||||
}
|
||||
|
||||
return $demo;
|
||||
}
|
||||
|
||||
public function getFormat()
|
||||
{
|
||||
return 'as input';
|
||||
}
|
||||
|
||||
public function addField($field)
|
||||
{
|
||||
$this->fields[$field->name] = $field;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function text()
|
||||
{
|
||||
}
|
||||
|
||||
public function fval($name)
|
||||
{
|
||||
return $this->fields[$name]->value;
|
||||
}
|
||||
}
|
||||
|
@@ -1,52 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Field
|
||||
{
|
||||
public $name;
|
||||
public $default;
|
||||
public $value;
|
||||
public $request;
|
||||
public $hint;
|
||||
|
||||
function __construct($name, $default = null, $hint = '')
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->default = $default;
|
||||
|
||||
if ($hint == '')
|
||||
$hint = $name;
|
||||
|
||||
$this->hint = $hint;
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default);
|
||||
}
|
||||
|
||||
function render()
|
||||
{
|
||||
$id = htmlentities($this->name);
|
||||
echo '<label style="background-color: #c0c0c0; padding: 5px; margin: 2px;" for="imgparam_' . $id . '" title="' . htmlentities($this->hint) . '">';
|
||||
echo $this->name . ': ';
|
||||
$this->renderBody($id, 'imgparam_' . $id);
|
||||
echo '</label> ';
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
echo '<input id="' . $id . '" type="text" size="15" name="' . $name . '" value="' . $this->getRenderValue() . '" />';
|
||||
}
|
||||
|
||||
function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
function getUrlValue()
|
||||
{
|
||||
return urlencode($this->name) . '=' . urlencode($this->value);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Field
|
||||
{
|
||||
public $name;
|
||||
public $default;
|
||||
public $value;
|
||||
public $request;
|
||||
public $hint;
|
||||
|
||||
public function __construct($name, $default = null, $hint = '')
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->default = $default;
|
||||
|
||||
if ($hint == '') {
|
||||
$hint = $name;
|
||||
}
|
||||
|
||||
$this->hint = $hint;
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$id = htmlentities($this->name);
|
||||
echo '<label style="background-color: #c0c0c0; padding: 5px; margin: 2px;" for="imgparam_'.$id.'" title="'.htmlentities($this->hint).'">';
|
||||
echo $this->name.': ';
|
||||
$this->renderBody($id, 'imgparam_'.$id);
|
||||
echo '</label> ';
|
||||
}
|
||||
|
||||
public function renderBody($name, $id)
|
||||
{
|
||||
echo '<input id="'.$id.'" type="text" size="15" name="'.$name.'" value="'.$this->getRenderValue().'" />';
|
||||
}
|
||||
|
||||
public function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getUrlValue()
|
||||
{
|
||||
return urlencode($this->name).'='.urlencode($this->value);
|
||||
}
|
||||
}
|
||||
|
@@ -1,83 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class FileSelectField extends Field
|
||||
{
|
||||
public $request;
|
||||
public $files = array();
|
||||
public $options;
|
||||
|
||||
function __construct($name, $path, $options = array())
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->path = $path;
|
||||
$this->options = $options;
|
||||
|
||||
if (!isset($options['show']))
|
||||
$this->options['show'] = true;
|
||||
|
||||
if (!isset($options['pattern']))
|
||||
$this->options['pattern'] = '/(.*)/';
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = null;
|
||||
$di = new DirectoryIterator(DEMO_PATH . $this->path);
|
||||
foreach ($di as $file)
|
||||
if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0 && preg_match($this->options['pattern'], $file->getFilename()))
|
||||
{
|
||||
$this->files[] = $file->getFilename();
|
||||
if ($this->value === null && isset($this->options['default']) && $this->options['default'] == $file->getFilename())
|
||||
$this->value = $this->options['default'];
|
||||
|
||||
if ($this->request->get($this->name) == $file->getFilename())
|
||||
$this->value = $file->getFilename();
|
||||
}
|
||||
|
||||
sort($this->files);
|
||||
|
||||
if (!$this->value && count($this->files) > 0)
|
||||
$this->value = $this->files[0];
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
if ($this->options['show'])
|
||||
{
|
||||
$onch = "document.getElementById('sel_{$id}').src = '{$this->path}/' + this.options[this.selectedIndex].value;";
|
||||
}
|
||||
else
|
||||
$onch = '';
|
||||
|
||||
echo '<select id="' . $id . '" name="' . $name . '" onchange="' . $onch . '">';
|
||||
$selected_file = null;
|
||||
foreach ($this->files as $file)
|
||||
{
|
||||
if ($this->value == $file)
|
||||
{
|
||||
$sel = 'selected="selected"';
|
||||
$selected_file = $file;
|
||||
}
|
||||
else
|
||||
$sel = '';
|
||||
|
||||
echo '<option ' . $sel . ' value="' . $file . '">' . $file . '</option>' . PHP_EOL;
|
||||
}
|
||||
echo '</select>';
|
||||
|
||||
if ($this->options['show'] && $selected_file)
|
||||
{
|
||||
echo '<div style="display: inline; min-width: 50px; min-height: 50px">';
|
||||
echo '<img style="position: absolute" id="sel_' . $id . '" width="50" src="' . $this->path . '/' . $selected_file . '" /> ';
|
||||
echo " ";
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function getURLValue()
|
||||
{
|
||||
return $this->name . '=' . $this->value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class FileSelectField extends Field
|
||||
{
|
||||
public $request;
|
||||
public $files = [];
|
||||
public $options;
|
||||
|
||||
public function __construct($name, $path, $options = [])
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->path = $path;
|
||||
$this->options = $options;
|
||||
|
||||
if (!isset($options['show'])) {
|
||||
$this->options['show'] = true;
|
||||
}
|
||||
|
||||
if (!isset($options['pattern'])) {
|
||||
$this->options['pattern'] = '/(.*)/';
|
||||
}
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = null;
|
||||
$di = new DirectoryIterator(DEMO_PATH.$this->path);
|
||||
foreach ($di as $file) {
|
||||
if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0 && preg_match($this->options['pattern'], $file->getFilename())) {
|
||||
$this->files[] = $file->getFilename();
|
||||
if ($this->value === null && isset($this->options['default']) && $this->options['default'] == $file->getFilename()) {
|
||||
$this->value = $this->options['default'];
|
||||
}
|
||||
|
||||
if ($this->request->get($this->name) == $file->getFilename()) {
|
||||
$this->value = $file->getFilename();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort($this->files);
|
||||
|
||||
if (!$this->value && count($this->files) > 0) {
|
||||
$this->value = $this->files[0];
|
||||
}
|
||||
}
|
||||
|
||||
public function renderBody($name, $id)
|
||||
{
|
||||
if ($this->options['show']) {
|
||||
$onch = "document.getElementById('sel_{$id}').src = '{$this->path}/' + this.options[this.selectedIndex].value;";
|
||||
} else {
|
||||
$onch = '';
|
||||
}
|
||||
|
||||
echo '<select id="'.$id.'" name="'.$name.'" onchange="'.$onch.'">';
|
||||
$selected_file = null;
|
||||
foreach ($this->files as $file) {
|
||||
if ($this->value == $file) {
|
||||
$sel = 'selected="selected"';
|
||||
$selected_file = $file;
|
||||
} else {
|
||||
$sel = '';
|
||||
}
|
||||
|
||||
echo '<option '.$sel.' value="'.$file.'">'.$file.'</option>'.PHP_EOL;
|
||||
}
|
||||
echo '</select>';
|
||||
|
||||
if ($this->options['show'] && $selected_file) {
|
||||
echo '<div style="display: inline; min-width: 50px; min-height: 50px">';
|
||||
echo '<img style="position: absolute" id="sel_'.$id.'" width="50" src="'.$this->path.'/'.$selected_file.'" /> ';
|
||||
echo ' ';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function getURLValue()
|
||||
{
|
||||
return $this->name.'='.$this->value;
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class FloatField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'Float')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->getFloat($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class FloatField extends Field
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'Float')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->getFloat($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class FormatSelectField extends SelectField
|
||||
{
|
||||
function __construct($name)
|
||||
{
|
||||
parent::__construct($name, array('preset for demo', 'as input', 'png8', 'png24', 'jpeg', 'gif', 'bmp'), null, 'Image format');
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class FormatSelectField extends SelectField
|
||||
{
|
||||
public function __construct($name)
|
||||
{
|
||||
parent::__construct($name, ['preset for demo', 'as input', 'png8', 'png24', 'jpeg', 'gif', 'bmp'], null, 'Image format');
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class IntField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'Integer')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->getInt($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class IntField extends Field
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'Integer')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->getInt($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
|
@@ -1,135 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
protected $vars = array();
|
||||
|
||||
protected static $instance;
|
||||
static function getInstance()
|
||||
{
|
||||
if (self::$instance === null)
|
||||
self::$instance = new Request;
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
$this->vars = $_GET;
|
||||
|
||||
/*
|
||||
// have to rely on parsing QUERY_STRING, thanks to PHP
|
||||
// http://bugs.php.net/bug.php?id=39078
|
||||
// http://bugs.php.net/bug.php?id=45149
|
||||
$all_vars = explode('&', $_SERVER['QUERY_STRING']);
|
||||
foreach ($all_vars as $keyval)
|
||||
{
|
||||
if (strlen($keyval) == 0)
|
||||
continue;
|
||||
|
||||
if (strpos($keyval, '=') === false)
|
||||
{
|
||||
$key = $keyval;
|
||||
$value = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
list($key, $value) = explode('=', $keyval);
|
||||
#$value = str_replace('%2B', '[[PLUS]]', $value);
|
||||
$value = urldecode($value);
|
||||
#$value = str_replace('[[PLUS]]', '+', $value);
|
||||
}
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function get($key, $default = null)
|
||||
{
|
||||
if (isset($this->vars[$key]))
|
||||
return $this->vars[$key];
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
|
||||
function getInt($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0)
|
||||
return intval($value);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getFloat($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0)
|
||||
return floatval($value);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getCoordinate($key, $default = 0)
|
||||
{
|
||||
$v = self::get($key);
|
||||
if (strlen($v) > 0 && WideImage_Coordinate::parse($v) !== null)
|
||||
return self::get($key);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getOption($key, $valid = array(), $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && in_array($value, $valid))
|
||||
return strval($value);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getColor($key, $default = '000000')
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (substr($value, 0, 1) == '#')
|
||||
$value = substr($value, 1);
|
||||
|
||||
if ($value === '' || preg_match('~^[0-9a-f]{1,6}$~i', $value))
|
||||
return $value;
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getRegex($key, $regex, $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && preg_match($regex, $value))
|
||||
return $value;
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
/**
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**/
|
||||
|
||||
/**
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
protected $vars = [];
|
||||
|
||||
protected static $instance;
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
$this->vars = $_GET;
|
||||
|
||||
/*
|
||||
// have to rely on parsing QUERY_STRING, thanks to PHP
|
||||
// http://bugs.php.net/bug.php?id=39078
|
||||
// http://bugs.php.net/bug.php?id=45149
|
||||
$all_vars = explode('&', $_SERVER['QUERY_STRING']);
|
||||
foreach ($all_vars as $keyval)
|
||||
{
|
||||
if (strlen($keyval) == 0)
|
||||
continue;
|
||||
|
||||
if (strpos($keyval, '=') === false)
|
||||
{
|
||||
$key = $keyval;
|
||||
$value = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
list($key, $value) = explode('=', $keyval);
|
||||
#$value = str_replace('%2B', '[[PLUS]]', $value);
|
||||
$value = urldecode($value);
|
||||
#$value = str_replace('[[PLUS]]', '+', $value);
|
||||
}
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (isset($this->vars[$key])) {
|
||||
return $this->vars[$key];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
|
||||
public function getInt($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0) {
|
||||
return intval($value);
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFloat($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0) {
|
||||
return floatval($value);
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getCoordinate($key, $default = 0)
|
||||
{
|
||||
$v = self::get($key);
|
||||
if (strlen($v) > 0 && WideImage_Coordinate::parse($v) !== null) {
|
||||
return self::get($key);
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getOption($key, $valid = [], $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && in_array($value, $valid)) {
|
||||
return strval($value);
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getColor($key, $default = '000000')
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (substr($value, 0, 1) == '#') {
|
||||
$value = substr($value, 1);
|
||||
}
|
||||
|
||||
if ($value === '' || preg_match('~^[0-9a-f]{1,6}$~i', $value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getRegex($key, $regex, $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && preg_match($regex, $value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,42 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class SelectField extends Field
|
||||
{
|
||||
public $options;
|
||||
|
||||
function __construct($name, $options, $default = null, $hint = null)
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
if ($default === null)
|
||||
$this->default = $options[0];
|
||||
else
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $this->default;
|
||||
$v = str_replace('+', ' ', $request->get($this->name));
|
||||
if (in_array($v, $this->options))
|
||||
$this->value = $v;
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
echo '<select id="' . $id . '" name="' . $name . '">';
|
||||
foreach ($this->options as $option)
|
||||
{
|
||||
if ($this->value == $option)
|
||||
$sel = 'selected="selected"';
|
||||
else
|
||||
$sel = '';
|
||||
|
||||
echo '<option ' . $sel . ' value="' . $option . '">' . $option . '</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class SelectField extends Field
|
||||
{
|
||||
public $options;
|
||||
|
||||
public function __construct($name, $options, $default = null, $hint = null)
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
if ($default === null) {
|
||||
$this->default = $options[0];
|
||||
} else {
|
||||
$this->default = $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $this->default;
|
||||
$v = str_replace('+', ' ', $request->get($this->name));
|
||||
if (in_array($v, $this->options)) {
|
||||
$this->value = $v;
|
||||
}
|
||||
}
|
||||
|
||||
public function renderBody($name, $id)
|
||||
{
|
||||
echo '<select id="'.$id.'" name="'.$name.'">';
|
||||
foreach ($this->options as $option) {
|
||||
if ($this->value == $option) {
|
||||
$sel = 'selected="selected"';
|
||||
} else {
|
||||
$sel = '';
|
||||
}
|
||||
|
||||
echo '<option '.$sel.' value="'.$option.'">'.$option.'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
}
|
||||
|
@@ -1,22 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
define('DEMO_PATH', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR);
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
require_once DEMO_PATH . 'helpers/Request.php';
|
||||
require_once DEMO_PATH . 'helpers/Demo.php';
|
||||
require_once DEMO_PATH . 'helpers/Field.php';
|
||||
require_once DEMO_PATH . 'helpers/CheckboxField.php';
|
||||
require_once DEMO_PATH . 'helpers/FileSelectField.php';
|
||||
require_once DEMO_PATH . 'helpers/CoordinateField.php';
|
||||
require_once DEMO_PATH . 'helpers/IntField.php';
|
||||
require_once DEMO_PATH . 'helpers/FloatField.php';
|
||||
require_once DEMO_PATH . 'helpers/AngleField.php';
|
||||
require_once DEMO_PATH . 'helpers/SelectField.php';
|
||||
require_once DEMO_PATH . 'helpers/FormatSelectField.php';
|
||||
require_once DEMO_PATH . 'helpers/ColorField.php';
|
||||
/**
|
||||
*/
|
||||
define('DEMO_PATH', realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..').DIRECTORY_SEPARATOR);
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
require_once DEMO_PATH.'helpers/Request.php';
|
||||
require_once DEMO_PATH.'helpers/Demo.php';
|
||||
require_once DEMO_PATH.'helpers/Field.php';
|
||||
require_once DEMO_PATH.'helpers/CheckboxField.php';
|
||||
require_once DEMO_PATH.'helpers/FileSelectField.php';
|
||||
require_once DEMO_PATH.'helpers/CoordinateField.php';
|
||||
require_once DEMO_PATH.'helpers/IntField.php';
|
||||
require_once DEMO_PATH.'helpers/FloatField.php';
|
||||
require_once DEMO_PATH.'helpers/AngleField.php';
|
||||
require_once DEMO_PATH.'helpers/SelectField.php';
|
||||
require_once DEMO_PATH.'helpers/FormatSelectField.php';
|
||||
require_once DEMO_PATH.'helpers/ColorField.php';
|
||||
|
@@ -1,52 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/helpers/common.php';
|
||||
require_once dirname(__FILE__) . '/../lib/WideImage.php';
|
||||
|
||||
$request = Request::getInstance();
|
||||
$demo = Demo::create($request->get('demo'));
|
||||
$image = WideImage::load('images/' . $request->get('image'));
|
||||
|
||||
$result = $demo->execute($image, $request);
|
||||
|
||||
$output = new FormatSelectField('output');
|
||||
$output->init(Request::getInstance());
|
||||
|
||||
if ($output->value == 'preset for demo')
|
||||
$format = $demo->getFormat();
|
||||
else
|
||||
$format = $output->value;
|
||||
|
||||
if ($format === 'as input')
|
||||
$format = substr($request->get('image'), -3);
|
||||
|
||||
$output = 24;
|
||||
if ($format == 'png8')
|
||||
{
|
||||
$output = 8;
|
||||
$format = 'png';
|
||||
}
|
||||
elseif ($format == 'png24')
|
||||
$format = 'png';
|
||||
elseif ($format == 'gif')
|
||||
$output = 8;
|
||||
|
||||
if ($output == 8)
|
||||
{
|
||||
$ncolors = new IntField('colors', 255);
|
||||
$ncolors->init(Request::getInstance());
|
||||
|
||||
$dither = new CheckboxField('dither', true);
|
||||
$dither->init(Request::getInstance());
|
||||
|
||||
$match_palette = new CheckboxField('match_palette', true);
|
||||
$match_palette->init(Request::getInstance());
|
||||
|
||||
$result = $result->asPalette($ncolors->value, $dither->value, $match_palette->value);
|
||||
}
|
||||
|
||||
$result->output($format);
|
||||
|
||||
/**
|
||||
*/
|
||||
require_once dirname(__FILE__).'/helpers/common.php';
|
||||
require_once dirname(__FILE__).'/../lib/WideImage.php';
|
||||
|
||||
$request = Request::getInstance();
|
||||
$demo = Demo::create($request->get('demo'));
|
||||
$image = WideImage::load('images/'.$request->get('image'));
|
||||
|
||||
$result = $demo->execute($image, $request);
|
||||
|
||||
$output = new FormatSelectField('output');
|
||||
$output->init(Request::getInstance());
|
||||
|
||||
if ($output->value == 'preset for demo') {
|
||||
$format = $demo->getFormat();
|
||||
} else {
|
||||
$format = $output->value;
|
||||
}
|
||||
|
||||
if ($format === 'as input') {
|
||||
$format = substr($request->get('image'), -3);
|
||||
}
|
||||
|
||||
$output = 24;
|
||||
if ($format == 'png8') {
|
||||
$output = 8;
|
||||
$format = 'png';
|
||||
} elseif ($format == 'png24') {
|
||||
$format = 'png';
|
||||
} elseif ($format == 'gif') {
|
||||
$output = 8;
|
||||
}
|
||||
|
||||
if ($output == 8) {
|
||||
$ncolors = new IntField('colors', 255);
|
||||
$ncolors->init(Request::getInstance());
|
||||
|
||||
$dither = new CheckboxField('dither', true);
|
||||
$dither->init(Request::getInstance());
|
||||
|
||||
$match_palette = new CheckboxField('match_palette', true);
|
||||
$match_palette->init(Request::getInstance());
|
||||
|
||||
$result = $result->asPalette($ncolors->value, $dither->value, $match_palette->value);
|
||||
}
|
||||
|
||||
$result->output($format);
|
||||
|
@@ -1,63 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Demos
|
||||
**/
|
||||
|
||||
include 'helpers/common.php';
|
||||
require_once '../lib/WideImage.php';
|
||||
|
||||
$demos = array();
|
||||
$di = new DirectoryIterator(dirname(__FILE__) . '/demos/');
|
||||
foreach ($di as $file)
|
||||
if (substr($file->getFilename(), -4) == '.php')
|
||||
$demos[] = Demo::create(substr($file->getFilename(), 0, -4));
|
||||
|
||||
usort($demos, 'cmp_demos');
|
||||
|
||||
function cmp_demos($d1, $d2)
|
||||
{
|
||||
if ($d1->order === $d2->order)
|
||||
return 0;
|
||||
|
||||
return ($d1->order < $d2->order ? -1 : 1);
|
||||
}
|
||||
|
||||
if (isset($_GET['demo']))
|
||||
$activeDemoName = $_GET['demo'];
|
||||
else
|
||||
$activeDemoName = null;
|
||||
|
||||
$activeDemo = null;
|
||||
foreach ($demos as $demo)
|
||||
if ($demo->name == $activeDemoName)
|
||||
{
|
||||
$activeDemo = $demo;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$activeDemo)
|
||||
$activeDemoName = null;
|
||||
|
||||
/**
|
||||
|
||||
**/
|
||||
include 'helpers/common.php';
|
||||
require_once '../lib/WideImage.php';
|
||||
|
||||
$demos = [];
|
||||
$di = new DirectoryIterator(dirname(__FILE__).'/demos/');
|
||||
foreach ($di as $file) {
|
||||
if (substr($file->getFilename(), -4) == '.php') {
|
||||
$demos[] = Demo::create(substr($file->getFilename(), 0, -4));
|
||||
}
|
||||
}
|
||||
|
||||
usort($demos, 'cmp_demos');
|
||||
|
||||
function cmp_demos($d1, $d2)
|
||||
{
|
||||
if ($d1->order === $d2->order) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $d1->order < $d2->order ? -1 : 1;
|
||||
}
|
||||
|
||||
if (isset($_GET['demo'])) {
|
||||
$activeDemoName = $_GET['demo'];
|
||||
} else {
|
||||
$activeDemoName = null;
|
||||
}
|
||||
|
||||
$activeDemo = null;
|
||||
foreach ($demos as $demo) {
|
||||
if ($demo->name == $activeDemoName) {
|
||||
$activeDemo = $demo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$activeDemo) {
|
||||
$activeDemoName = null;
|
||||
}
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>WideImage -<?php if ($activeDemo) echo " " . $activeDemo->name; ?> demo</title>
|
||||
<title>WideImage -<?php if ($activeDemo) {
|
||||
echo ' '.$activeDemo->name;
|
||||
} ?> demo</title>
|
||||
|
||||
<style>
|
||||
body
|
||||
@@ -119,28 +109,28 @@
|
||||
|
||||
<ul>
|
||||
<?php
|
||||
$top_form = array();
|
||||
|
||||
$top_form['output'] = new FormatSelectField('output');
|
||||
$top_form['output']->init(Request::getInstance());
|
||||
|
||||
$top_form['ncolors'] = new IntField('colors', 255);
|
||||
$top_form['ncolors']->init(Request::getInstance());
|
||||
|
||||
$top_form['dither'] = new CheckboxField('dither', true);
|
||||
$top_form['dither']->init(Request::getInstance());
|
||||
$top_form['match_palette'] = new CheckboxField('match_palette', true);
|
||||
$top_form['match_palette']->init(Request::getInstance());
|
||||
|
||||
foreach ($demos as $demo)
|
||||
{
|
||||
if ($activeDemo !== null && $demo->name == $activeDemo->name)
|
||||
$css = 'active_demo';
|
||||
else
|
||||
$css = '';
|
||||
|
||||
echo "<li><a class=\"$css\" href=\"?demo={$demo->name}&output={$top_form['output']->value}&colors={$top_form['ncolors']->value}&dither={$top_form['dither']->value}&match_palette={$top_form['match_palette']->value}\">{$demo->name}</a></li>\n";
|
||||
}
|
||||
$top_form = [];
|
||||
|
||||
$top_form['output'] = new FormatSelectField('output');
|
||||
$top_form['output']->init(Request::getInstance());
|
||||
|
||||
$top_form['ncolors'] = new IntField('colors', 255);
|
||||
$top_form['ncolors']->init(Request::getInstance());
|
||||
|
||||
$top_form['dither'] = new CheckboxField('dither', true);
|
||||
$top_form['dither']->init(Request::getInstance());
|
||||
$top_form['match_palette'] = new CheckboxField('match_palette', true);
|
||||
$top_form['match_palette']->init(Request::getInstance());
|
||||
|
||||
foreach ($demos as $demo) {
|
||||
if ($activeDemo !== null && $demo->name == $activeDemo->name) {
|
||||
$css = 'active_demo';
|
||||
} else {
|
||||
$css = '';
|
||||
}
|
||||
|
||||
echo "<li><a class=\"$css\" href=\"?demo={$demo->name}&output={$top_form['output']->value}&colors={$top_form['ncolors']->value}&dither={$top_form['dither']->value}&match_palette={$top_form['match_palette']->value}\">{$demo->name}</a></li>\n";
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
||||
@@ -164,10 +154,9 @@
|
||||
</div>
|
||||
<div style="margin-left: 200px">
|
||||
<?php
|
||||
if ($activeDemo)
|
||||
{
|
||||
include 'demo_screen.php';
|
||||
}
|
||||
if ($activeDemo) {
|
||||
include 'demo_screen.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
|
@@ -1,167 +1,156 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package WideImage
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Exceptions
|
||||
*/
|
||||
class WideImage_NoFontException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* @package Exceptions
|
||||
*/
|
||||
class WideImage_InvalidFontFileException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* @package Exceptions
|
||||
*/
|
||||
class WideImage_InvalidCanvasMethodException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* @package WideImage
|
||||
*/
|
||||
class WideImage_Canvas
|
||||
{
|
||||
protected $handle = 0;
|
||||
protected $image = null;
|
||||
protected $font = null;
|
||||
|
||||
/**
|
||||
* Creates a canvas object that writes to the image passed as a parameter
|
||||
*
|
||||
* Shouldn't be used directly, use WideImage_Image::getCanvas() instead.
|
||||
*
|
||||
* @param WideImage_Image $img Image object
|
||||
*/
|
||||
function __construct($img)
|
||||
{
|
||||
$this->handle = $img->getHandle();
|
||||
$this->image = $img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the active font. Can be an instance of
|
||||
* WideImage_Font_TTF, WideImage_Font_PS, or WideImage_Font_GDF.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param object $font Font object to set for writeText()
|
||||
*/
|
||||
function setFont($font)
|
||||
{
|
||||
$this->font = $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and sets the current font
|
||||
*
|
||||
* The supported font types are: TTF/OTF, PS, and GDF.
|
||||
* Font type is detected from the extension. If the $file parameter doesn't have an extension, TTF font is presumed.
|
||||
*
|
||||
* Note: not all parameters are supported by all fonts.
|
||||
*
|
||||
* @param string $file Font file name (string)
|
||||
* @param int $size Font size (supported for TTF/OTF and PS fonts, ignored for GDF)
|
||||
* @param int $color Text color
|
||||
* @param int $bgcolor Background color (supported only for PS font, ignored for TTF and PS)
|
||||
* @return mixed One of the WideImage_Font_* objects
|
||||
*/
|
||||
function useFont($file, $size = 12, $color = 0, $bgcolor = null)
|
||||
{
|
||||
$p = strrpos($file, '.');
|
||||
if ($p === false || $p < strlen($file) - 4)
|
||||
$ext = 'ttf';
|
||||
else
|
||||
$ext = strtolower(substr($file, $p + 1));
|
||||
|
||||
if ($ext == 'ttf' || $ext == 'otf')
|
||||
$font = new WideImage_Font_TTF($file, $size, $color);
|
||||
elseif ($ext == 'ps')
|
||||
$font = new WideImage_Font_PS($file, $size, $color, $bgcolor);
|
||||
elseif ($ext == 'gdf')
|
||||
$font = new WideImage_Font_GDF($file, $color);
|
||||
else
|
||||
throw new WideImage_InvalidFontFileException("'$file' appears to be an invalid font file.");
|
||||
|
||||
$this->setFont($font);
|
||||
return $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write text on the image at specified position
|
||||
*
|
||||
* You must set a font with a call to WideImage_Canvas::setFont() prior to writing text to the image.
|
||||
*
|
||||
* Smart coordinates are supported for $x and $y arguments, but currently only for TTF/OTF fonts.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $img = WideImage::load('pic.jpg');
|
||||
* $canvas = $img->getCanvas();
|
||||
* $canvas->useFont('Verdana.ttf', 16, $img->allocateColor(255, 0, 0));
|
||||
* $canvas->writeText('right', 'bottom', 'www.website.com');
|
||||
* </code>
|
||||
*
|
||||
* @param int $x Left
|
||||
* @param int $y Top
|
||||
* @param string $text Text to write
|
||||
* @param int $angle The angle, defaults to 0
|
||||
*/
|
||||
function writeText($x, $y, $text, $angle = 0)
|
||||
{
|
||||
if ($this->font === null)
|
||||
throw new WideImage_NoFontException("Can't write text without a font.");
|
||||
|
||||
$angle = - floatval($angle);
|
||||
if ($angle < 0)
|
||||
$angle = 360 + $angle;
|
||||
$angle = $angle % 360;
|
||||
|
||||
$this->font->writeText($this->image, $x, $y, $text, $angle);
|
||||
}
|
||||
|
||||
/**
|
||||
* A magic method that allows you to call any PHP function that starts with "image".
|
||||
*
|
||||
* This is a shortcut to call custom functions on the image handle.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $img = WideImage::load('pic.jpg');
|
||||
* $canvas = $img->getCanvas();
|
||||
* $canvas->filledRect(10, 10, 20, 30, $img->allocateColor(0, 0, 0));
|
||||
* $canvas->line(60, 80, 30, 100, $img->allocateColor(255, 0, 0));
|
||||
* </code>
|
||||
*/
|
||||
function __call($method, $params)
|
||||
{
|
||||
if (function_exists('image' . $method))
|
||||
{
|
||||
array_unshift($params, $this->handle);
|
||||
call_user_func_array('image' . $method, $params);
|
||||
}
|
||||
else
|
||||
throw new WideImage_InvalidCanvasMethodException("Function doesn't exist: image{$method}.");
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class WideImage_NoFontException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_InvalidFontFileException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_InvalidCanvasMethodException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_Canvas
|
||||
{
|
||||
protected $handle = 0;
|
||||
protected $image = null;
|
||||
protected $font = null;
|
||||
|
||||
/**
|
||||
* Creates a canvas object that writes to the image passed as a parameter.
|
||||
*
|
||||
* Shouldn't be used directly, use WideImage_Image::getCanvas() instead.
|
||||
*
|
||||
* @param WideImage_Image $img Image object
|
||||
*/
|
||||
public function __construct($img)
|
||||
{
|
||||
$this->handle = $img->getHandle();
|
||||
$this->image = $img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the active font. Can be an instance of
|
||||
* WideImage_Font_TTF, WideImage_Font_PS, or WideImage_Font_GDF.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param object $font Font object to set for writeText()
|
||||
*/
|
||||
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 WideImage_Font_TTF($file, $size, $color);
|
||||
} elseif ($ext == 'ps') {
|
||||
$font = new WideImage_Font_PS($file, $size, $color, $bgcolor);
|
||||
} elseif ($ext == 'gdf') {
|
||||
$font = new WideImage_Font_GDF($file, $color);
|
||||
} else {
|
||||
throw new WideImage_InvalidFontFileException("'$file' appears to be an invalid font file.");
|
||||
}
|
||||
|
||||
$this->setFont($font);
|
||||
|
||||
return $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write text on the image at specified position.
|
||||
*
|
||||
* You must set a font with a call to WideImage_Canvas::setFont() prior to writing text to the image.
|
||||
*
|
||||
* Smart coordinates are supported for $x and $y arguments, but currently only for TTF/OTF fonts.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $img = WideImage::load('pic.jpg');
|
||||
* $canvas = $img->getCanvas();
|
||||
* $canvas->useFont('Verdana.ttf', 16, $img->allocateColor(255, 0, 0));
|
||||
* $canvas->writeText('right', 'bottom', 'www.website.com');
|
||||
* </code>
|
||||
*
|
||||
* @param int $x Left
|
||||
* @param int $y Top
|
||||
* @param string $text Text to write
|
||||
* @param int $angle The angle, defaults to 0
|
||||
*/
|
||||
public function writeText($x, $y, $text, $angle = 0)
|
||||
{
|
||||
if ($this->font === null) {
|
||||
throw new WideImage_NoFontException("Can't write text without a font.");
|
||||
}
|
||||
|
||||
$angle = -floatval($angle);
|
||||
if ($angle < 0) {
|
||||
$angle = 360 + $angle;
|
||||
}
|
||||
$angle = $angle % 360;
|
||||
|
||||
$this->font->writeText($this->image, $x, $y, $text, $angle);
|
||||
}
|
||||
|
||||
/**
|
||||
* A magic method that allows you to call any PHP function that starts with "image".
|
||||
*
|
||||
* This is a shortcut to call custom functions on the image handle.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $img = WideImage::load('pic.jpg');
|
||||
* $canvas = $img->getCanvas();
|
||||
* $canvas->filledRect(10, 10, 20, 30, $img->allocateColor(0, 0, 0));
|
||||
* $canvas->line(60, 80, 30, 100, $img->allocateColor(255, 0, 0));
|
||||
* </code>
|
||||
*/
|
||||
public 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}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,208 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
*/
|
||||
class WideImage_InvalidCoordinateException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
* @package Internals
|
||||
**/
|
||||
|
||||
|
||||
/**
|
||||
* @package Exceptions
|
||||
*/
|
||||
class WideImage_InvalidCoordinateException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* A utility class for smart coordinates
|
||||
*
|
||||
* @package Internals
|
||||
**/
|
||||
class WideImage_Coordinate
|
||||
{
|
||||
static protected $coord_align = array("left", "center", "right", "top", "middle", "bottom");
|
||||
static protected $coord_numeric = array("[0-9]+", "[0-9]+\.[0-9]+", "[0-9]+%", "[0-9]+\.[0-9]+%");
|
||||
|
||||
/**
|
||||
* Parses a numeric or string representation of a corrdinate into a structure
|
||||
*
|
||||
* @param string $coord Smart coordinate
|
||||
* @return array Parsed smart coordinate
|
||||
*/
|
||||
static function parse($c)
|
||||
{
|
||||
$tokens = array();
|
||||
$operators = array('+', '-');
|
||||
|
||||
$flush_operand = false;
|
||||
$flush_operator = false;
|
||||
$current_operand = '';
|
||||
$current_operator = '';
|
||||
$coordinate = strval($c);
|
||||
$expr_len = strlen($coordinate);
|
||||
|
||||
for ($i = 0; $i < $expr_len; $i++)
|
||||
{
|
||||
$char = $coordinate[$i];
|
||||
|
||||
if (in_array($char, $operators))
|
||||
{
|
||||
$flush_operand = true;
|
||||
$flush_operator = true;
|
||||
$current_operator = $char;
|
||||
}
|
||||
else
|
||||
{
|
||||
$current_operand .= $char;
|
||||
if ($i == $expr_len - 1)
|
||||
$flush_operand = true;
|
||||
}
|
||||
|
||||
if ($flush_operand)
|
||||
{
|
||||
if (trim($current_operand) != '')
|
||||
$tokens[] = array('type' => 'operand', 'value' => trim($current_operand));
|
||||
|
||||
$current_operand = '';
|
||||
$flush_operand = false;
|
||||
}
|
||||
|
||||
if ($flush_operator)
|
||||
{
|
||||
$tokens[] = array('type' => 'operator', 'value' => $char);
|
||||
$flush_operator = false;
|
||||
}
|
||||
}
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates the $coord relatively to $dim
|
||||
*
|
||||
* @param string $coord A numeric value or percent string
|
||||
* @param int $dim Dimension
|
||||
* @param int $sec_dim Secondary dimension (for align)
|
||||
* @return int Calculated value
|
||||
*/
|
||||
static function evaluate($coord, $dim, $sec_dim = null)
|
||||
{
|
||||
$comp_regex = implode('|', self::$coord_align) . '|' . implode('|', self::$coord_numeric);
|
||||
if (preg_match("/^([+-])?({$comp_regex})$/", $coord, $matches))
|
||||
{
|
||||
$sign = intval($matches[1] . "1");
|
||||
$val = $matches[2];
|
||||
if (in_array($val, self::$coord_align))
|
||||
{
|
||||
if ($sec_dim === null)
|
||||
{
|
||||
switch ($val)
|
||||
{
|
||||
case 'left':
|
||||
case 'top':
|
||||
return 0;
|
||||
break;
|
||||
case 'center':
|
||||
case 'middle':
|
||||
return $sign * intval($dim / 2);
|
||||
break;
|
||||
case 'right':
|
||||
case 'bottom':
|
||||
return $sign * $dim;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($val)
|
||||
{
|
||||
case 'left':
|
||||
case 'top':
|
||||
return 0;
|
||||
break;
|
||||
case 'center':
|
||||
case 'middle':
|
||||
return $sign * intval($dim / 2 - $sec_dim / 2);
|
||||
break;
|
||||
case 'right':
|
||||
case 'bottom':
|
||||
return $sign * ($dim - $sec_dim);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (substr($val, -1) === '%')
|
||||
return intval(round($sign * $dim * floatval(str_replace('%', '', $val)) / 100));
|
||||
else
|
||||
return $sign * intval(round($val));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates and fixes a smart coordinate into a numeric value
|
||||
*
|
||||
* @param mixed $value Smart coordinate, relative to $dim
|
||||
* @param int $dim Coordinate to which $value is relative
|
||||
* @param int $sec_dim Secondary dimension (for align)
|
||||
* @return int Calculated value
|
||||
*/
|
||||
static function fix($value, $dim, $sec_dim = null)
|
||||
{
|
||||
$coord_tokens = self::parse($value);
|
||||
|
||||
if (count($coord_tokens) == 0 || $coord_tokens[count($coord_tokens) - 1]['type'] != 'operand')
|
||||
throw new WideImage_InvalidCoordinateException("Couldn't parse coordinate '$value' properly.");
|
||||
|
||||
$value = 0;
|
||||
$operation = 1;
|
||||
foreach ($coord_tokens as $token)
|
||||
{
|
||||
if ($token['type'] == 'operand')
|
||||
{
|
||||
$operand_value = self::evaluate($token['value'], $dim, $sec_dim);
|
||||
if ($operation == 1)
|
||||
$value = $value + $operand_value;
|
||||
elseif ($operation == -1)
|
||||
$value = $value - $operand_value;
|
||||
else
|
||||
throw new WideImage_InvalidCoordinateException("Invalid coordinate syntax.");
|
||||
|
||||
$operation = 0;
|
||||
}
|
||||
elseif ($token['type'] == 'operator')
|
||||
{
|
||||
if ($token['value'] == '-')
|
||||
{
|
||||
if ($operation == 0)
|
||||
$operation = -1;
|
||||
else
|
||||
$operation = $operation * -1;
|
||||
}
|
||||
elseif ($token['value'] == '+')
|
||||
{
|
||||
if ($operation == 0)
|
||||
$operation = '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A utility class for smart coordinates.
|
||||
**/
|
||||
class WideImage_Coordinate
|
||||
{
|
||||
protected static $coord_align = ['left', 'center', 'right', 'top', 'middle', 'bottom'];
|
||||
protected static $coord_numeric = ['[0-9]+', "[0-9]+\.[0-9]+", '[0-9]+%', "[0-9]+\.[0-9]+%"];
|
||||
|
||||
/**
|
||||
* Parses a numeric or string representation of a corrdinate into a structure.
|
||||
*
|
||||
* @param string $coord Smart coordinate
|
||||
*
|
||||
* @return array Parsed smart coordinate
|
||||
*/
|
||||
public static function parse($c)
|
||||
{
|
||||
$tokens = [];
|
||||
$operators = ['+', '-'];
|
||||
|
||||
$flush_operand = false;
|
||||
$flush_operator = false;
|
||||
$current_operand = '';
|
||||
$current_operator = '';
|
||||
$coordinate = strval($c);
|
||||
$expr_len = strlen($coordinate);
|
||||
|
||||
for ($i = 0; $i < $expr_len; $i++) {
|
||||
$char = $coordinate[$i];
|
||||
|
||||
if (in_array($char, $operators)) {
|
||||
$flush_operand = true;
|
||||
$flush_operator = true;
|
||||
$current_operator = $char;
|
||||
} else {
|
||||
$current_operand .= $char;
|
||||
if ($i == $expr_len - 1) {
|
||||
$flush_operand = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($flush_operand) {
|
||||
if (trim($current_operand) != '') {
|
||||
$tokens[] = ['type' => 'operand', 'value' => trim($current_operand)];
|
||||
}
|
||||
|
||||
$current_operand = '';
|
||||
$flush_operand = false;
|
||||
}
|
||||
|
||||
if ($flush_operator) {
|
||||
$tokens[] = ['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;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
} 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 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,31 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package WideImage
|
||||
**/
|
||||
|
||||
/**
|
||||
* Base Exception class
|
||||
*
|
||||
* @package Exceptions
|
||||
**/
|
||||
class WideImage_Exception extends RuntimeException {}
|
||||
|
||||
/**
|
||||
* Base Exception class.
|
||||
**/
|
||||
class WideImage_Exception extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
@@ -1,48 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package WideImage
|
||||
**/
|
||||
|
||||
/**
|
||||
* GDF font support class
|
||||
*
|
||||
* @package WideImage
|
||||
*/
|
||||
class WideImage_Font_GDF
|
||||
{
|
||||
protected $font;
|
||||
protected $color;
|
||||
|
||||
function __construct($face, $color)
|
||||
{
|
||||
if (is_int($face) && $face >= 1 && $face <= 5)
|
||||
$this->font = $face;
|
||||
else
|
||||
$this->font = imageloadfont($face);
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
function writeText($image, $x, $y, $text)
|
||||
{
|
||||
imagestring($image->getHandle(), $this->font, $x, $y, $text, $this->color);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* GDF font support class.
|
||||
*/
|
||||
class WideImage_Font_GDF
|
||||
{
|
||||
protected $font;
|
||||
protected $color;
|
||||
|
||||
public function __construct($face, $color)
|
||||
{
|
||||
if (is_int($face) && $face >= 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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,60 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* PS font support class.
|
||||
*/
|
||||
class WideImage_Font_PS
|
||||
{
|
||||
public $size;
|
||||
public $color;
|
||||
public $handle;
|
||||
|
||||
* @package WideImage
|
||||
**/
|
||||
|
||||
/**
|
||||
* PS font support class
|
||||
*
|
||||
* @package WideImage
|
||||
*/
|
||||
class WideImage_Font_PS
|
||||
{
|
||||
public $size;
|
||||
public $color;
|
||||
public $handle;
|
||||
|
||||
function __construct($file, $size, $color, $bgcolor = null)
|
||||
{
|
||||
$this->handle = imagepsloadfont($file);
|
||||
$this->size = $size;
|
||||
$this->color = $color;
|
||||
if ($bgcolor === null)
|
||||
$this->bgcolor = $color;
|
||||
else
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
function writeText($image, $x, $y, $text, $angle = 0)
|
||||
{
|
||||
if ($image->isTrueColor())
|
||||
$image->alphaBlending(true);
|
||||
|
||||
imagepstext($image->getHandle(), $text, $this->handle, $this->size, $this->color, $this->bgcolor, $x, $y, 0, 0, $angle, 4);
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
imagepsfreefont($this->handle);
|
||||
$this->handle = null;
|
||||
}
|
||||
}
|
||||
public function __construct($file, $size, $color, $bgcolor = null)
|
||||
{
|
||||
$this->handle = imagepsloadfont($file);
|
||||
$this->size = $size;
|
||||
$this->color = $color;
|
||||
if ($bgcolor === null) {
|
||||
$this->bgcolor = $color;
|
||||
} else {
|
||||
$this->color = $color;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,75 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* TTF font support class.
|
||||
*/
|
||||
class WideImage_Font_TTF
|
||||
{
|
||||
public $face;
|
||||
public $size;
|
||||
public $color;
|
||||
|
||||
* @package WideImage
|
||||
**/
|
||||
|
||||
/**
|
||||
* TTF font support class
|
||||
*
|
||||
* @package WideImage
|
||||
*/
|
||||
class WideImage_Font_TTF
|
||||
{
|
||||
public $face;
|
||||
public $size;
|
||||
public $color;
|
||||
|
||||
function __construct($face, $size, $color)
|
||||
{
|
||||
$this->face = $face;
|
||||
$this->size = $size;
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes text onto an image
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param mixed $x smart coordinate
|
||||
* @param mixed $y smart coordinate
|
||||
* @param string $text
|
||||
* @param int $angle Angle in degrees clockwise
|
||||
*/
|
||||
function writeText($image, $x, $y, $text, $angle = 0)
|
||||
{
|
||||
if ($image->isTrueColor())
|
||||
$image->alphaBlending(true);
|
||||
|
||||
$box = imageftbbox($this->size, $angle, $this->face, $text);
|
||||
$obox = array(
|
||||
'left' => min($box[0], $box[2], $box[4], $box[6]),
|
||||
'top' => min($box[1], $box[3], $box[5], $box[7]),
|
||||
'right' => max($box[0], $box[2], $box[4], $box[6]) - 1,
|
||||
'bottom' => max($box[1], $box[3], $box[5], $box[7]) - 1
|
||||
);
|
||||
$obox['width'] = abs($obox['left']) + abs($obox['right']);
|
||||
$obox['height'] = abs($obox['top']) + abs($obox['bottom']);
|
||||
|
||||
$x = WideImage_Coordinate::fix($x, $image->getWidth(), $obox['width']);
|
||||
$y = WideImage_Coordinate::fix($y, $image->getHeight(), $obox['height']);
|
||||
|
||||
$fixed_x = $x - $obox['left'];
|
||||
$fixed_y = $y - $obox['top'];
|
||||
|
||||
imagettftext($image->getHandle(), $this->size, $angle, $fixed_x, $fixed_y, $this->color, $this->face, $text);
|
||||
}
|
||||
}
|
||||
public function __construct($face, $size, $color)
|
||||
{
|
||||
$this->face = $face;
|
||||
$this->size = $size;
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes text onto an image.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param mixed $x smart coordinate
|
||||
* @param mixed $y smart coordinate
|
||||
* @param string $text
|
||||
* @param int $angle Angle in degrees clockwise
|
||||
*/
|
||||
public function writeText($image, $x, $y, $text, $angle = 0)
|
||||
{
|
||||
if ($image->isTrueColor()) {
|
||||
$image->alphaBlending(true);
|
||||
}
|
||||
|
||||
$box = imageftbbox($this->size, $angle, $this->face, $text);
|
||||
$obox = [
|
||||
'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);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,51 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
include_once WideImage::path().'/vendor/de77/BMP.php';
|
||||
|
||||
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
|
||||
/**
|
||||
* Mapper support for BMP.
|
||||
*/
|
||||
class WideImage_Mapper_BMP
|
||||
{
|
||||
public function load($uri)
|
||||
{
|
||||
return WideImage_vendor_de77_BMP::imagecreatefrombmp($uri);
|
||||
}
|
||||
|
||||
* @package Internal/Mappers
|
||||
**/
|
||||
|
||||
include_once WideImage::path() . '/vendor/de77/BMP.php';
|
||||
|
||||
/**
|
||||
* Mapper support for BMP
|
||||
*
|
||||
* @package Internal/Mappers
|
||||
*/
|
||||
class WideImage_Mapper_BMP
|
||||
{
|
||||
function load($uri)
|
||||
{
|
||||
return WideImage_vendor_de77_BMP::imagecreatefrombmp($uri);
|
||||
}
|
||||
|
||||
function loadFromString($data)
|
||||
{
|
||||
return WideImage_vendor_de77_BMP::imagecreatefromstring($data);
|
||||
}
|
||||
|
||||
function save($handle, $uri = null)
|
||||
{
|
||||
if ($uri == null)
|
||||
return WideImage_vendor_de77_BMP::imagebmp($handle);
|
||||
else
|
||||
return WideImage_vendor_de77_BMP::imagebmp($handle, $uri);
|
||||
}
|
||||
}
|
||||
public function loadFromString($data)
|
||||
{
|
||||
return WideImage_vendor_de77_BMP::imagecreatefromstring($data);
|
||||
}
|
||||
|
||||
public function save($handle, $uri = null)
|
||||
{
|
||||
if ($uri == null) {
|
||||
return WideImage_vendor_de77_BMP::imagebmp($handle);
|
||||
} else {
|
||||
return WideImage_vendor_de77_BMP::imagebmp($handle, $uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,44 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Mapper class for GD files.
|
||||
*/
|
||||
class WideImage_Mapper_GD
|
||||
{
|
||||
public function load($uri)
|
||||
{
|
||||
return @imagecreatefromgd($uri);
|
||||
}
|
||||
|
||||
* @package Internal/Mappers
|
||||
**/
|
||||
|
||||
/**
|
||||
* Mapper class for GD files
|
||||
*
|
||||
* @package Internal/Mappers
|
||||
*/
|
||||
class WideImage_Mapper_GD
|
||||
{
|
||||
function load($uri)
|
||||
{
|
||||
return @imagecreatefromgd($uri);
|
||||
}
|
||||
|
||||
function save($handle, $uri = null)
|
||||
{
|
||||
if ($uri == null)
|
||||
return imagegd($handle);
|
||||
else
|
||||
return imagegd($handle, $uri);
|
||||
}
|
||||
}
|
||||
public function save($handle, $uri = null)
|
||||
{
|
||||
if ($uri == null) {
|
||||
return imagegd($handle);
|
||||
} else {
|
||||
return imagegd($handle, $uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,41 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Mapper class for GD2 files.
|
||||
*/
|
||||
class WideImage_Mapper_GD2
|
||||
{
|
||||
public function load($uri)
|
||||
{
|
||||
return @imagecreatefromgd2($uri);
|
||||
}
|
||||
|
||||
* @package Internal/Mappers
|
||||
**/
|
||||
|
||||
/**
|
||||
* Mapper class for GD2 files
|
||||
*
|
||||
* @package Internal/Mappers
|
||||
*/
|
||||
class WideImage_Mapper_GD2
|
||||
{
|
||||
function load($uri)
|
||||
{
|
||||
return @imagecreatefromgd2($uri);
|
||||
}
|
||||
|
||||
function save($handle, $uri = null, $chunk_size = null, $type = null)
|
||||
{
|
||||
return imagegd2($handle, $uri, $chunk_size, $type);
|
||||
}
|
||||
}
|
||||
public function save($handle, $uri = null, $chunk_size = null, $type = null)
|
||||
{
|
||||
return imagegd2($handle, $uri, $chunk_size, $type);
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Mapper class for GIF files.
|
||||
*/
|
||||
class WideImage_Mapper_GIF
|
||||
{
|
||||
public function load($uri)
|
||||
{
|
||||
return @imagecreatefromgif($uri);
|
||||
}
|
||||
|
||||
* @package Internal/Mappers
|
||||
**/
|
||||
|
||||
/**
|
||||
* Mapper class for GIF files
|
||||
*
|
||||
* @package Internal/Mappers
|
||||
*/
|
||||
class WideImage_Mapper_GIF
|
||||
{
|
||||
function load($uri)
|
||||
{
|
||||
return @imagecreatefromgif($uri);
|
||||
}
|
||||
|
||||
function save($handle, $uri = null)
|
||||
{
|
||||
// This is a workaround for a bug, for which PHP devs claim it's not
|
||||
// really a bug. Well, it IS.
|
||||
// You can't pass null as the second parameter, because php is
|
||||
// then trying to save an image to a '' location (which results in an
|
||||
// error, of course). And the same thing works fine for imagepng() and
|
||||
// imagejpeg(). It's a bug! ;)
|
||||
if ($uri)
|
||||
return imagegif($handle, $uri);
|
||||
else
|
||||
return imagegif($handle);
|
||||
}
|
||||
}
|
||||
public function save($handle, $uri = null)
|
||||
{
|
||||
// This is a workaround for a bug, for which PHP devs claim it's not
|
||||
// really a bug. Well, it IS.
|
||||
// You can't pass null as the second parameter, because php is
|
||||
// then trying to save an image to a '' location (which results in an
|
||||
// error, of course). And the same thing works fine for imagepng() and
|
||||
// imagejpeg(). It's a bug! ;)
|
||||
if ($uri) {
|
||||
return imagegif($handle, $uri);
|
||||
} else {
|
||||
return imagegif($handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,41 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Mapper class for JPEG files.
|
||||
*/
|
||||
class WideImage_Mapper_JPEG
|
||||
{
|
||||
public function load($uri)
|
||||
{
|
||||
return @imagecreatefromjpeg($uri);
|
||||
}
|
||||
|
||||
* @package Internal/Mappers
|
||||
**/
|
||||
|
||||
/**
|
||||
* Mapper class for JPEG files
|
||||
*
|
||||
* @package Internal/Mappers
|
||||
*/
|
||||
class WideImage_Mapper_JPEG
|
||||
{
|
||||
function load($uri)
|
||||
{
|
||||
return @imagecreatefromjpeg($uri);
|
||||
}
|
||||
|
||||
function save($handle, $uri = null, $quality = 100)
|
||||
{
|
||||
return imagejpeg($handle, $uri, $quality);
|
||||
}
|
||||
}
|
||||
public function save($handle, $uri = null, $quality = 100)
|
||||
{
|
||||
return imagejpeg($handle, $uri, $quality);
|
||||
}
|
||||
}
|
||||
|
@@ -1,41 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Mapper class for PNG files.
|
||||
*/
|
||||
class WideImage_Mapper_PNG
|
||||
{
|
||||
public function load($uri)
|
||||
{
|
||||
return @imagecreatefrompng($uri);
|
||||
}
|
||||
|
||||
* @package Internal/Mappers
|
||||
**/
|
||||
|
||||
/**
|
||||
* Mapper class for PNG files
|
||||
*
|
||||
* @package Internal/Mappers
|
||||
*/
|
||||
class WideImage_Mapper_PNG
|
||||
{
|
||||
function load($uri)
|
||||
{
|
||||
return @imagecreatefrompng($uri);
|
||||
}
|
||||
|
||||
function save($handle, $uri = null, $compression = 9, $filters = PNG_ALL_FILTERS)
|
||||
{
|
||||
return imagepng($handle, $uri, $compression, $filters);
|
||||
}
|
||||
}
|
||||
public function save($handle, $uri = null, $compression = 9, $filters = PNG_ALL_FILTERS)
|
||||
{
|
||||
return imagepng($handle, $uri, $compression, $filters);
|
||||
}
|
||||
}
|
||||
|
@@ -1,48 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
include_once WideImage::path().'/vendor/de77/TGA.php';
|
||||
|
||||
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
|
||||
/**
|
||||
* Mapper support for TGA.
|
||||
*/
|
||||
class WideImage_Mapper_TGA
|
||||
{
|
||||
public function load($uri)
|
||||
{
|
||||
return WideImage_vendor_de77_TGA::imagecreatefromtga($uri);
|
||||
}
|
||||
|
||||
* @package Internal/Mappers
|
||||
**/
|
||||
|
||||
include_once WideImage::path() . '/vendor/de77/TGA.php';
|
||||
|
||||
/**
|
||||
* Mapper support for TGA
|
||||
*
|
||||
* @package Internal/Mappers
|
||||
*/
|
||||
class WideImage_Mapper_TGA
|
||||
{
|
||||
function load($uri)
|
||||
{
|
||||
return WideImage_vendor_de77_TGA::imagecreatefromtga($uri);
|
||||
}
|
||||
|
||||
function loadFromString($data)
|
||||
{
|
||||
return WideImage_vendor_de77_TGA::imagecreatefromstring($data);
|
||||
}
|
||||
|
||||
function save($handle, $uri = null)
|
||||
{
|
||||
throw new WideImage_Exception("Saving to TGA isn't supported.");
|
||||
}
|
||||
}
|
||||
public function loadFromString($data)
|
||||
{
|
||||
return WideImage_vendor_de77_TGA::imagecreatefromstring($data);
|
||||
}
|
||||
|
||||
public function save($handle, $uri = null)
|
||||
{
|
||||
throw new WideImage_Exception("Saving to TGA isn't supported.");
|
||||
}
|
||||
}
|
||||
|
@@ -1,126 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package WideImage
|
||||
**/
|
||||
|
||||
/**
|
||||
* Thrown when image format isn't supported
|
||||
*
|
||||
* @package Exceptions
|
||||
*/
|
||||
class WideImage_UnsupportedFormatException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* Mapper factory
|
||||
*
|
||||
* @package Internals
|
||||
**/
|
||||
abstract class WideImage_MapperFactory
|
||||
{
|
||||
static protected $mappers = array();
|
||||
static protected $customMappers = array();
|
||||
|
||||
static protected $mimeTable = array(
|
||||
'image/jpg' => '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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Thrown when image format isn't supported.
|
||||
*/
|
||||
class WideImage_UnsupportedFormatException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapper factory.
|
||||
**/
|
||||
abstract class WideImage_MapperFactory
|
||||
{
|
||||
protected static $mappers = [];
|
||||
protected static $customMappers = [];
|
||||
|
||||
protected static $mimeTable = [
|
||||
'image/jpg' => '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
|
||||
**/
|
||||
public 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.");
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return array_search(strtoupper($format), self::$mimeTable);
|
||||
}
|
||||
|
||||
public static function extractExtension($uri)
|
||||
{
|
||||
$p = strrpos($uri, '.');
|
||||
if ($p === false) {
|
||||
return '';
|
||||
} else {
|
||||
return substr($uri, $p + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,153 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Tomasz Kapusta
|
||||
* @copyright 2010
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* Noise filter
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_AddNoise {
|
||||
/**
|
||||
* Returns image with noise added
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param float $amount
|
||||
* @param const $type
|
||||
* @param float $threshold
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
|
||||
function execute($image, $amount, $type) {
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'salt&pepper' : $fun = 'saltPepperNoise_fun';
|
||||
break;
|
||||
case 'color' : $fun = 'colorNoise_fun';
|
||||
break;
|
||||
default : $fun = 'monoNoise_fun';
|
||||
break;
|
||||
}
|
||||
|
||||
return self::filter($image->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;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @author Tomasz Kapusta
|
||||
* @copyright 2010
|
||||
**/
|
||||
|
||||
/**
|
||||
* Noise filter.
|
||||
*/
|
||||
class WideImage_Operation_AddNoise
|
||||
{
|
||||
/**
|
||||
* Returns image with noise added.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param float $amount
|
||||
* @param const $type
|
||||
* @param float $threshold
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image, $amount, $type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'salt&pepper': $fun = 'saltPepperNoise_fun';
|
||||
break;
|
||||
case 'color': $fun = 'colorNoise_fun';
|
||||
break;
|
||||
default: $fun = 'monoNoise_fun';
|
||||
break;
|
||||
}
|
||||
|
||||
return self::filter($image->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;
|
||||
|
||||
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
|
||||
*/
|
||||
public 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
|
||||
*/
|
||||
public 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,48 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* ApplyConvolution operation class.
|
||||
*/
|
||||
class WideImage_Operation_ApplyConvolution
|
||||
{
|
||||
/**
|
||||
* Executes imageconvolution() filter.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param array $matrix
|
||||
* @param numeric $div
|
||||
* @param numeric $offset
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image, $matrix, $div, $offset)
|
||||
{
|
||||
$new = $image->asTrueColor();
|
||||
if (!imageconvolution($new->getHandle(), $matrix, $div, $offset)) {
|
||||
throw new WideImage_GDFunctionResultException('imageconvolution() returned false');
|
||||
}
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* ApplyConvolution operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_ApplyConvolution
|
||||
{
|
||||
/**
|
||||
* Executes imageconvolution() filter
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param array $matrix
|
||||
* @param numeric $div
|
||||
* @param numeric $offset
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image, $matrix, $div, $offset)
|
||||
{
|
||||
$new = $image->asTrueColor();
|
||||
if (!imageconvolution($new->getHandle(), $matrix, $div, $offset))
|
||||
throw new WideImage_GDFunctionResultException("imageconvolution() returned false");
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
|
@@ -1,67 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* ApplyFilter operation class.
|
||||
*/
|
||||
class WideImage_Operation_ApplyFilter
|
||||
{
|
||||
/**
|
||||
* A list of filters that only accept one arguments for imagefilter().
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $one_arg_filters = [IMG_FILTER_SMOOTH, IMG_FILTER_CONTRAST, IMG_FILTER_BRIGHTNESS];
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* ApplyFilter operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_ApplyFilter
|
||||
{
|
||||
/**
|
||||
* A list of filters that only accept one arguments for imagefilter()
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static protected $one_arg_filters = array(IMG_FILTER_SMOOTH, IMG_FILTER_CONTRAST, IMG_FILTER_BRIGHTNESS);
|
||||
|
||||
/**
|
||||
* Executes imagefilter
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param int $filter
|
||||
* @param numeric $arg1
|
||||
* @param numeric $arg2
|
||||
* @param numeric $arg3
|
||||
* @return WideImage_TrueColorImage
|
||||
*/
|
||||
function execute($image, $filter, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null)
|
||||
{
|
||||
$new = $image->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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Executes imagefilter.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param int $filter
|
||||
* @param numeric $arg1
|
||||
* @param numeric $arg2
|
||||
* @param numeric $arg3
|
||||
*
|
||||
* @return WideImage_TrueColorImage
|
||||
*/
|
||||
public function execute($image, $filter, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null)
|
||||
{
|
||||
$new = $image->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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,105 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* ApplyMask operation class.
|
||||
*/
|
||||
class WideImage_Operation_ApplyMask
|
||||
{
|
||||
/**
|
||||
* Applies a mask on the copy of source image.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param WideImage_Image $mask
|
||||
* @param smart_coordinate $left
|
||||
* @param smart_coordinate $top
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image, $mask, $left = 0, $top = 0)
|
||||
{
|
||||
$left = WideImage_Coordinate::fix($left, $image->getWidth(), $mask->getWidth());
|
||||
$top = WideImage_Coordinate::fix($top, $image->getHeight(), $mask->getHeight());
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* ApplyMask operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_ApplyMask
|
||||
{
|
||||
/**
|
||||
* Applies a mask on the copy of source image
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param WideImage_Image $mask
|
||||
* @param smart_coordinate $left
|
||||
* @param smart_coordinate $top
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image, $mask, $left = 0, $top = 0)
|
||||
{
|
||||
$left = WideImage_Coordinate::fix($left, $image->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;
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,49 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* AsGrayscale operation class.
|
||||
*/
|
||||
class WideImage_Operation_AsGrayscale
|
||||
{
|
||||
/**
|
||||
* Returns a greyscale copy of an image.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image)
|
||||
{
|
||||
$new = $image->asTrueColor();
|
||||
if (!imagefilter($new->getHandle(), IMG_FILTER_GRAYSCALE)) {
|
||||
throw new WideImage_GDFunctionResultException('imagefilter() returned false');
|
||||
}
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* AsGrayscale operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_AsGrayscale
|
||||
{
|
||||
/**
|
||||
* Returns a greyscale copy of an image
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image)
|
||||
{
|
||||
$new = $image->asTrueColor();
|
||||
if (!imagefilter($new->getHandle(), IMG_FILTER_GRAYSCALE))
|
||||
throw new WideImage_GDFunctionResultException("imagefilter() returned false");
|
||||
|
||||
if (!$image->isTrueColor())
|
||||
$new = $new->asPalette();
|
||||
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
if (!$image->isTrueColor()) {
|
||||
$new = $new->asPalette();
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
|
@@ -1,63 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* AsNegative operation class.
|
||||
*/
|
||||
class WideImage_Operation_AsNegative
|
||||
{
|
||||
/**
|
||||
* Returns a greyscale copy of an image.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image)
|
||||
{
|
||||
$palette = !$image->isTrueColor();
|
||||
$transparent = $image->isTransparent();
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* AsNegative operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_AsNegative
|
||||
{
|
||||
/**
|
||||
* Returns a greyscale copy of an image
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image)
|
||||
{
|
||||
$palette = !$image->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;
|
||||
}
|
||||
}
|
||||
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 = ['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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,162 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* AutoCrop operation.
|
||||
*/
|
||||
class WideImage_Operation_AutoCrop
|
||||
{
|
||||
/**
|
||||
* Executes the auto-crop operation on the $img.
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param int $rgb_threshold The difference in RGB from $base_color
|
||||
* @param int $pixel_cutoff The number of pixels on each border that must be over $rgb_threshold
|
||||
* @param int $base_color The color that will get cropped
|
||||
*
|
||||
* @return WideImage_Image resulting auto-cropped image
|
||||
*/
|
||||
public function execute($img, $margin, $rgb_threshold, $pixel_cutoff, $base_color)
|
||||
{
|
||||
$margin = intval($margin);
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* AutoCrop operation
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_AutoCrop
|
||||
{
|
||||
/**
|
||||
* Executes the auto-crop operation on the $img
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param int $rgb_threshold The difference in RGB from $base_color
|
||||
* @param int $pixel_cutoff The number of pixels on each border that must be over $rgb_threshold
|
||||
* @param int $base_color The color that will get cropped
|
||||
* @return WideImage_Image resulting auto-cropped image
|
||||
*/
|
||||
function execute($img, $margin, $rgb_threshold, $pixel_cutoff, $base_color)
|
||||
{
|
||||
$margin = intval($margin);
|
||||
|
||||
$rgb_threshold = intval($rgb_threshold);
|
||||
if ($rgb_threshold < 0)
|
||||
$rgb_threshold = 0;
|
||||
|
||||
$pixel_cutoff = intval($pixel_cutoff);
|
||||
if ($pixel_cutoff <= 1)
|
||||
$pixel_cutoff = 1;
|
||||
|
||||
if ($base_color === null)
|
||||
$rgb_base = $img->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);
|
||||
}
|
||||
}
|
||||
$rgb_threshold = intval($rgb_threshold);
|
||||
if ($rgb_threshold < 0) {
|
||||
$rgb_threshold = 0;
|
||||
}
|
||||
|
||||
$pixel_cutoff = intval($pixel_cutoff);
|
||||
if ($pixel_cutoff <= 1) {
|
||||
$pixel_cutoff = 1;
|
||||
}
|
||||
|
||||
if ($base_color === null) {
|
||||
$rgb_base = $img->getRGBAt(0, 0);
|
||||
} else {
|
||||
if ($base_color < 0) {
|
||||
return $img->copy();
|
||||
}
|
||||
|
||||
$rgb_base = $img->getColorRGB($base_color);
|
||||
}
|
||||
|
||||
$cut_rect = ['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 = [
|
||||
'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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,90 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* CopyChannelsPalette operation class.
|
||||
*
|
||||
* This operation is intended to be used on palette images
|
||||
*/
|
||||
class WideImage_Operation_CopyChannelsPalette
|
||||
{
|
||||
/**
|
||||
* Returns an image with only specified channels copied.
|
||||
*
|
||||
* @param WideImage_PaletteImage $img
|
||||
* @param array $channels
|
||||
*
|
||||
* @return WideImage_PaletteImage
|
||||
*/
|
||||
public function execute($img, $channels)
|
||||
{
|
||||
$blank = ['red' => 0, 'green' => 0, 'blue' => 0];
|
||||
if (isset($channels['alpha'])) {
|
||||
unset($channels['alpha']);
|
||||
}
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* CopyChannelsPalette operation class
|
||||
*
|
||||
* This operation is intended to be used on palette images
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_CopyChannelsPalette
|
||||
{
|
||||
/**
|
||||
* Returns an image with only specified channels copied
|
||||
*
|
||||
* @param WideImage_PaletteImage $img
|
||||
* @param array $channels
|
||||
* @return WideImage_PaletteImage
|
||||
*/
|
||||
function execute($img, $channels)
|
||||
{
|
||||
$blank = array('red' => 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;
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,67 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* CopyChannelsTrueColor operation class.
|
||||
*
|
||||
* Used to perform CopyChannels operation on truecolor images
|
||||
*/
|
||||
class WideImage_Operation_CopyChannelsTrueColor
|
||||
{
|
||||
/**
|
||||
* Returns an image with only specified channels copied.
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param array $channels
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($img, $channels)
|
||||
{
|
||||
$blank = ['red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0];
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* CopyChannelsTrueColor operation class
|
||||
*
|
||||
* Used to perform CopyChannels operation on truecolor images
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_CopyChannelsTrueColor
|
||||
{
|
||||
/**
|
||||
* Returns an image with only specified channels copied
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param array $channels
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($img, $channels)
|
||||
{
|
||||
$blank = array('red' => 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;
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,48 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* CorrectGamma operation class.
|
||||
*/
|
||||
class WideImage_Operation_CorrectGamma
|
||||
{
|
||||
/**
|
||||
* Executes imagegammacorrect().
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param numeric $input_gamma
|
||||
* @param numeric $output_gamma
|
||||
*
|
||||
* @return WideImage_TrueColorImage
|
||||
*/
|
||||
public function execute($image, $input_gamma, $output_gamma)
|
||||
{
|
||||
$new = $image->copy();
|
||||
if (!imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma)) {
|
||||
throw new WideImage_GDFunctionResultException('imagegammacorrect() returned false');
|
||||
}
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* CorrectGamma operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_CorrectGamma
|
||||
{
|
||||
/**
|
||||
* Executes imagegammacorrect()
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param numeric $input_gamma
|
||||
* @param numeric $output_gamma
|
||||
* @return WideImage_TrueColorImage
|
||||
*/
|
||||
function execute($image, $input_gamma, $output_gamma)
|
||||
{
|
||||
$new = $image->copy();
|
||||
if (!imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma))
|
||||
throw new WideImage_GDFunctionResultException("imagegammacorrect() returned false");
|
||||
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
|
@@ -1,86 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Crop operation class.
|
||||
*/
|
||||
class WideImage_Operation_Crop
|
||||
{
|
||||
/**
|
||||
* Returns a cropped image.
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param smart_coordinate $left
|
||||
* @param smart_coordinate $top
|
||||
* @param smart_coordinate $width
|
||||
* @param smart_coordinate $height
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($img, $left, $top, $width, $height)
|
||||
{
|
||||
$width = WideImage_Coordinate::fix($width, $img->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;
|
||||
}
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* Crop operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_Crop
|
||||
{
|
||||
/**
|
||||
* Returns a cropped image
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param smart_coordinate $left
|
||||
* @param smart_coordinate $top
|
||||
* @param smart_coordinate $width
|
||||
* @param smart_coordinate $height
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($img, $left, $top, $width, $height)
|
||||
{
|
||||
$width = WideImage_Coordinate::fix($width, $img->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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,54 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Flip operation class.
|
||||
*/
|
||||
class WideImage_Operation_Flip
|
||||
{
|
||||
/**
|
||||
* Returns a flipped image.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image)
|
||||
{
|
||||
$new = $image->copy();
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* Flip operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_Flip
|
||||
{
|
||||
/**
|
||||
* Returns a flipped image
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image)
|
||||
{
|
||||
$new = $image->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;
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,67 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* GetMask operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_GetMask
|
||||
{
|
||||
/**
|
||||
* Returns a mask
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image)
|
||||
{
|
||||
$width = $image->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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* GetMask operation class.
|
||||
*/
|
||||
class WideImage_Operation_GetMask
|
||||
{
|
||||
/**
|
||||
* Returns a mask.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image)
|
||||
{
|
||||
$width = $image->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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,78 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Merge operation class.
|
||||
*/
|
||||
class WideImage_Operation_Merge
|
||||
{
|
||||
/**
|
||||
* Returns a merged image.
|
||||
*
|
||||
* @param WideImage_Image $base
|
||||
* @param WideImage_Image $overlay
|
||||
* @param smart_coordinate $left
|
||||
* @param smart_coordinate $top
|
||||
* @param numeric $pct
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($base, $overlay, $left, $top, $pct)
|
||||
{
|
||||
$x = WideImage_Coordinate::fix($left, $base->getWidth(), $overlay->getWidth());
|
||||
$y = WideImage_Coordinate::fix($top, $base->getHeight(), $overlay->getHeight());
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* Merge operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_Merge
|
||||
{
|
||||
/**
|
||||
* Returns a merged image
|
||||
*
|
||||
* @param WideImage_Image $base
|
||||
* @param WideImage_Image $overlay
|
||||
* @param smart_coordinate $left
|
||||
* @param smart_coordinate $top
|
||||
* @param numeric $pct
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($base, $overlay, $left, $top, $pct)
|
||||
{
|
||||
$x = WideImage_Coordinate::fix($left, $base->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;
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,55 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Mirror operation class.
|
||||
*/
|
||||
class WideImage_Operation_Mirror
|
||||
{
|
||||
/**
|
||||
* Returns a mirrored image.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image)
|
||||
{
|
||||
$new = $image->copy();
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* Mirror operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_Mirror
|
||||
{
|
||||
/**
|
||||
* Returns a mirrored image
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image)
|
||||
{
|
||||
$new = $image->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;
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,157 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* An Exception for when an invalid fit method is passed.
|
||||
*/
|
||||
class WideImage_Operation_InvalidFitMethodException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
/**
|
||||
* An Exception for when an invalid resize dimensions are passed.
|
||||
*/
|
||||
class WideImage_Operation_InvalidResizeDimensionException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* An Exception for when an invalid fit method is passed
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_InvalidFitMethodException extends WideImage_Exception {}
|
||||
/**
|
||||
* An Exception for when an invalid resize dimensions are passed
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_InvalidResizeDimensionException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* Resize operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_Resize
|
||||
{
|
||||
/**
|
||||
* Prepares and corrects smart coordinates
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param smart_coordinate $width
|
||||
* @param smart_coordinate $height
|
||||
* @param string $fit
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareDimensions($img, $width, $height, $fit)
|
||||
{
|
||||
if ($width === null && $height === null)
|
||||
{
|
||||
$width = $img->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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Resize operation class.
|
||||
*/
|
||||
class WideImage_Operation_Resize
|
||||
{
|
||||
/**
|
||||
* Prepares and corrects smart coordinates.
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param smart_coordinate $width
|
||||
* @param smart_coordinate $height
|
||||
* @param string $fit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareDimensions($img, $width, $height, $fit)
|
||||
{
|
||||
if ($width === null && $height === null) {
|
||||
$width = $img->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 ['width' => 0, 'height' => 0];
|
||||
}
|
||||
|
||||
if ($fit == null) {
|
||||
$fit = 'inside';
|
||||
}
|
||||
|
||||
$dim = [];
|
||||
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
|
||||
*/
|
||||
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 = ['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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,107 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* ResizeCanvas operation class.
|
||||
*/
|
||||
class WideImage_Operation_ResizeCanvas
|
||||
{
|
||||
/**
|
||||
* Returns an image with a resized canvas.
|
||||
*
|
||||
* The image is filled with $color. Use $scale to determine, when to resize.
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param smart_coordinate $width
|
||||
* @param smart_coordinate $height
|
||||
* @param smart_coordinate $left
|
||||
* @param smart_coordinate $top
|
||||
* @param int $color
|
||||
* @param string $scale 'up', 'down', 'any'
|
||||
* @param bool $merge
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($img, $width, $height, $left, $top, $color, $scale, $merge)
|
||||
{
|
||||
$new_width = WideImage_Coordinate::fix($width, $img->getWidth());
|
||||
$new_height = WideImage_Coordinate::fix($height, $img->getHeight());
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* ResizeCanvas operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_ResizeCanvas
|
||||
{
|
||||
/**
|
||||
* Returns an image with a resized canvas
|
||||
*
|
||||
* The image is filled with $color. Use $scale to determine, when to resize.
|
||||
*
|
||||
* @param WideImage_Image $img
|
||||
* @param smart_coordinate $width
|
||||
* @param smart_coordinate $height
|
||||
* @param smart_coordinate $left
|
||||
* @param smart_coordinate $top
|
||||
* @param int $color
|
||||
* @param string $scale 'up', 'down', 'any'
|
||||
* @param boolean $merge
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($img, $width, $height, $left, $top, $color, $scale, $merge)
|
||||
{
|
||||
$new_width = WideImage_Coordinate::fix($width, $img->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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,64 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Rotate operation class.
|
||||
*/
|
||||
class WideImage_Operation_Rotate
|
||||
{
|
||||
/**
|
||||
* Returns rotated image.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param numeric $angle
|
||||
* @param int $bgColor
|
||||
* @param bool $ignoreTransparent
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image, $angle, $bgColor, $ignoreTransparent)
|
||||
{
|
||||
$angle = -floatval($angle);
|
||||
if ($angle < 0) {
|
||||
$angle = 360 + $angle;
|
||||
}
|
||||
$angle = $angle % 360;
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* Rotate operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_Rotate
|
||||
{
|
||||
/**
|
||||
* Returns rotated image
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param numeric $angle
|
||||
* @param int $bgColor
|
||||
* @param bool $ignoreTransparent
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image, $angle, $bgColor, $ignoreTransparent)
|
||||
{
|
||||
$angle = -floatval($angle);
|
||||
if ($angle < 0)
|
||||
$angle = 360 + $angle;
|
||||
$angle = $angle % 360;
|
||||
|
||||
if ($angle == 0)
|
||||
return $image->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));
|
||||
}
|
||||
}
|
||||
if ($angle == 0) {
|
||||
return $image->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));
|
||||
}
|
||||
}
|
||||
|
@@ -1,114 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* ApplyMask operation class.
|
||||
*/
|
||||
class WideImage_Operation_RoundCorners
|
||||
{
|
||||
/**
|
||||
* @param WideImage_Image $image
|
||||
* @param int $radius
|
||||
* @param int $color
|
||||
* @param int $smoothness
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image, $radius, $color, $smoothness, $corners)
|
||||
{
|
||||
if ($smoothness < 1) {
|
||||
$sample_ratio = 1;
|
||||
} elseif ($smoothness > 16) {
|
||||
$sample_ratio = 16;
|
||||
} else {
|
||||
$sample_ratio = $smoothness;
|
||||
}
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* ApplyMask operation class
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_RoundCorners
|
||||
{
|
||||
/**
|
||||
* @param WideImage_Image $image
|
||||
* @param int $radius
|
||||
* @param int $color
|
||||
* @param int $smoothness
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image, $radius, $color, $smoothness, $corners)
|
||||
{
|
||||
if ($smoothness < 1)
|
||||
$sample_ratio = 1;
|
||||
elseif ($smoothness > 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,135 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
* Unsharp filter.
|
||||
*
|
||||
* This filter was taken from http://vikjavev.no/computing/ump.php,
|
||||
* the original author Torstein Hønsi. Adapted to fit better within
|
||||
* the Wideimage package.
|
||||
*/
|
||||
class WideImage_Operation_Unsharp
|
||||
{
|
||||
/**
|
||||
* Returns sharpened image.
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param float $amount
|
||||
* @param int $radius
|
||||
* @param float $threshold
|
||||
*
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
public function execute($image, $amount, $radius, $threshold)
|
||||
{
|
||||
|
||||
* @package Internal/Operations
|
||||
**/
|
||||
|
||||
/**
|
||||
* Unsharp filter
|
||||
*
|
||||
* This filter was taken from http://vikjavev.no/computing/ump.php,
|
||||
* the original author Torstein Hønsi. Adapted to fit better within
|
||||
* the Wideimage package.
|
||||
*
|
||||
* @package Internal/Operations
|
||||
*/
|
||||
class WideImage_Operation_Unsharp {
|
||||
/**
|
||||
* Returns sharpened image
|
||||
*
|
||||
* @param WideImage_Image $image
|
||||
* @param float $amount
|
||||
* @param int $radius
|
||||
* @param float $threshold
|
||||
* @return WideImage_Image
|
||||
*/
|
||||
function execute($image, $amount, $radius, $threshold) {
|
||||
|
||||
// Attempt to calibrate the parameters to Photoshop:
|
||||
if ($amount > 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;
|
||||
}
|
||||
}
|
||||
// Attempt to calibrate the parameters to Photoshop:
|
||||
if ($amount > 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 = [
|
||||
[1, 2, 1],
|
||||
[2, 4, 2],
|
||||
[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 = ['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 = ['red' => $rNew, 'green' => $gNew, 'blue' => $bNew, 'alpha' => 0];
|
||||
|
||||
$image->setRGBAt($x, $y, $rgbNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
}
|
||||
|
@@ -1,57 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/**
|
||||
*/
|
||||
class WideImage_UnknownImageOperationException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
* @package Internals
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Exceptions
|
||||
*/
|
||||
class WideImage_UnknownImageOperationException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* Operation factory
|
||||
*
|
||||
* @package Internals
|
||||
**/
|
||||
class WideImage_OperationFactory
|
||||
{
|
||||
static protected $cache = array();
|
||||
|
||||
static function get($operationName)
|
||||
{
|
||||
$lcname = strtolower($operationName);
|
||||
if (!isset(self::$cache[$lcname]))
|
||||
{
|
||||
$opClassName = "WideImage_Operation_" . ucfirst($operationName);
|
||||
if (!class_exists($opClassName, false))
|
||||
{
|
||||
$fileName = WideImage::path() . 'Operation/' . ucfirst($operationName) . '.php';
|
||||
if (file_exists($fileName))
|
||||
require_once $fileName;
|
||||
elseif (!class_exists($opClassName))
|
||||
throw new WideImage_UnknownImageOperationException("Can't load '{$operationName}' operation.");
|
||||
}
|
||||
self::$cache[$lcname] = new $opClassName();
|
||||
}
|
||||
return self::$cache[$lcname];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Operation factory.
|
||||
**/
|
||||
class WideImage_OperationFactory
|
||||
{
|
||||
protected static $cache = [];
|
||||
|
||||
public static function get($operationName)
|
||||
{
|
||||
$lcname = strtolower($operationName);
|
||||
if (!isset(self::$cache[$lcname])) {
|
||||
$opClassName = 'WideImage_Operation_'.ucfirst($operationName);
|
||||
if (!class_exists($opClassName, false)) {
|
||||
$fileName = WideImage::path().'Operation/'.ucfirst($operationName).'.php';
|
||||
if (file_exists($fileName)) {
|
||||
require_once $fileName;
|
||||
} elseif (!class_exists($opClassName)) {
|
||||
throw new WideImage_UnknownImageOperationException("Can't load '{$operationName}' operation.");
|
||||
}
|
||||
}
|
||||
self::$cache[$lcname] = new $opClassName();
|
||||
}
|
||||
|
||||
return self::$cache[$lcname];
|
||||
}
|
||||
}
|
||||
|
@@ -1,136 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package WideImage
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package WideImage
|
||||
*/
|
||||
class WideImage_PaletteImage extends WideImage_Image
|
||||
{
|
||||
/**
|
||||
* Create a palette image
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
* @return WideImage_PaletteImage
|
||||
*/
|
||||
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_PaletteImage(imagecreate($width, $height));
|
||||
}
|
||||
|
||||
function doCreate($width, $height)
|
||||
{
|
||||
return self::create($width, $height);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see WideImage_Image#isTrueColor()
|
||||
*/
|
||||
function isTrueColor()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see WideImage_Image#asPalette($nColors, $dither, $matchPalette)
|
||||
*/
|
||||
function asPalette($nColors = 255, $dither = null, $matchPalette = true)
|
||||
{
|
||||
return $this->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'));
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class WideImage_PaletteImage extends WideImage_Image
|
||||
{
|
||||
/**
|
||||
* Create a palette image.
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*
|
||||
* @return WideImage_PaletteImage
|
||||
*/
|
||||
public 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 self(imagecreate($width, $height));
|
||||
}
|
||||
|
||||
public function doCreate($width, $height)
|
||||
{
|
||||
return self::create($width, $height);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc).
|
||||
*
|
||||
* @see WideImage_Image#isTrueColor()
|
||||
*/
|
||||
public function isTrueColor()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc).
|
||||
*
|
||||
* @see WideImage_Image#asPalette($nColors, $dither, $matchPalette)
|
||||
*/
|
||||
public function asPalette($nColors = 255, $dither = null, $matchPalette = true)
|
||||
{
|
||||
return $this->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 = self::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 WideImage_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 WideImage_OperationFactory::get('CopyChannelsPalette')->execute($this, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc).
|
||||
*
|
||||
* @see WideImage_Image#copyNoAlpha()
|
||||
*/
|
||||
public function copyNoAlpha()
|
||||
{
|
||||
return WideImage_Image::loadFromString($this->asString('png'));
|
||||
}
|
||||
}
|
||||
|
@@ -1,218 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**/
|
||||
|
||||
/**
|
||||
* A class for truecolor image objects
|
||||
*
|
||||
* @package WideImage
|
||||
*/
|
||||
class WideImage_TrueColorImage extends WideImage_Image
|
||||
{
|
||||
/**
|
||||
* Creates the object
|
||||
*
|
||||
* @param resource $handle
|
||||
*/
|
||||
function __construct($handle)
|
||||
{
|
||||
parent::__construct($handle);
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A class for truecolor image objects.
|
||||
*/
|
||||
class WideImage_TrueColorImage extends WideImage_Image
|
||||
{
|
||||
/**
|
||||
* Creates the object.
|
||||
*
|
||||
* @param resource $handle
|
||||
*/
|
||||
public function __construct($handle)
|
||||
{
|
||||
parent::__construct($handle);
|
||||
$this->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 WideImage_InvalidImageDimensionException("Can't create an image with dimensions [$width, $height].");
|
||||
}
|
||||
|
||||
return new self(imagecreatetruecolor($width, $height));
|
||||
}
|
||||
|
||||
public function doCreate($width, $height)
|
||||
{
|
||||
return self::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']);
|
||||
} else {
|
||||
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 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
|
||||
*/
|
||||
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']);
|
||||
} 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
|
||||
*/
|
||||
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']);
|
||||
} else {
|
||||
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 WideImage_OperationFactory::get('CopyChannelsTrueColor')->execute($this, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc).
|
||||
*
|
||||
* @see WideImage_Image#copyNoAlpha()
|
||||
*/
|
||||
public 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()
|
||||
*/
|
||||
public function asTrueColor()
|
||||
{
|
||||
return $this->copy();
|
||||
}
|
||||
}
|
||||
|
@@ -1,377 +1,376 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
**/
|
||||
require_once WideImage::path().'Exception.php';
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package WideImage
|
||||
**/
|
||||
|
||||
require_once WideImage::path() . 'Exception.php';
|
||||
|
||||
require_once WideImage::path() . 'Image.php';
|
||||
require_once WideImage::path() . 'TrueColorImage.php';
|
||||
require_once WideImage::path() . 'PaletteImage.php';
|
||||
|
||||
require_once WideImage::path() . 'Coordinate.php';
|
||||
require_once WideImage::path() . 'Canvas.php';
|
||||
require_once WideImage::path() . 'MapperFactory.php';
|
||||
require_once WideImage::path() . 'OperationFactory.php';
|
||||
|
||||
require_once WideImage::path() . 'Font/TTF.php';
|
||||
require_once WideImage::path() . 'Font/GDF.php';
|
||||
require_once WideImage::path() . 'Font/PS.php';
|
||||
|
||||
/**
|
||||
* @package Exceptions
|
||||
*/
|
||||
class WideImage_InvalidImageHandleException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* @package Exceptions
|
||||
*/
|
||||
class WideImage_InvalidImageSourceException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* @package Exceptions
|
||||
*
|
||||
* Class for invalid GD function calls result (for example those that return bool)
|
||||
*/
|
||||
class WideImage_GDFunctionResultException extends WideImage_Exception {}
|
||||
|
||||
/**
|
||||
* The gateway class for loading images and core library functions
|
||||
*
|
||||
* @package WideImage
|
||||
*/
|
||||
class WideImage
|
||||
{
|
||||
const SIDE_TOP_LEFT = 1;
|
||||
const SIDE_TOP = 2;
|
||||
const SIDE_TOP_RIGHT = 4;
|
||||
const SIDE_RIGHT = 8;
|
||||
const SIDE_BOTTOM_RIGHT = 16;
|
||||
const SIDE_BOTTOM = 32;
|
||||
const SIDE_BOTTOM_LEFT = 64;
|
||||
const SIDE_LEFT = 128;
|
||||
const SIDE_ALL = 255;
|
||||
|
||||
/**
|
||||
* @var string Path to the library base directory
|
||||
*/
|
||||
protected static $path = null;
|
||||
|
||||
/**
|
||||
* Returns the library version
|
||||
* @return string The library version
|
||||
*/
|
||||
static function version()
|
||||
{
|
||||
return '11.02.19';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the library
|
||||
* @return string
|
||||
*/
|
||||
static function path()
|
||||
{
|
||||
if (self::$path === null)
|
||||
self::$path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
|
||||
return self::$path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the gd library is loaded, and throws an exception otherwise
|
||||
*/
|
||||
static function checkGD()
|
||||
{
|
||||
if (!extension_loaded('gd'))
|
||||
throw new WideImage_Exception("WideImage requires the GD extension, but it's apparently not loaded.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a custom mapper for image loading and saving
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* WideImage::registerCustomMapper('WideImage_Mapper_TGA', 'image/tga', 'tga');
|
||||
* </code>
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* <code>
|
||||
* $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
|
||||
* </code>
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* <b>Note:</b> 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.
|
||||
*
|
||||
* <code>
|
||||
* $handle = imagecreatefrompng('file.png');
|
||||
* $image = WideImage::loadFromHandle($handle);
|
||||
* </code>
|
||||
*
|
||||
* @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');
|
||||
|
||||
require_once WideImage::path().'Image.php';
|
||||
require_once WideImage::path().'TrueColorImage.php';
|
||||
require_once WideImage::path().'PaletteImage.php';
|
||||
|
||||
require_once WideImage::path().'Coordinate.php';
|
||||
require_once WideImage::path().'Canvas.php';
|
||||
require_once WideImage::path().'MapperFactory.php';
|
||||
require_once WideImage::path().'OperationFactory.php';
|
||||
|
||||
require_once WideImage::path().'Font/TTF.php';
|
||||
require_once WideImage::path().'Font/GDF.php';
|
||||
require_once WideImage::path().'Font/PS.php';
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_InvalidImageHandleException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_InvalidImageSourceException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_GDFunctionResultException extends WideImage_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The gateway class for loading images and core library functions.
|
||||
*/
|
||||
class WideImage
|
||||
{
|
||||
const SIDE_TOP_LEFT = 1;
|
||||
const SIDE_TOP = 2;
|
||||
const SIDE_TOP_RIGHT = 4;
|
||||
const SIDE_RIGHT = 8;
|
||||
const SIDE_BOTTOM_RIGHT = 16;
|
||||
const SIDE_BOTTOM = 32;
|
||||
const SIDE_BOTTOM_LEFT = 64;
|
||||
const SIDE_LEFT = 128;
|
||||
const SIDE_ALL = 255;
|
||||
|
||||
/**
|
||||
* @var string Path to the library base directory
|
||||
*/
|
||||
protected static $path = null;
|
||||
|
||||
/**
|
||||
* Returns the library version.
|
||||
*
|
||||
* @return string The library version
|
||||
*/
|
||||
public static function version()
|
||||
{
|
||||
return '11.02.19';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the library.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function path()
|
||||
{
|
||||
if (self::$path === null) {
|
||||
self::$path = dirname(__FILE__).DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
return self::$path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the gd library is loaded, and throws an exception otherwise.
|
||||
*/
|
||||
public static function checkGD()
|
||||
{
|
||||
if (!extension_loaded('gd')) {
|
||||
throw new WideImage_Exception("WideImage requires the GD extension, but it's apparently not loaded.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a custom mapper for image loading and saving.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* WideImage::registerCustomMapper('WideImage_Mapper_TGA', 'image/tga', 'tga');
|
||||
* </code>
|
||||
*
|
||||
* @param string $mapper_class_name
|
||||
* @param string $mime_type
|
||||
* @param string $extension
|
||||
*/
|
||||
public 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.
|
||||
*
|
||||
* <code>
|
||||
* $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
|
||||
* </code>
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public 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(['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
|
||||
*/
|
||||
public 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
|
||||
*/
|
||||
public 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.
|
||||
*
|
||||
* <b>Note:</b> 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.
|
||||
*
|
||||
* <code>
|
||||
* $handle = imagecreatefrompng('file.png');
|
||||
* $image = WideImage::loadFromHandle($handle);
|
||||
* </code>
|
||||
*
|
||||
* @param resource $handle A valid GD image resource
|
||||
*
|
||||
* @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance
|
||||
*/
|
||||
public 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
|
||||
*/
|
||||
public 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 = [];
|
||||
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
|
||||
*/
|
||||
public 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
|
||||
*/
|
||||
public 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
|
||||
*/
|
||||
public 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
|
||||
*/
|
||||
public 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');
|
||||
|
@@ -1,80 +1,79 @@
|
||||
<?php
|
||||
|
||||
require dirname(__FILE__) . '/../lib/WideImage.php';
|
||||
|
||||
define('TEST_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
|
||||
define('IMG_PATH', TEST_PATH . 'images' . DIRECTORY_SEPARATOR);
|
||||
|
||||
abstract class WideImage_TestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function load($file)
|
||||
{
|
||||
return WideImage::load(IMG_PATH . $file);
|
||||
}
|
||||
|
||||
function assertValidImage($image)
|
||||
{
|
||||
$this->assertInstanceOf("WideImage_Image", $image);
|
||||
$this->assertTrue($image->isValid());
|
||||
}
|
||||
|
||||
function assertDimensions($image, $width, $height)
|
||||
{
|
||||
$this->assertEquals($width, $image->getWidth());
|
||||
$this->assertEquals($height, $image->getHeight());
|
||||
}
|
||||
|
||||
function assertTransparentColorMatch($img1, $img2)
|
||||
{
|
||||
$tc1 = $img1->getTransparentColorRGB();
|
||||
$tc2 = $img2->getTransparentColorRGB();
|
||||
$this->assertEquals($tc1, $tc2);
|
||||
}
|
||||
|
||||
function assertTransparentColorAt($img, $x, $y)
|
||||
{
|
||||
$this->assertEquals($img->getTransparentColor(), $img->getColorAt($x, $y));
|
||||
}
|
||||
|
||||
function assertRGBWithinMargin($rec, $r, $g, $b, $a, $margin)
|
||||
{
|
||||
if (is_array($r))
|
||||
{
|
||||
$a = $r['alpha'];
|
||||
$b = $r['blue'];
|
||||
$g = $r['green'];
|
||||
$r = $r['red'];
|
||||
}
|
||||
|
||||
$result =
|
||||
abs($rec['red'] - $r) <= $margin &&
|
||||
abs($rec['green'] - $g) <= $margin &&
|
||||
abs($rec['blue'] - $b) <= $margin;
|
||||
|
||||
$result = $result && ($a === null || abs($rec['alpha'] - $a) <= $margin);
|
||||
|
||||
$this->assertTrue($result,
|
||||
"RGBA [{$rec['red']}, {$rec['green']}, {$rec['blue']}, {$rec['alpha']}] " .
|
||||
"doesn't match RGBA [$r, $g, $b, $a] within margin [$margin].");
|
||||
}
|
||||
|
||||
function assertRGBAt($img, $x, $y, $rgba)
|
||||
{
|
||||
if (is_array($rgba))
|
||||
$cmp = $img->getRGBAt($x, $y);
|
||||
else
|
||||
$cmp = $img->getColorAt($x, $y);
|
||||
$this->assertSame($cmp, $rgba);
|
||||
}
|
||||
|
||||
function assertRGBNear($rec, $r, $g = null, $b = null, $a = null)
|
||||
{
|
||||
$this->assertRGBWithinMargin($rec, $r, $g, $b, $a, 2);
|
||||
}
|
||||
|
||||
function assertRGBEqual($rec, $r, $g = null, $b = null, $a = null)
|
||||
{
|
||||
$this->assertRGBWithinMargin($rec, $r, $g, $b, $a, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
require dirname(__FILE__).'/../lib/WideImage.php';
|
||||
|
||||
define('TEST_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
|
||||
define('IMG_PATH', TEST_PATH.'images'.DIRECTORY_SEPARATOR);
|
||||
|
||||
abstract class WideImage_TestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function load($file)
|
||||
{
|
||||
return WideImage::load(IMG_PATH.$file);
|
||||
}
|
||||
|
||||
public function assertValidImage($image)
|
||||
{
|
||||
$this->assertInstanceOf('WideImage_Image', $image);
|
||||
$this->assertTrue($image->isValid());
|
||||
}
|
||||
|
||||
public function assertDimensions($image, $width, $height)
|
||||
{
|
||||
$this->assertEquals($width, $image->getWidth());
|
||||
$this->assertEquals($height, $image->getHeight());
|
||||
}
|
||||
|
||||
public function assertTransparentColorMatch($img1, $img2)
|
||||
{
|
||||
$tc1 = $img1->getTransparentColorRGB();
|
||||
$tc2 = $img2->getTransparentColorRGB();
|
||||
$this->assertEquals($tc1, $tc2);
|
||||
}
|
||||
|
||||
public function assertTransparentColorAt($img, $x, $y)
|
||||
{
|
||||
$this->assertEquals($img->getTransparentColor(), $img->getColorAt($x, $y));
|
||||
}
|
||||
|
||||
public function assertRGBWithinMargin($rec, $r, $g, $b, $a, $margin)
|
||||
{
|
||||
if (is_array($r)) {
|
||||
$a = $r['alpha'];
|
||||
$b = $r['blue'];
|
||||
$g = $r['green'];
|
||||
$r = $r['red'];
|
||||
}
|
||||
|
||||
$result =
|
||||
abs($rec['red'] - $r) <= $margin &&
|
||||
abs($rec['green'] - $g) <= $margin &&
|
||||
abs($rec['blue'] - $b) <= $margin;
|
||||
|
||||
$result = $result && ($a === null || abs($rec['alpha'] - $a) <= $margin);
|
||||
|
||||
$this->assertTrue($result,
|
||||
"RGBA [{$rec['red']}, {$rec['green']}, {$rec['blue']}, {$rec['alpha']}] ".
|
||||
"doesn't match RGBA [$r, $g, $b, $a] within margin [$margin].");
|
||||
}
|
||||
|
||||
public function assertRGBAt($img, $x, $y, $rgba)
|
||||
{
|
||||
if (is_array($rgba)) {
|
||||
$cmp = $img->getRGBAt($x, $y);
|
||||
} else {
|
||||
$cmp = $img->getColorAt($x, $y);
|
||||
}
|
||||
$this->assertSame($cmp, $rgba);
|
||||
}
|
||||
|
||||
public function assertRGBNear($rec, $r, $g = null, $b = null, $a = null)
|
||||
{
|
||||
$this->assertRGBWithinMargin($rec, $r, $g, $b, $a, 2);
|
||||
}
|
||||
|
||||
public function assertRGBEqual($rec, $r, $g = null, $b = null, $a = null)
|
||||
{
|
||||
$this->assertRGBWithinMargin($rec, $r, $g, $b, $a, 0);
|
||||
}
|
||||
}
|
||||
|
@@ -1,45 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
/**
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Canvas_Test extends WideImage_TestCase
|
||||
{
|
||||
function testCreate()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(10, 10);
|
||||
|
||||
$canvas1 = $img->getCanvas();
|
||||
$this->assertInstanceOf('WideImage_Canvas', $canvas1);
|
||||
|
||||
$canvas2 = $img->getCanvas();
|
||||
$this->assertSame($canvas1, $canvas2);
|
||||
}
|
||||
|
||||
function testMagicCallDrawRectangle()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(10, 10);
|
||||
$canvas = $img->getCanvas();
|
||||
$canvas->filledRectangle(1, 1, 5, 5, $img->allocateColorAlpha(255, 0, 0, 64));
|
||||
$this->assertRGBAt($img, 3, 3, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 64));
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class WideImage_Canvas_Test extends WideImage_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(10, 10);
|
||||
|
||||
$canvas1 = $img->getCanvas();
|
||||
$this->assertInstanceOf('WideImage_Canvas', $canvas1);
|
||||
|
||||
$canvas2 = $img->getCanvas();
|
||||
$this->assertSame($canvas1, $canvas2);
|
||||
}
|
||||
|
||||
public function testMagicCallDrawRectangle()
|
||||
{
|
||||
$img = WideImage::createTrueColorImage(10, 10);
|
||||
$canvas = $img->getCanvas();
|
||||
$canvas->filledRectangle(1, 1, 5, 5, $img->allocateColorAlpha(255, 0, 0, 64));
|
||||
$this->assertRGBAt($img, 3, 3, ['red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 64]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,105 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Coordinate_Test extends WideImage_TestCase
|
||||
{
|
||||
function testEvaluate()
|
||||
{
|
||||
$this->assertSame(400, WideImage_Coordinate::evaluate('+200%', 200));
|
||||
$this->assertSame(-1, WideImage_Coordinate::evaluate('-1', 200));
|
||||
$this->assertSame(10, WideImage_Coordinate::evaluate('+10', 200));
|
||||
$this->assertSame(40, WideImage_Coordinate::evaluate('+20%', 200));
|
||||
$this->assertSame(-11, WideImage_Coordinate::evaluate('-11.23', 200));
|
||||
$this->assertSame(-30, WideImage_Coordinate::evaluate('-15%', 200));
|
||||
}
|
||||
|
||||
function testFix()
|
||||
{
|
||||
$this->assertSame(10, WideImage_Coordinate::fix('10%', 100));
|
||||
$this->assertSame(10, WideImage_Coordinate::fix('10', 100));
|
||||
|
||||
$this->assertSame(-10, WideImage_Coordinate::fix('-10%', 100));
|
||||
$this->assertSame(-1, WideImage_Coordinate::fix('-1', 100));
|
||||
$this->assertSame(-50, WideImage_Coordinate::fix('-50%', 100));
|
||||
$this->assertSame(-100, WideImage_Coordinate::fix('-100%', 100));
|
||||
$this->assertSame(-1, WideImage_Coordinate::fix('-5%', 20));
|
||||
|
||||
$this->assertSame(300, WideImage_Coordinate::fix('150.12%', 200));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('150', 200));
|
||||
|
||||
$this->assertSame(100, WideImage_Coordinate::fix('100%-50%', 200));
|
||||
$this->assertSame(200, WideImage_Coordinate::fix('100%', 200));
|
||||
|
||||
$this->assertSame(130, WideImage_Coordinate::fix('50% -20', 300));
|
||||
$this->assertSame(12, WideImage_Coordinate::fix(' 12 - 0', 300));
|
||||
|
||||
$this->assertSame(15, WideImage_Coordinate::fix('50%', 30));
|
||||
$this->assertSame(15, WideImage_Coordinate::fix('50%-0', 30));
|
||||
$this->assertSame(15, WideImage_Coordinate::fix('50%+0', 30));
|
||||
$this->assertSame(0, WideImage_Coordinate::fix(' - 50% + 50%', 30));
|
||||
$this->assertSame(30, WideImage_Coordinate::fix(' 50% + 49.6666%', 30));
|
||||
}
|
||||
|
||||
function testAlign()
|
||||
{
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('left', 300, 120));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('center', 300, 120));
|
||||
$this->assertSame(180, WideImage_Coordinate::fix('right', 300, 120));
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('top', 300, 120));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('middle', 300, 120));
|
||||
$this->assertSame(180, WideImage_Coordinate::fix('bottom', 300, 120));
|
||||
|
||||
$this->assertSame(200, WideImage_Coordinate::fix('bottom+20', 300, 120));
|
||||
$this->assertSame(178, WideImage_Coordinate::fix('-2 + right', 300, 120));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('right - center', 300, 120));
|
||||
}
|
||||
|
||||
function testAlignWithoutSecondaryCoordinate()
|
||||
{
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('left', 300));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('center', 300));
|
||||
$this->assertSame(300, WideImage_Coordinate::fix('right', 300));
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('top', 300));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('middle', 300));
|
||||
$this->assertSame(300, WideImage_Coordinate::fix('bottom', 300));
|
||||
|
||||
$this->assertSame(320, WideImage_Coordinate::fix('bottom+20', 300));
|
||||
$this->assertSame(280, WideImage_Coordinate::fix('-20 + right', 300));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('right - center', 300));
|
||||
}
|
||||
|
||||
function testMultipleOperands()
|
||||
{
|
||||
$this->assertSame(6, WideImage_Coordinate::fix('100%-100+1 + 5', 100));
|
||||
$this->assertSame(1, WideImage_Coordinate::fix('right +1- 100 - 50%', 200));
|
||||
$this->assertSame(200, WideImage_Coordinate::fix('-right+right +100%', 200));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('100--++++-10', 200));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_InvalidCoordinateException
|
||||
*/
|
||||
function testInvalidSyntaxEndsWithOperator()
|
||||
{
|
||||
WideImage_Coordinate::fix('5+2+', 10);
|
||||
}
|
||||
}
|
||||
/**
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**/
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_Coordinate_Test extends WideImage_TestCase
|
||||
{
|
||||
public function testEvaluate()
|
||||
{
|
||||
$this->assertSame(400, WideImage_Coordinate::evaluate('+200%', 200));
|
||||
$this->assertSame(-1, WideImage_Coordinate::evaluate('-1', 200));
|
||||
$this->assertSame(10, WideImage_Coordinate::evaluate('+10', 200));
|
||||
$this->assertSame(40, WideImage_Coordinate::evaluate('+20%', 200));
|
||||
$this->assertSame(-11, WideImage_Coordinate::evaluate('-11.23', 200));
|
||||
$this->assertSame(-30, WideImage_Coordinate::evaluate('-15%', 200));
|
||||
}
|
||||
|
||||
public function testFix()
|
||||
{
|
||||
$this->assertSame(10, WideImage_Coordinate::fix('10%', 100));
|
||||
$this->assertSame(10, WideImage_Coordinate::fix('10', 100));
|
||||
|
||||
$this->assertSame(-10, WideImage_Coordinate::fix('-10%', 100));
|
||||
$this->assertSame(-1, WideImage_Coordinate::fix('-1', 100));
|
||||
$this->assertSame(-50, WideImage_Coordinate::fix('-50%', 100));
|
||||
$this->assertSame(-100, WideImage_Coordinate::fix('-100%', 100));
|
||||
$this->assertSame(-1, WideImage_Coordinate::fix('-5%', 20));
|
||||
|
||||
$this->assertSame(300, WideImage_Coordinate::fix('150.12%', 200));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('150', 200));
|
||||
|
||||
$this->assertSame(100, WideImage_Coordinate::fix('100%-50%', 200));
|
||||
$this->assertSame(200, WideImage_Coordinate::fix('100%', 200));
|
||||
|
||||
$this->assertSame(130, WideImage_Coordinate::fix('50% -20', 300));
|
||||
$this->assertSame(12, WideImage_Coordinate::fix(' 12 - 0', 300));
|
||||
|
||||
$this->assertSame(15, WideImage_Coordinate::fix('50%', 30));
|
||||
$this->assertSame(15, WideImage_Coordinate::fix('50%-0', 30));
|
||||
$this->assertSame(15, WideImage_Coordinate::fix('50%+0', 30));
|
||||
$this->assertSame(0, WideImage_Coordinate::fix(' - 50% + 50%', 30));
|
||||
$this->assertSame(30, WideImage_Coordinate::fix(' 50% + 49.6666%', 30));
|
||||
}
|
||||
|
||||
public function testAlign()
|
||||
{
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('left', 300, 120));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('center', 300, 120));
|
||||
$this->assertSame(180, WideImage_Coordinate::fix('right', 300, 120));
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('top', 300, 120));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('middle', 300, 120));
|
||||
$this->assertSame(180, WideImage_Coordinate::fix('bottom', 300, 120));
|
||||
|
||||
$this->assertSame(200, WideImage_Coordinate::fix('bottom+20', 300, 120));
|
||||
$this->assertSame(178, WideImage_Coordinate::fix('-2 + right', 300, 120));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('right - center', 300, 120));
|
||||
}
|
||||
|
||||
public function testAlignWithoutSecondaryCoordinate()
|
||||
{
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('left', 300));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('center', 300));
|
||||
$this->assertSame(300, WideImage_Coordinate::fix('right', 300));
|
||||
$this->assertSame(0, WideImage_Coordinate::fix('top', 300));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('middle', 300));
|
||||
$this->assertSame(300, WideImage_Coordinate::fix('bottom', 300));
|
||||
|
||||
$this->assertSame(320, WideImage_Coordinate::fix('bottom+20', 300));
|
||||
$this->assertSame(280, WideImage_Coordinate::fix('-20 + right', 300));
|
||||
$this->assertSame(150, WideImage_Coordinate::fix('right - center', 300));
|
||||
}
|
||||
|
||||
public function testMultipleOperands()
|
||||
{
|
||||
$this->assertSame(6, WideImage_Coordinate::fix('100%-100+1 + 5', 100));
|
||||
$this->assertSame(1, WideImage_Coordinate::fix('right +1- 100 - 50%', 200));
|
||||
$this->assertSame(200, WideImage_Coordinate::fix('-right+right +100%', 200));
|
||||
$this->assertSame(90, WideImage_Coordinate::fix('100--++++-10', 200));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_InvalidCoordinateException
|
||||
*/
|
||||
public function testInvalidSyntaxEndsWithOperator()
|
||||
{
|
||||
WideImage_Coordinate::fix('5+2+', 10);
|
||||
}
|
||||
}
|
||||
|
@@ -1,190 +1,170 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_CustomOp
|
||||
{
|
||||
static public $args = null;
|
||||
|
||||
function execute()
|
||||
{
|
||||
self::$args = func_get_args();
|
||||
return self::$args[0]->copy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class ImageForOutput extends WideImage_TrueColorImage
|
||||
{
|
||||
public $headers = array();
|
||||
|
||||
function writeHeader($name, $data)
|
||||
{
|
||||
$this->headers[$name] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class TestableImage extends WideImage_TrueColorImage
|
||||
{
|
||||
public $headers = array();
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function writeHeader($name, $data)
|
||||
{
|
||||
$this->headers[$name] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Image_Test extends WideImage_TestCase
|
||||
{
|
||||
function testFactories()
|
||||
{
|
||||
$this->assertTrue(WideImage::createTrueColorImage(100, 100) instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue(WideImage::createPaletteImage(100, 100) instanceof WideImage_PaletteImage);
|
||||
}
|
||||
|
||||
function testDestructorUponUnset()
|
||||
{
|
||||
$img = $this->getMock('WideImage_TrueColorImage', array(), array(imagecreatetruecolor(10, 10)));
|
||||
$img->expectOnce('destroy');
|
||||
unset($img);
|
||||
$img = null;
|
||||
|
||||
for ($i = 0; $i++; $i < 1000);
|
||||
}
|
||||
|
||||
function testDestructorUponNull()
|
||||
{
|
||||
$img = $this->getMock('WideImage_TrueColorImage', array(), array(imagecreatetruecolor(10, 10)));
|
||||
$img->expectOnce('destroy');
|
||||
$img = null;
|
||||
|
||||
for ($i = 0; $i++; $i < 1000);
|
||||
}
|
||||
|
||||
function testAutoDestruct()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$handle = $img->getHandle();
|
||||
|
||||
unset($img);
|
||||
|
||||
$this->assertFalse(WideImage::isValidImageHandle($handle));
|
||||
}
|
||||
|
||||
function testAutoDestructWithRelease()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$handle = $img->getHandle();
|
||||
|
||||
$img->releaseHandle();
|
||||
unset($img);
|
||||
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testCustomOpMagic()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$result = $img->customOp(123, 'abc');
|
||||
$this->assertTrue($result instanceof WideImage_Image);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[0], $img);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[1], 123);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[2], 'abc');
|
||||
}
|
||||
|
||||
function testCustomOpCaseInsensitive()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$result = $img->CUSTomOP(123, 'abc');
|
||||
$this->assertTrue($result instanceof WideImage_Image);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[0], $img);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[1], 123);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[2], 'abc');
|
||||
}
|
||||
|
||||
function testInternalOpCaseInsensitive()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$result = $img->AUTOcrop();
|
||||
$this->assertTrue($result instanceof WideImage_Image);
|
||||
}
|
||||
|
||||
function testOutput()
|
||||
{
|
||||
$tmp = WideImage::load(IMG_PATH . 'fgnl.jpg');
|
||||
$img = new ImageForOutput($tmp->getHandle());
|
||||
|
||||
ob_start();
|
||||
$img->output('png');
|
||||
$data = ob_get_clean();
|
||||
|
||||
$this->assertEquals(array('Content-length' => strlen($data), 'Content-type' => 'image/png'), $img->headers);
|
||||
}
|
||||
|
||||
function testCanvasInstance()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . 'fgnl.jpg');
|
||||
$canvas1 = $img->getCanvas();
|
||||
$this->assertTrue($canvas1 instanceof WideImage_Canvas);
|
||||
$canvas2 = $img->getCanvas();
|
||||
$this->assertTrue($canvas1 === $canvas2);
|
||||
}
|
||||
|
||||
function testSerializeTrueColorImage()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . 'fgnl.jpg');
|
||||
$img2 = unserialize(serialize($img));
|
||||
$this->assertEquals(get_class($img2), get_class($img));
|
||||
$this->assertTrue($img2->isTrueColor());
|
||||
$this->assertTrue($img2->isValid());
|
||||
$this->assertFalse($img2->isTransparent());
|
||||
$this->assertEquals($img->getWidth(), $img2->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $img2->getHeight());
|
||||
}
|
||||
|
||||
function testSerializePaletteImage()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$img2 = unserialize(serialize($img));
|
||||
$this->assertEquals(get_class($img2), get_class($img));
|
||||
$this->assertFalse($img2->isTrueColor());
|
||||
$this->assertTrue($img2->isValid());
|
||||
$this->assertTrue($img2->isTransparent());
|
||||
$this->assertEquals($img->getWidth(), $img2->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $img2->getHeight());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_Operation_CustomOp
|
||||
{
|
||||
public static $args = null;
|
||||
|
||||
public function execute()
|
||||
{
|
||||
self::$args = func_get_args();
|
||||
|
||||
return self::$args[0]->copy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class ImageForOutput extends WideImage_TrueColorImage
|
||||
{
|
||||
public $headers = [];
|
||||
|
||||
public function writeHeader($name, $data)
|
||||
{
|
||||
$this->headers[$name] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class TestableImage extends WideImage_TrueColorImage
|
||||
{
|
||||
public $headers = [];
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
}
|
||||
|
||||
public function writeHeader($name, $data)
|
||||
{
|
||||
$this->headers[$name] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_Image_Test extends WideImage_TestCase
|
||||
{
|
||||
public function testFactories()
|
||||
{
|
||||
$this->assertTrue(WideImage::createTrueColorImage(100, 100) instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue(WideImage::createPaletteImage(100, 100) instanceof WideImage_PaletteImage);
|
||||
}
|
||||
|
||||
public function testDestructorUponUnset()
|
||||
{
|
||||
$img = $this->getMock('WideImage_TrueColorImage', [], [imagecreatetruecolor(10, 10)]);
|
||||
$img->expectOnce('destroy');
|
||||
unset($img);
|
||||
$img = null;
|
||||
|
||||
for ($i = 0; $i++; $i < 1000);
|
||||
}
|
||||
|
||||
public function testDestructorUponNull()
|
||||
{
|
||||
$img = $this->getMock('WideImage_TrueColorImage', [], [imagecreatetruecolor(10, 10)]);
|
||||
$img->expectOnce('destroy');
|
||||
$img = null;
|
||||
|
||||
for ($i = 0; $i++; $i < 1000);
|
||||
}
|
||||
|
||||
public function testAutoDestruct()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$handle = $img->getHandle();
|
||||
|
||||
unset($img);
|
||||
|
||||
$this->assertFalse(WideImage::isValidImageHandle($handle));
|
||||
}
|
||||
|
||||
public function testAutoDestructWithRelease()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$handle = $img->getHandle();
|
||||
|
||||
$img->releaseHandle();
|
||||
unset($img);
|
||||
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testCustomOpMagic()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$result = $img->customOp(123, 'abc');
|
||||
$this->assertTrue($result instanceof WideImage_Image);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[0], $img);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[1], 123);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[2], 'abc');
|
||||
}
|
||||
|
||||
public function testCustomOpCaseInsensitive()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$result = $img->CUSTomOP(123, 'abc');
|
||||
$this->assertTrue($result instanceof WideImage_Image);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[0], $img);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[1], 123);
|
||||
$this->assertSame(WideImage_Operation_CustomOp::$args[2], 'abc');
|
||||
}
|
||||
|
||||
public function testInternalOpCaseInsensitive()
|
||||
{
|
||||
$img = WideImage_TrueColorImage::create(10, 10);
|
||||
$result = $img->AUTOcrop();
|
||||
$this->assertTrue($result instanceof WideImage_Image);
|
||||
}
|
||||
|
||||
public function testOutput()
|
||||
{
|
||||
$tmp = WideImage::load(IMG_PATH.'fgnl.jpg');
|
||||
$img = new ImageForOutput($tmp->getHandle());
|
||||
|
||||
ob_start();
|
||||
$img->output('png');
|
||||
$data = ob_get_clean();
|
||||
|
||||
$this->assertEquals(['Content-length' => strlen($data), 'Content-type' => 'image/png'], $img->headers);
|
||||
}
|
||||
|
||||
public function testCanvasInstance()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'fgnl.jpg');
|
||||
$canvas1 = $img->getCanvas();
|
||||
$this->assertTrue($canvas1 instanceof WideImage_Canvas);
|
||||
$canvas2 = $img->getCanvas();
|
||||
$this->assertTrue($canvas1 === $canvas2);
|
||||
}
|
||||
|
||||
public function testSerializeTrueColorImage()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'fgnl.jpg');
|
||||
$img2 = unserialize(serialize($img));
|
||||
$this->assertEquals(get_class($img2), get_class($img));
|
||||
$this->assertTrue($img2->isTrueColor());
|
||||
$this->assertTrue($img2->isValid());
|
||||
$this->assertFalse($img2->isTransparent());
|
||||
$this->assertEquals($img->getWidth(), $img2->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $img2->getHeight());
|
||||
}
|
||||
|
||||
public function testSerializePaletteImage()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'100x100-color-hole.gif');
|
||||
$img2 = unserialize(serialize($img));
|
||||
$this->assertEquals(get_class($img2), get_class($img));
|
||||
$this->assertFalse($img2->isTrueColor());
|
||||
$this->assertTrue($img2->isValid());
|
||||
$this->assertTrue($img2->isTransparent());
|
||||
$this->assertEquals($img->getWidth(), $img2->getWidth());
|
||||
$this->assertEquals($img->getHeight(), $img2->getHeight());
|
||||
}
|
||||
}
|
||||
|
@@ -1,80 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/BMP.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_BMP_Test extends WideImage_TestCase
|
||||
{
|
||||
/**
|
||||
* @var WideImage_Mapper_BMP
|
||||
*/
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'bmp');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . 'fgnl.bmp');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(174, imagesx($handle));
|
||||
$this->assertEquals(287, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = WideImage_vendor_de77_BMP::imagecreatefrombmp(IMG_PATH . 'fgnl.bmp');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = $this->mapper->loadFromString($string);
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.bmp');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.bmp') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = $this->mapper->load(IMG_PATH . 'temp/test.bmp');
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
include WideImage::path().'Mapper/BMP.php';
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_Mapper_BMP_Test extends WideImage_TestCase
|
||||
{
|
||||
/**
|
||||
* @var WideImage_Mapper_BMP
|
||||
*/
|
||||
protected $mapper;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'bmp');
|
||||
}
|
||||
|
||||
public function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH.'fgnl.bmp');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(174, imagesx($handle));
|
||||
$this->assertEquals(287, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveToString()
|
||||
{
|
||||
$handle = WideImage_vendor_de77_BMP::imagecreatefrombmp(IMG_PATH.'fgnl.bmp');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = $this->mapper->loadFromString($string);
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH.'100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH.'temp/test.bmp');
|
||||
$this->assertTrue(filesize(IMG_PATH.'temp/test.bmp') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = $this->mapper->load(IMG_PATH.'temp/test.bmp');
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
|
@@ -1,71 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/GD2.php';
|
||||
/**
|
||||
|
||||
**/
|
||||
include WideImage::path().'Mapper/GD2.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_GD2_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'gd2');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.gd2'))
|
||||
unlink(IMG_PATH . 'temp/test.gd2');
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.gd2');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.gd2') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefromgd2(IMG_PATH . 'temp/test.gd2');
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class WideImage_Mapper_GD2_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'gd2');
|
||||
}
|
||||
|
||||
public function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH.'temp/test.gd2')) {
|
||||
unlink(IMG_PATH.'temp/test.gd2');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH.'100x100-color-hole.gif');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH.'100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH.'temp/test.gd2');
|
||||
$this->assertTrue(filesize(IMG_PATH.'temp/test.gd2') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefromgd2(IMG_PATH.'temp/test.gd2');
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
|
@@ -1,59 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/GD.php';
|
||||
/**
|
||||
|
||||
**/
|
||||
include WideImage::path().'Mapper/GD.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_GD_Test extends WideImage_TestCase
|
||||
{
|
||||
/**
|
||||
* @var WideImage_Mapper_GD
|
||||
*/
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'gd');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.gd'))
|
||||
unlink(IMG_PATH . 'temp/test.gd');
|
||||
}
|
||||
|
||||
function testSaveAndLoad()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.gd');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.gd') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = $this->mapper->load(IMG_PATH . 'temp/test.gd');
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class WideImage_Mapper_GD_Test extends WideImage_TestCase
|
||||
{
|
||||
/**
|
||||
* @var WideImage_Mapper_GD
|
||||
*/
|
||||
protected $mapper;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'gd');
|
||||
}
|
||||
|
||||
public function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH.'temp/test.gd')) {
|
||||
unlink(IMG_PATH.'temp/test.gd');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSaveAndLoad()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH.'100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH.'temp/test.gd');
|
||||
$this->assertTrue(filesize(IMG_PATH.'temp/test.gd') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = $this->mapper->load(IMG_PATH.'temp/test.gd');
|
||||
$this->assertTrue(WideImage::isValidImageHandle($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
|
@@ -1,83 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/GIF.php';
|
||||
/**
|
||||
|
||||
**/
|
||||
include WideImage::path().'Mapper/GIF.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*
|
||||
* @group Mapper
|
||||
* @group GIF
|
||||
*/
|
||||
class WideImage_Mapper_GIF_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'gif');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.gif'))
|
||||
unlink(IMG_PATH . 'temp/test.gif');
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(100, imagesx($handle));
|
||||
$this->assertEquals(100, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.gif');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.gif') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefromgif(IMG_PATH . 'temp/test.gif');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @group Mapper
|
||||
* @group GIF
|
||||
*/
|
||||
class WideImage_Mapper_GIF_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'gif');
|
||||
}
|
||||
|
||||
public function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH.'temp/test.gif')) {
|
||||
unlink(IMG_PATH.'temp/test.gif');
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH.'100x100-color-hole.gif');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(100, imagesx($handle));
|
||||
$this->assertEquals(100, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH.'100x100-color-hole.gif');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH.'100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH.'temp/test.gif');
|
||||
$this->assertTrue(filesize(IMG_PATH.'temp/test.gif') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefromgif(IMG_PATH.'temp/test.gif');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
|
@@ -1,98 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/JPEG.php';
|
||||
/**
|
||||
|
||||
**/
|
||||
include WideImage::path().'Mapper/JPEG.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_JPEG_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'jpg');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.jpg'))
|
||||
unlink(IMG_PATH . 'temp/test.jpg');
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . 'fgnl.jpg');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(174, imagesx($handle));
|
||||
$this->assertEquals(287, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefromjpeg(IMG_PATH . 'fgnl.jpg');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromjpeg(IMG_PATH . 'fgnl.jpg');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.jpg');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.jpg') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefromjpeg(IMG_PATH . 'temp/test.jpg');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testQuality()
|
||||
{
|
||||
$handle = imagecreatefromjpeg(IMG_PATH . 'fgnl.jpg');
|
||||
|
||||
ob_start();
|
||||
$this->mapper->save($handle, null, 100);
|
||||
$hq = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
$this->mapper->save($handle, null, 10);
|
||||
$lq = ob_get_clean();
|
||||
|
||||
$this->assertTrue(strlen($hq) > 0);
|
||||
$this->assertTrue(strlen($lq) > 0);
|
||||
$this->assertTrue(strlen($hq) > strlen($lq));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class WideImage_Mapper_JPEG_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'jpg');
|
||||
}
|
||||
|
||||
public function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH.'temp/test.jpg')) {
|
||||
unlink(IMG_PATH.'temp/test.jpg');
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH.'fgnl.jpg');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(174, imagesx($handle));
|
||||
$this->assertEquals(287, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefromjpeg(IMG_PATH.'fgnl.jpg');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefromjpeg(IMG_PATH.'fgnl.jpg');
|
||||
$this->mapper->save($handle, IMG_PATH.'temp/test.jpg');
|
||||
$this->assertTrue(filesize(IMG_PATH.'temp/test.jpg') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefromjpeg(IMG_PATH.'temp/test.jpg');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testQuality()
|
||||
{
|
||||
$handle = imagecreatefromjpeg(IMG_PATH.'fgnl.jpg');
|
||||
|
||||
ob_start();
|
||||
$this->mapper->save($handle, null, 100);
|
||||
$hq = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
$this->mapper->save($handle, null, 10);
|
||||
$lq = ob_get_clean();
|
||||
|
||||
$this->assertTrue(strlen($hq) > 0);
|
||||
$this->assertTrue(strlen($lq) > 0);
|
||||
$this->assertTrue(strlen($hq) > strlen($lq));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
}
|
||||
|
@@ -1,93 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/PNG.php';
|
||||
/**
|
||||
|
||||
**/
|
||||
include WideImage::path().'Mapper/PNG.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Mapper_PNG_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'png');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH . 'temp/test.png'))
|
||||
unlink(IMG_PATH . 'temp/test.png');
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . '100x100-color-hole.png');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(100, imagesx($handle));
|
||||
$this->assertEquals(100, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefrompng(IMG_PATH . '100x100-color-hole.png');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefrompng(IMG_PATH . '100x100-color-hole.png');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.png');
|
||||
$this->assertTrue(filesize(IMG_PATH . 'temp/test.png') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefrompng(IMG_PATH . 'temp/test.png');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
function testSaveCompression()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . '100x100-rainbow.png');
|
||||
$file1 = IMG_PATH . 'temp/test-comp-0.png';
|
||||
$file2 = IMG_PATH . 'temp/test-comp-9.png';
|
||||
$this->mapper->save($handle, $file1, 0);
|
||||
$this->mapper->save($handle, $file2, 9);
|
||||
$this->assertTrue(filesize($file1) > filesize($file2));
|
||||
|
||||
unlink($file1);
|
||||
unlink($file2);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class WideImage_Mapper_PNG_Test extends WideImage_TestCase
|
||||
{
|
||||
protected $mapper;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'png');
|
||||
}
|
||||
|
||||
public function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
|
||||
if (file_exists(IMG_PATH.'temp/test.png')) {
|
||||
unlink(IMG_PATH.'temp/test.png');
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH.'100x100-color-hole.png');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(100, imagesx($handle));
|
||||
$this->assertEquals(100, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveToString()
|
||||
{
|
||||
$handle = imagecreatefrompng(IMG_PATH.'100x100-color-hole.png');
|
||||
ob_start();
|
||||
$this->mapper->save($handle);
|
||||
$string = ob_get_clean();
|
||||
$this->assertTrue(strlen($string) > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// string contains valid image data
|
||||
$handle = imagecreatefromstring($string);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveToFile()
|
||||
{
|
||||
$handle = imagecreatefrompng(IMG_PATH.'100x100-color-hole.png');
|
||||
$this->mapper->save($handle, IMG_PATH.'temp/test.png');
|
||||
$this->assertTrue(filesize(IMG_PATH.'temp/test.png') > 0);
|
||||
imagedestroy($handle);
|
||||
|
||||
// file is a valid image
|
||||
$handle = imagecreatefrompng(IMG_PATH.'temp/test.png');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
public function testSaveCompression()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH.'100x100-rainbow.png');
|
||||
$file1 = IMG_PATH.'temp/test-comp-0.png';
|
||||
$file2 = IMG_PATH.'temp/test-comp-9.png';
|
||||
$this->mapper->save($handle, $file1, 0);
|
||||
$this->mapper->save($handle, $file2, 9);
|
||||
$this->assertTrue(filesize($file1) > filesize($file2));
|
||||
|
||||
unlink($file1);
|
||||
unlink($file2);
|
||||
}
|
||||
}
|
||||
|
@@ -1,71 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
include WideImage::path() . 'Mapper/TGA.php';
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group mapper
|
||||
*/
|
||||
class WideImage_Mapper_TGA_Test extends WideImage_TestCase
|
||||
{
|
||||
/**
|
||||
* @var WideImage_Mapper_TGA
|
||||
*/
|
||||
protected $mapper;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'tga');
|
||||
}
|
||||
|
||||
function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
}
|
||||
|
||||
function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH . 'splat.tga');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(100, imagesx($handle));
|
||||
$this->assertEquals(100, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_Exception
|
||||
*/
|
||||
function testSaveToStringNotSupported()
|
||||
{
|
||||
$handle = WideImage_vendor_de77_BMP::imagecreatefrombmp(IMG_PATH . 'splat.tga');
|
||||
$this->mapper->save($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_Exception
|
||||
*/
|
||||
function testSaveToFileNotSupported()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH . 'temp/test.bmp');
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
include WideImage::path().'Mapper/TGA.php';
|
||||
|
||||
/**
|
||||
* @group mapper
|
||||
*/
|
||||
class WideImage_Mapper_TGA_Test extends WideImage_TestCase
|
||||
{
|
||||
/**
|
||||
* @var WideImage_Mapper_TGA
|
||||
*/
|
||||
protected $mapper;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->mapper = WideImage_MapperFactory::selectMapper(null, 'tga');
|
||||
}
|
||||
|
||||
public function teardown()
|
||||
{
|
||||
$this->mapper = null;
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$handle = $this->mapper->load(IMG_PATH.'splat.tga');
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$this->assertEquals(100, imagesx($handle));
|
||||
$this->assertEquals(100, imagesy($handle));
|
||||
imagedestroy($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_Exception
|
||||
*/
|
||||
public function testSaveToStringNotSupported()
|
||||
{
|
||||
$handle = WideImage_vendor_de77_BMP::imagecreatefrombmp(IMG_PATH.'splat.tga');
|
||||
$this->mapper->save($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException WideImage_Exception
|
||||
*/
|
||||
public function testSaveToFileNotSupported()
|
||||
{
|
||||
$handle = imagecreatefromgif(IMG_PATH.'100x100-color-hole.gif');
|
||||
$this->mapper->save($handle, IMG_PATH.'temp/test.bmp');
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_MapperFactory_Test extends WideImage_TestCase
|
||||
{
|
||||
function testMapperPNGByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.png');
|
||||
$this->assertInstanceOf("WideImage_Mapper_PNG", $mapper);
|
||||
}
|
||||
|
||||
function testMapperGIFByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.gif');
|
||||
$this->assertInstanceOf("WideImage_Mapper_GIF", $mapper);
|
||||
}
|
||||
|
||||
function testMapperJPGByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.jpg');
|
||||
$this->assertInstanceOf("WideImage_Mapper_JPEG", $mapper);
|
||||
}
|
||||
|
||||
function testMapperBMPByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.bmp');
|
||||
$this->assertInstanceOf("WideImage_Mapper_BMP", $mapper);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_MapperFactory_Test extends WideImage_TestCase
|
||||
{
|
||||
public function testMapperPNGByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.png');
|
||||
$this->assertInstanceOf('WideImage_Mapper_PNG', $mapper);
|
||||
}
|
||||
|
||||
public function testMapperGIFByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.gif');
|
||||
$this->assertInstanceOf('WideImage_Mapper_GIF', $mapper);
|
||||
}
|
||||
|
||||
public function testMapperJPGByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.jpg');
|
||||
$this->assertInstanceOf('WideImage_Mapper_JPEG', $mapper);
|
||||
}
|
||||
|
||||
public function testMapperBMPByURI()
|
||||
{
|
||||
$mapper = WideImage_MapperFactory::selectMapper('uri.bmp');
|
||||
$this->assertInstanceOf('WideImage_Mapper_BMP', $mapper);
|
||||
}
|
||||
}
|
||||
|
@@ -1,39 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_ApplyConvolution_Test extends WideImage_TestCase
|
||||
{
|
||||
function testApplyConvolution()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$result = $img->applyConvolution(array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1)), 1, 220);
|
||||
|
||||
$this->assertTrue($result instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_ApplyConvolution_Test extends WideImage_TestCase
|
||||
{
|
||||
public function testApplyConvolution()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'100x100-color-hole.gif');
|
||||
$result = $img->applyConvolution([[2, 0, 0], [0, -1, 0], [0, 0, -1]], 1, 220);
|
||||
|
||||
$this->assertTrue($result instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
}
|
||||
}
|
||||
|
@@ -1,39 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_ApplyFilter_Test extends WideImage_TestCase
|
||||
{
|
||||
function testApplyFilter()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$result = $img->applyFilter(IMG_FILTER_EDGEDETECT);
|
||||
|
||||
$this->assertTrue($result instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
* @group operation
|
||||
*/
|
||||
class WideImage_Operation_ApplyFilter_Test extends WideImage_TestCase
|
||||
{
|
||||
public function testApplyFilter()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'100x100-color-hole.gif');
|
||||
$result = $img->applyFilter(IMG_FILTER_EDGEDETECT);
|
||||
|
||||
$this->assertTrue($result instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
}
|
||||
}
|
||||
|
@@ -1,43 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_ApplyMask_Test extends WideImage_TestCase
|
||||
{
|
||||
function testApplyMask()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
$mask = WideImage::load(IMG_PATH . '75x25-gray.png');
|
||||
|
||||
$result = $img->applyMask($mask);
|
||||
$this->assertTrue($result instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
|
||||
$this->assertRGBNear($result->getRGBAt(10, 10), 255, 255, 255);
|
||||
$this->assertRGBNear($result->getRGBAt(30, 10), 255, 255, 0, 64);
|
||||
$this->assertRGBNear($result->getRGBAt(60, 10), 0, 0, 255, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_Operation_ApplyMask_Test extends WideImage_TestCase
|
||||
{
|
||||
public function testApplyMask()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'100x100-color-hole.gif');
|
||||
$mask = WideImage::load(IMG_PATH.'75x25-gray.png');
|
||||
|
||||
$result = $img->applyMask($mask);
|
||||
$this->assertTrue($result instanceof WideImage_TrueColorImage);
|
||||
$this->assertTrue($result->isTransparent());
|
||||
|
||||
$this->assertEquals(100, $result->getWidth());
|
||||
$this->assertEquals(100, $result->getHeight());
|
||||
|
||||
$this->assertRGBNear($result->getRGBAt(10, 10), 255, 255, 255);
|
||||
$this->assertRGBNear($result->getRGBAt(30, 10), 255, 255, 0, 64);
|
||||
$this->assertRGBNear($result->getRGBAt(60, 10), 0, 0, 255, 0);
|
||||
}
|
||||
}
|
||||
|
@@ -1,82 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_AsGrayscale_Test extends WideImage_TestCase
|
||||
{
|
||||
function skip()
|
||||
{
|
||||
$this->skipUnless(function_exists('imagefilter'));
|
||||
}
|
||||
|
||||
function testTransparentGIF()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
|
||||
|
||||
$gray = $img->asGrayscale();
|
||||
$this->assertTrue($gray instanceof WideImage_PaletteImage);
|
||||
|
||||
$this->assertEquals(100, $gray->getWidth());
|
||||
$this->assertEquals(100, $gray->getHeight());
|
||||
|
||||
$this->assertRGBNear($gray->getRGBAt(10, 10), 227, 227, 227);
|
||||
$this->assertRGBNear($gray->getRGBAt(90, 10), 28, 28, 28);
|
||||
$this->assertRGBNear($gray->getRGBAt(90, 90), 150, 150, 150);
|
||||
$this->assertRGBNear($gray->getRGBAt(10, 90), 76, 76, 76);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($gray->isTransparent());
|
||||
$this->assertEquals($gray->getColorAt(50, 50), $gray->getTransparentColor());
|
||||
}
|
||||
|
||||
function testTransparentLogoGIF()
|
||||
{
|
||||
$img = $this->load('logo.gif');
|
||||
$this->assertTransparentColorAt($img, 1, 1);
|
||||
|
||||
$res = $img->asGrayscale();
|
||||
$this->assertDimensions($res, 150, 23);
|
||||
$this->assertInstanceOf("WideImage_PaletteImage", $res);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorAt($res, 1, 1);
|
||||
}
|
||||
|
||||
function testPNGAlpha()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png');
|
||||
|
||||
$gray = $img->asGrayscale();
|
||||
$this->assertTrue($gray instanceof WideImage_TrueColorImage);
|
||||
$this->assertEquals(100, $gray->getWidth());
|
||||
$this->assertEquals(100, $gray->getHeight());
|
||||
|
||||
$this->assertRGBNear($gray->getRGBAt(25, 25), 29, 29, 29, 32);
|
||||
$this->assertRGBNear($gray->getRGBAt(75, 25), 29, 29, 29, 64);
|
||||
$this->assertRGBNear($gray->getRGBAt(75, 75), 29, 29, 29, 96);
|
||||
$this->assertRGBNear($gray->getRGBAt(25, 75), 0, 0, 0, 127);
|
||||
|
||||
$this->assertFalse($gray->isTransparent());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_Operation_AsGrayscale_Test extends WideImage_TestCase
|
||||
{
|
||||
public function skip()
|
||||
{
|
||||
$this->skipUnless(function_exists('imagefilter'));
|
||||
}
|
||||
|
||||
public function testTransparentGIF()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'100x100-color-hole.gif');
|
||||
|
||||
$gray = $img->asGrayscale();
|
||||
$this->assertTrue($gray instanceof WideImage_PaletteImage);
|
||||
|
||||
$this->assertEquals(100, $gray->getWidth());
|
||||
$this->assertEquals(100, $gray->getHeight());
|
||||
|
||||
$this->assertRGBNear($gray->getRGBAt(10, 10), 227, 227, 227);
|
||||
$this->assertRGBNear($gray->getRGBAt(90, 10), 28, 28, 28);
|
||||
$this->assertRGBNear($gray->getRGBAt(90, 90), 150, 150, 150);
|
||||
$this->assertRGBNear($gray->getRGBAt(10, 90), 76, 76, 76);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($gray->isTransparent());
|
||||
$this->assertEquals($gray->getColorAt(50, 50), $gray->getTransparentColor());
|
||||
}
|
||||
|
||||
public function testTransparentLogoGIF()
|
||||
{
|
||||
$img = $this->load('logo.gif');
|
||||
$this->assertTransparentColorAt($img, 1, 1);
|
||||
|
||||
$res = $img->asGrayscale();
|
||||
$this->assertDimensions($res, 150, 23);
|
||||
$this->assertInstanceOf('WideImage_PaletteImage', $res);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorAt($res, 1, 1);
|
||||
}
|
||||
|
||||
public function testPNGAlpha()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'100x100-blue-alpha.png');
|
||||
|
||||
$gray = $img->asGrayscale();
|
||||
$this->assertTrue($gray instanceof WideImage_TrueColorImage);
|
||||
$this->assertEquals(100, $gray->getWidth());
|
||||
$this->assertEquals(100, $gray->getHeight());
|
||||
|
||||
$this->assertRGBNear($gray->getRGBAt(25, 25), 29, 29, 29, 32);
|
||||
$this->assertRGBNear($gray->getRGBAt(75, 25), 29, 29, 29, 64);
|
||||
$this->assertRGBNear($gray->getRGBAt(75, 75), 29, 29, 29, 96);
|
||||
$this->assertRGBNear($gray->getRGBAt(25, 75), 0, 0, 0, 127);
|
||||
|
||||
$this->assertFalse($gray->isTransparent());
|
||||
}
|
||||
}
|
||||
|
@@ -1,81 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_AsNegativeTest extends WideImage_TestCase
|
||||
{
|
||||
function skip()
|
||||
{
|
||||
$this->skipUnless(function_exists('imagefilter'));
|
||||
}
|
||||
|
||||
function testTransparentGIF()
|
||||
{
|
||||
$img = $this->load('100x100-color-hole.gif');
|
||||
|
||||
$res = $img->asNegative();
|
||||
|
||||
$this->assertDimensions($res, 100, 100);
|
||||
$this->assertInstanceOf("WideImage_PaletteImage", $res);
|
||||
|
||||
$this->assertRGBNear($res->getRGBAt(10, 10), 0, 0, 255);
|
||||
$this->assertRGBNear($res->getRGBAt(90, 10), 255, 255, 0);
|
||||
$this->assertRGBNear($res->getRGBAt(90, 90), 255, 0, 255);
|
||||
$this->assertRGBNear($res->getRGBAt(10, 90), 0, 255, 255);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorAt($res, 50, 50);
|
||||
}
|
||||
|
||||
function testTransparentLogoGIF()
|
||||
{
|
||||
$img = $this->load('logo.gif');
|
||||
$this->assertTransparentColorAt($img, 1, 1);
|
||||
|
||||
$res = $img->asNegative();
|
||||
$this->assertDimensions($res, 150, 23);
|
||||
$this->assertInstanceOf("WideImage_PaletteImage", $res);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorAt($res, 1, 1);
|
||||
}
|
||||
|
||||
function testPNGAlpha()
|
||||
{
|
||||
$img = $this->load('100x100-blue-alpha.png');
|
||||
|
||||
$res = $img->asNegative();
|
||||
|
||||
$this->assertDimensions($res, 100, 100);
|
||||
$this->assertInstanceOf("WideImage_TrueColorImage", $res);
|
||||
|
||||
$this->assertRGBNear($res->getRGBAt(25, 25), 255, 255, 0, 32);
|
||||
$this->assertRGBNear($res->getRGBAt(75, 25), 255, 255, 0, 64);
|
||||
$this->assertRGBNear($res->getRGBAt(75, 75), 255, 255, 0, 96);
|
||||
$this->assertRGBNear($res->getRGBAt(25, 75), 255, 255, 255, 127);
|
||||
|
||||
$this->assertFalse($res->isTransparent());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_Operation_AsNegativeTest extends WideImage_TestCase
|
||||
{
|
||||
public function skip()
|
||||
{
|
||||
$this->skipUnless(function_exists('imagefilter'));
|
||||
}
|
||||
|
||||
public function testTransparentGIF()
|
||||
{
|
||||
$img = $this->load('100x100-color-hole.gif');
|
||||
|
||||
$res = $img->asNegative();
|
||||
|
||||
$this->assertDimensions($res, 100, 100);
|
||||
$this->assertInstanceOf('WideImage_PaletteImage', $res);
|
||||
|
||||
$this->assertRGBNear($res->getRGBAt(10, 10), 0, 0, 255);
|
||||
$this->assertRGBNear($res->getRGBAt(90, 10), 255, 255, 0);
|
||||
$this->assertRGBNear($res->getRGBAt(90, 90), 255, 0, 255);
|
||||
$this->assertRGBNear($res->getRGBAt(10, 90), 0, 255, 255);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorAt($res, 50, 50);
|
||||
}
|
||||
|
||||
public function testTransparentLogoGIF()
|
||||
{
|
||||
$img = $this->load('logo.gif');
|
||||
$this->assertTransparentColorAt($img, 1, 1);
|
||||
|
||||
$res = $img->asNegative();
|
||||
$this->assertDimensions($res, 150, 23);
|
||||
$this->assertInstanceOf('WideImage_PaletteImage', $res);
|
||||
|
||||
// preserves transparency
|
||||
$this->assertTrue($res->isTransparent());
|
||||
$this->assertTransparentColorAt($res, 1, 1);
|
||||
}
|
||||
|
||||
public function testPNGAlpha()
|
||||
{
|
||||
$img = $this->load('100x100-blue-alpha.png');
|
||||
|
||||
$res = $img->asNegative();
|
||||
|
||||
$this->assertDimensions($res, 100, 100);
|
||||
$this->assertInstanceOf('WideImage_TrueColorImage', $res);
|
||||
|
||||
$this->assertRGBNear($res->getRGBAt(25, 25), 255, 255, 0, 32);
|
||||
$this->assertRGBNear($res->getRGBAt(75, 25), 255, 255, 0, 64);
|
||||
$this->assertRGBNear($res->getRGBAt(75, 75), 255, 255, 0, 96);
|
||||
$this->assertRGBNear($res->getRGBAt(25, 75), 255, 255, 255, 127);
|
||||
|
||||
$this->assertFalse($res->isTransparent());
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Tests
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Tests
|
||||
*/
|
||||
class WideImage_Operation_Autocrop_Test extends WideImage_TestCase
|
||||
{
|
||||
function testAutocrop()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-red-spot.png');
|
||||
|
||||
$cropped = $img->autocrop();
|
||||
$this->assertTrue($cropped instanceof WideImage_TrueColorImage);
|
||||
$this->assertEquals(71, $cropped->getWidth());
|
||||
$this->assertEquals(70, $cropped->getHeight());
|
||||
|
||||
$this->assertRGBNear($cropped->getRGBAt(10, 10), 255, 0, 0);
|
||||
}
|
||||
|
||||
function testAutocropHalfImageBug()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH . '100x100-red-spot-half-cut.png');
|
||||
|
||||
$cropped = $img->autocrop();
|
||||
$this->assertTrue($cropped instanceof WideImage_TrueColorImage);
|
||||
$this->assertEquals(22, $cropped->getWidth());
|
||||
$this->assertEquals(23, $cropped->getHeight());
|
||||
|
||||
$this->assertRGBNear($cropped->getRGBAt(10, 10), 255, 0, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
*/
|
||||
class WideImage_Operation_Autocrop_Test extends WideImage_TestCase
|
||||
{
|
||||
public function testAutocrop()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'100x100-red-spot.png');
|
||||
|
||||
$cropped = $img->autocrop();
|
||||
$this->assertTrue($cropped instanceof WideImage_TrueColorImage);
|
||||
$this->assertEquals(71, $cropped->getWidth());
|
||||
$this->assertEquals(70, $cropped->getHeight());
|
||||
|
||||
$this->assertRGBNear($cropped->getRGBAt(10, 10), 255, 0, 0);
|
||||
}
|
||||
|
||||
public function testAutocropHalfImageBug()
|
||||
{
|
||||
$img = WideImage::load(IMG_PATH.'100x100-red-spot-half-cut.png');
|
||||
|
||||
$cropped = $img->autocrop();
|
||||
$this->assertTrue($cropped instanceof WideImage_TrueColorImage);
|
||||
$this->assertEquals(22, $cropped->getWidth());
|
||||
$this->assertEquals(23, $cropped->getHeight());
|
||||
|
||||
$this->assertRGBNear($cropped->getRGBAt(10, 10), 255, 0, 0);
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user