first commit of free version
This commit is contained in:
153
admin/compiler/joomla_3/wideimage/Operation/AddNoise.php
Normal file
153
admin/compiler/joomla_3/wideimage/Operation/AddNoise.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
67
admin/compiler/joomla_3/wideimage/Operation/ApplyFilter.php
Normal file
67
admin/compiler/joomla_3/wideimage/Operation/ApplyFilter.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
105
admin/compiler/joomla_3/wideimage/Operation/ApplyMask.php
Normal file
105
admin/compiler/joomla_3/wideimage/Operation/ApplyMask.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
49
admin/compiler/joomla_3/wideimage/Operation/AsGrayscale.php
Normal file
49
admin/compiler/joomla_3/wideimage/Operation/AsGrayscale.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
63
admin/compiler/joomla_3/wideimage/Operation/AsNegative.php
Normal file
63
admin/compiler/joomla_3/wideimage/Operation/AsNegative.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
162
admin/compiler/joomla_3/wideimage/Operation/AutoCrop.php
Normal file
162
admin/compiler/joomla_3/wideimage/Operation/AutoCrop.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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);
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
48
admin/compiler/joomla_3/wideimage/Operation/CorrectGamma.php
Normal file
48
admin/compiler/joomla_3/wideimage/Operation/CorrectGamma.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
86
admin/compiler/joomla_3/wideimage/Operation/Crop.php
Normal file
86
admin/compiler/joomla_3/wideimage/Operation/Crop.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
54
admin/compiler/joomla_3/wideimage/Operation/Flip.php
Normal file
54
admin/compiler/joomla_3/wideimage/Operation/Flip.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
67
admin/compiler/joomla_3/wideimage/Operation/GetMask.php
Normal file
67
admin/compiler/joomla_3/wideimage/Operation/GetMask.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
78
admin/compiler/joomla_3/wideimage/Operation/Merge.php
Normal file
78
admin/compiler/joomla_3/wideimage/Operation/Merge.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
55
admin/compiler/joomla_3/wideimage/Operation/Mirror.php
Normal file
55
admin/compiler/joomla_3/wideimage/Operation/Mirror.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
157
admin/compiler/joomla_3/wideimage/Operation/Resize.php
Normal file
157
admin/compiler/joomla_3/wideimage/Operation/Resize.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
107
admin/compiler/joomla_3/wideimage/Operation/ResizeCanvas.php
Normal file
107
admin/compiler/joomla_3/wideimage/Operation/ResizeCanvas.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
64
admin/compiler/joomla_3/wideimage/Operation/Rotate.php
Normal file
64
admin/compiler/joomla_3/wideimage/Operation/Rotate.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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));
|
||||
}
|
||||
}
|
114
admin/compiler/joomla_3/wideimage/Operation/RoundCorners.php
Normal file
114
admin/compiler/joomla_3/wideimage/Operation/RoundCorners.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
||||
}
|
135
admin/compiler/joomla_3/wideimage/Operation/Unsharp.php
Normal file
135
admin/compiler/joomla_3/wideimage/Operation/Unsharp.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Gasper Kozak
|
||||
* @copyright 2007-2011
|
||||
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package 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;
|
||||
}
|
||||
}
|
1
admin/compiler/joomla_3/wideimage/Operation/index.html
Normal file
1
admin/compiler/joomla_3/wideimage/Operation/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
Reference in New Issue
Block a user