From 2155abcc7c042513b7fb5cc784bf0295f16f9f34 Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Tue, 4 Feb 2014 23:07:41 -0600 Subject: [PATCH 01/32] Update ImageWorkshopLayer.php add features including: - apply image convolution - apply alpha mask - split channels - get channel - merge channels --- .../Core/ImageWorkshopLayer.php | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 37944fd..87917e8 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1218,6 +1218,222 @@ public function applyFilter($filterType, $arg1 = null, $arg2 = null, $arg3 = nul } } + /** + * Apply a image convolution on the layer + * + * + * @param array $matrix + * @param int $div + * @param int $offset + * @param boolean $recursive + * + * @author by Jondalar K. Lee + * + */ + public function applyimageconvolution($matrix, $div=0, $offset=0,$recursive=false){ + if(is_string($matrix)){ + $matrix = strtolower($matrix); + switch($matrix){ + case "blur": + $matrix = array(array(1,1,1), array(1,.25,1), array(1,1,1)); + $div = 8.25; + $offset = 0; + break; + + case "emboss": + $matrix = array(array(2, 2, 2), array(2, 1, -2), array(-2, -2, -2)); + $div = 0; + $offset = 127; + break; + + case "gaussian blur" : + $matrix = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0)); + $div = 16; + $offset = 0; + break; + + case "sharpen" : + $Matrix = array(array(-1.2, -1.2, -1.2),array(-1.2, .4, -1.2),array(-1.2, -1.2, -1.2)); + $div = array_sum(array_map('array_sum', $Matrix)); + $offset = 0; + break; + + } + + } + if(is_array($matrix)){ + imageconvolution($this->image, $matrix, $div, $offset); + } + + if ($recursive) { + + $layers = $this->layers; + + foreach($layers as $layerId => $layer) { + $this->layers[$layerId]->applyImageConvolution($matrix, $div, $offset); + } + } + + + + } + + /** + * Apply alpha layer mask. + * + * @param layer $mask + * + * @author email goodlittledeveloper@gmail.com + * + */ + + public function applyalphamask($mask){ + + $masktemp = clone $mask; + + $masktemp->resizeInPixel($this->width, $this->height); // make $mask and $layer the same size. + $masktemp->applyFilter(IMG_FILTER_GRAYSCALE); //converts to greyscale if not greyscale; + $masktemp->applyFilter(IMG_FILTER_NEGATE); + + $layerImg= $this->getImage(); + $maskImg = $masktemp->getImage(); + + $imgtemp = imageCreateTrueColor($this->width,$this->height); + + imagealphablending($imgtemp, false); + imagesavealpha($imgtemp, true); + + + for ($h=0; $h<$this->height; $h++){ + for ($w=0; $w<$this->width; $w++){ + $Lrgb = imagecolorat($layerImg, $w, $h); + $Lcolors = imagecolorsforindex($layerImg, $Lrgb); + + $Mrgb = imagecolorat($maskImg, $w, $h); + $Mcolors = imagecolorsforindex($maskImg, $Mrgb); + + $alpha = $Mcolors["red"]/255*127; + //$alpha = (int)( $alpha); + + imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Lcolors["red"],$Lcolors["green"],$Lcolors["blue"],$alpha)); + }} + + + + //imagecopyresampled($imgtemp, $this->image, 0, 0, 0, 0, $this->width, $this->height, -$this->width, $this->height); + $this->image = $imgtemp; + } + + /** + * split Layer in to channels. + * + * @return a group of 4 layers each one a channel. + * + * @author email goodlittledeveloper@gmail.com + * + */ + + public function splitchannels(){ + $ChlR = imageCreateTrueColor($this->width,$this->height); + $ChlG = imageCreateTrueColor($this->width,$this->height); + $ChlB = imageCreateTrueColor($this->width,$this->height); + $ChlA = imageCreateTrueColor($this->width,$this->height); + + for ($h=0; $h<$this->height; $h++){ + for ($w=0; $w<$this->width; $w++){ + $Lrgb = imagecolorat($this->image, $w, $h); + $Lcolors = imagecolorsforindex($this->image, $Lrgb); + + + imagesetpixel($ChlR,$w,$h,imagecolorallocatealpha($ChlR,$Lcolors["red"],0,0,0)); + imagesetpixel($ChlG,$w,$h,imagecolorallocatealpha($ChlG,0,$Lcolors["green"],0,0)); + imagesetpixel($ChlB,$w,$h,imagecolorallocatealpha($ChlB,0,0,$Lcolors["blue"],0)); + imagesetpixel($ChlA,$w,$h,imagecolorallocatealpha($ChlA,127,127,127,$Lcolors["alpha"])); + }} + + $group = ImageWorkshop::initVirginLayer($this->width,$this->height); + $r = ImageWorkshop::initFromResourceVar($ChlR); + $g = ImageWorkshop::initFromResourceVar($ChlG); + $b = ImageWorkshop::initFromResourceVar($ChlB); + $a = ImageWorkshop::initFromResourceVar($ChlA); + + $sublayerInfos = $group->addLayer("1", $r, 0, 0, "LT"); + $sublayerInfos = $group->addLayer("2", $g, 0, 0, "LT"); + $sublayerInfos = $group->addLayer("3", $b, 0, 0, "LT"); + $sublayerInfos = $group->addLayer("4", $a, 0, 0, "LT"); + + return $group; + } + + /** + * get channel by color. + * + * @param string of channel name + * + * @return a layer based on channel name a channel. + * + * @author email goodlittledeveloper@gmail.com + * + */ + + public function getchannel($channel){ + switch (variable) { + case 'red': + return $this->getLayer(1); + break; + + case 'green': + return $this->getLayer(2); + break; + + case 'blue': + return $this->getLayer(3); + break; + + case 'alpha': + return $this->getLayer(4); + break; + + } + } + + /** + * get channel by color. + * + * @param group of channels + * + * @return sets layer image to merge channels. + * + * @author email goodlittledeveloper@gmail.com + * + */ + + public function mergechannels($group){ + $ChlR = $group->getLayer(1)->getResult(); + $ChlG = $group->getLayer(2)->getResult(); + $ChlB = $group->getLayer(3)->getResult(); + $ChlA = $group->getLayer(4)->getResult(); + + $imgtemp = imageCreateTrueColor($this->width,$this->height); + + imagealphablending($imgtemp, false); + imagesavealpha($imgtemp, true); + + for ($h=0; $h<$this->height; $h++){ + for ($w=0; $w<$this->width; $w++){ + //$LR = imagecolorsforindex($ChlR,imagecolorat($ChlR, $w, $h)); + $Color["red"] = (imagecolorat($ChlR, $w, $h) >> 16) & 0xFF; + $Color["green"] = (imagecolorat($ChlG, $w, $h) >> 8) & 0xFF; + $Color["blue"] = imagecolorat($ChlB, $w, $h) & 0xFF; + $Color["alpha"] = (imagecolorat($ChlA, $w, $h) & 0x7F000000) >> 24; + + imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Color["red"],$Color["green"],$Color["blue"],$Color["alpha"])); + } + } + + $this->image = $imgtemp; + } + /** * Apply horizontal or vertical flip (Transformation) * From dc818a0d835ce75faf4b554f88c3db17187885fc Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Tue, 4 Feb 2014 23:15:15 -0600 Subject: [PATCH 02/32] Update ImageWorkshopLayer.php --- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 87917e8..d38032c 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1377,7 +1377,7 @@ public function splitchannels(){ */ public function getchannel($channel){ - switch (variable) { + switch ($channel) { case 'red': return $this->getLayer(1); break; From 422fbbfd3337e16390702da8d08530cd193a9ee8 Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Tue, 4 Feb 2014 23:50:46 -0600 Subject: [PATCH 03/32] Update ImageWorkshopLayer.php --- .../Core/ImageWorkshopLayer.php | 78 +++++++++++++++++-- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index d38032c..101fabf 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -7,9 +7,9 @@ use PHPImageWorkshop\Core\Exception\ImageWorkshopLayerException as ImageWorkshopLayerException; // If no autoloader, uncomment these lines: -//require_once(__DIR__.'/../ImageWorkshop.php'); -//require_once(__DIR__.'/ImageWorkshopLib.php'); -//require_once(__DIR__.'/Exception/ImageWorkshopLayerException.php'); +require_once(__DIR__.'/../ImageWorkshop.php'); +require_once(__DIR__.'/ImageWorkshopLib.php'); +require_once(__DIR__.'/Exception/ImageWorkshopLayerException.php'); /** * ImageWorkshopLayer class @@ -21,6 +21,58 @@ * @license http://en.wikipedia.org/wiki/MIT_License * @copyright Clément Guillemain */ + +class Logger{ + protected $filename; + + public function __construct($filename = "",$ext = "html"){ + if($filename != ""){ + $this->filename = $filename; + } + else{ + $this->filename = realpath(dirname(__FILE__))."\logmask2.".$ext; + }; + } + public function open(){ + $fd = fopen($this->filename, "a"); + // append date/time to message + $str = "\n \n log for ".basename(__FILE__)." \n \n "; + $str .="

Log for ".basename(__FILE__)."

"; + // write string + fwrite($fd, $str . "\n"); + // close file + fclose($fd); + + } + + public function LogToFile($msg){ + $fd = fopen($this->filename, "a"); + // append date/time to message + $str = "
" .$msg."
"; + // write string + fwrite($fd, $str . "\n"); + // close file + fclose($fd); + + } + public function deleteLog(){ + unlink($this->filename); + } + public function close(){ + $fd = fopen($this->filename, "a"); + // append date/time to message + + $str ="\n"; + $str .= ""; + // write string + fwrite($fd, $str . "\n"); + // close file + fclose($fd); + + } +} + + class ImageWorkshopLayer { // =================================================================================== @@ -119,6 +171,11 @@ class ImageWorkshopLayer * @var integer */ const ERROR_NEGATIVE_NUMBER_USED = 5; + + /** + * @var integer + */ + const ERROR_LAYER_GROUP = 6; // =================================================================================== // Methods @@ -1217,8 +1274,8 @@ public function applyFilter($filterType, $arg1 = null, $arg2 = null, $arg3 = nul } } } - - /** + + /** * Apply a image convolution on the layer * * @@ -1334,6 +1391,11 @@ public function applyalphamask($mask){ */ public function splitchannels(){ + if($this->getLastLayerId()!=0){ + throw new ImageWorkshopException('Can\'t split channels of a layer group', static::ERROR_LAYER_GROUP); + } + else{ + $ChlR = imageCreateTrueColor($this->width,$this->height); $ChlG = imageCreateTrueColor($this->width,$this->height); $ChlB = imageCreateTrueColor($this->width,$this->height); @@ -1363,7 +1425,7 @@ public function splitchannels(){ $sublayerInfos = $group->addLayer("4", $a, 0, 0, "LT"); return $group; - } + }} /** * get channel by color. @@ -1375,7 +1437,7 @@ public function splitchannels(){ * @author email goodlittledeveloper@gmail.com * */ - + public function getchannel($channel){ switch ($channel) { case 'red': @@ -1433,7 +1495,7 @@ public function mergechannels($group){ $this->image = $imgtemp; } - + /** * Apply horizontal or vertical flip (Transformation) * From d5bb6e98009f9c3e76c0f28e744cafba00a57fbf Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Wed, 5 Feb 2014 00:00:57 -0600 Subject: [PATCH 04/32] Update ImageWorkshopLayer.php --- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 101fabf..2dc73fc 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1350,7 +1350,7 @@ public function applyalphamask($mask){ $masktemp->resizeInPixel($this->width, $this->height); // make $mask and $layer the same size. $masktemp->applyFilter(IMG_FILTER_GRAYSCALE); //converts to greyscale if not greyscale; - $masktemp->applyFilter(IMG_FILTER_NEGATE); + $masktemp->applyFilter(IMG_FILTER_NEGATE); // inverts the mask so black = 100% transparent and white = 0 $layerImg= $this->getImage(); $maskImg = $masktemp->getImage(); @@ -1366,10 +1366,9 @@ public function applyalphamask($mask){ $Lrgb = imagecolorat($layerImg, $w, $h); $Lcolors = imagecolorsforindex($layerImg, $Lrgb); - $Mrgb = imagecolorat($maskImg, $w, $h); - $Mcolors = imagecolorsforindex($maskImg, $Mrgb); - $alpha = $Mcolors["red"]/255*127; + $alpha = (imagecolorat($maskImg, $w, $h) >> 16) & 0xFF; //faster calc to get red + $alpha = $alpha/255*127; // the gets alpha from red value //$alpha = (int)( $alpha); imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Lcolors["red"],$Lcolors["green"],$Lcolors["blue"],$alpha)); From 82e405c195d4ff94c957af308ca2d8d015c37730 Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Wed, 5 Feb 2014 00:01:58 -0600 Subject: [PATCH 05/32] Update ImageWorkshopLayer.php --- .../Core/ImageWorkshopLayer.php | 49 ------------------- 1 file changed, 49 deletions(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 2dc73fc..5db9752 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -22,55 +22,6 @@ * @copyright Clément Guillemain */ -class Logger{ - protected $filename; - - public function __construct($filename = "",$ext = "html"){ - if($filename != ""){ - $this->filename = $filename; - } - else{ - $this->filename = realpath(dirname(__FILE__))."\logmask2.".$ext; - }; - } - public function open(){ - $fd = fopen($this->filename, "a"); - // append date/time to message - $str = "\n \n log for ".basename(__FILE__)." \n \n "; - $str .="

Log for ".basename(__FILE__)."

"; - // write string - fwrite($fd, $str . "\n"); - // close file - fclose($fd); - - } - - public function LogToFile($msg){ - $fd = fopen($this->filename, "a"); - // append date/time to message - $str = "
" .$msg."
"; - // write string - fwrite($fd, $str . "\n"); - // close file - fclose($fd); - - } - public function deleteLog(){ - unlink($this->filename); - } - public function close(){ - $fd = fopen($this->filename, "a"); - // append date/time to message - - $str ="\n"; - $str .= ""; - // write string - fwrite($fd, $str . "\n"); - // close file - fclose($fd); - - } -} class ImageWorkshopLayer From e137ecb3e148430ea042ed78ae7580e2a224f83a Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Wed, 5 Feb 2014 00:03:25 -0600 Subject: [PATCH 06/32] Update ImageWorkshopLayer.php --- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 5db9752..fa4b574 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1235,7 +1235,7 @@ public function applyFilter($filterType, $arg1 = null, $arg2 = null, $arg3 = nul * @param int $offset * @param boolean $recursive * - * @author by Jondalar K. Lee + * @author Email Goodlittledeveloper@gmail.com * */ public function applyimageconvolution($matrix, $div=0, $offset=0,$recursive=false){ From edf35ab95582f30860fbdacacba1b8b813c585b2 Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Wed, 5 Feb 2014 00:53:50 -0600 Subject: [PATCH 07/32] Update ImageWorkshopLayer.php --- .../Core/ImageWorkshopLayer.php | 87 +++++++++++++++++-- 1 file changed, 82 insertions(+), 5 deletions(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index fa4b574..73d77cd 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1284,6 +1284,70 @@ public function applyimageconvolution($matrix, $div=0, $offset=0,$recursive=fals + } + + public function toGreyscale($type = null,$recursive=false){ + $type = strtolower($type); + + switch ($type) { + case 'lightness': + for ($h=0; $h<$this->height; $h++){ + for ($w=0; $w<$this->width; $w++){ + $rgb = imagecolorat($this->image, $w, $h); + $r = ($rgb >> 16) & 0xFF; + $g = ($rgb >> 8) & 0xFF; + $b = $rgb & 0xFF; + $a = ($rgb & 0x7F000000) >> 24; + + $grey = (max($r,$g,$b)+min($r,$g,$b))/2; + + imagesetpixel($this->image,$w,$h,imagecolorallocatealpha($this->image,$grey,$grey,$grey,$a)); + } + } + + break; + + case 'luminosity': + for ($h=0; $h<$this->height; $h++){ + for ($w=0; $w<$this->width; $w++){ + $rgb = imagecolorat($this->image, $w, $h); + $r = ($rgb >> 16) & 0xFF; + $g = ($rgb >> 8) & 0xFF; + $b = $rgb & 0xFF; + $a = ($rgb & 0x7F000000) >> 24; + + $grey = 0.21*$r+0.71*$g+0.07*$b; + + imagesetpixel($this->image,$w,$h,imagecolorallocatealpha($this->image,$grey,$grey,$grey,$a)); + } + } + break; + + default://average + for ($h=0; $h<$this->height; $h++){ + for ($w=0; $w<$this->width; $w++){ + $rgb = imagecolorat($this->image, $w, $h); + $r = ($rgb >> 16) & 0xFF; + $g = ($rgb >> 8) & 0xFF; + $b = $rgb & 0xFF; + $a = ($rgb & 0x7F000000) >> 24; + + $grey = ($r+$g+$b)/3; + + imagesetpixel($this->image,$w,$h,imagecolorallocatealpha($this->image,$grey,$grey,$grey,$a)); + } + } + break; + } + + if ($recursive) { + + $layers = $this->layers; + + foreach($layers as $layerId => $layer) { + $this->layers[$layerId]->applyImageConvolution($matrix, $div, $offset); + } + } } /** @@ -1318,17 +1382,19 @@ public function applyalphamask($mask){ $Lcolors = imagecolorsforindex($layerImg, $Lrgb); - $alpha = (imagecolorat($maskImg, $w, $h) >> 16) & 0xFF; //faster calc to get red - $alpha = $alpha/255*127; // the gets alpha from red value - //$alpha = (int)( $alpha); + $alpha = (imagecolorat($maskImg, $w, $h) >> 16) & 0xFF; //faster calc to get red value. + $alpha = $alpha/255*127; // the gets alpha from red value imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Lcolors["red"],$Lcolors["green"],$Lcolors["blue"],$alpha)); }} - //imagecopyresampled($imgtemp, $this->image, 0, 0, 0, 0, $this->width, $this->height, -$this->width, $this->height); + //imagecopyresampled($imgtemp, $this->image, 0, 0, 0, 0, $this->width, $this->height, -$this->width, $this->height); + unset($this->image); $this->image = $imgtemp; + unset($imgtemp); + } /** @@ -1369,6 +1435,12 @@ public function splitchannels(){ $b = ImageWorkshop::initFromResourceVar($ChlB); $a = ImageWorkshop::initFromResourceVar($ChlA); + unset($ChlR); + unset($ChlG); + unset($ChlB); + unset($ChlA); + + $sublayerInfos = $group->addLayer("1", $r, 0, 0, "LT"); $sublayerInfos = $group->addLayer("2", $g, 0, 0, "LT"); $sublayerInfos = $group->addLayer("3", $b, 0, 0, "LT"); @@ -1443,9 +1515,14 @@ public function mergechannels($group){ } } - $this->image = $imgtemp; + unset($this->image); + $this->image = $imgtemp; + unset($imgtemp); } + + + /** * Apply horizontal or vertical flip (Transformation) * From 3e433108bceb3fd2f6f3665367f3f2643c6aed8e Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Wed, 5 Feb 2014 00:55:59 -0600 Subject: [PATCH 08/32] Update ImageWorkshopLayer.php --- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 73d77cd..ba2cfab 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1278,7 +1278,7 @@ public function applyimageconvolution($matrix, $div=0, $offset=0,$recursive=fals $layers = $this->layers; foreach($layers as $layerId => $layer) { - $this->layers[$layerId]->applyImageConvolution($matrix, $div, $offset); + $this->layers[$layerId]->applyImageConvolution($matrix, $div, $offset, true); } } @@ -1345,7 +1345,7 @@ public function toGreyscale($type = null,$recursive=false){ $layers = $this->layers; foreach($layers as $layerId => $layer) { - $this->layers[$layerId]->applyImageConvolution($matrix, $div, $offset); + $this->layers[$layerId]->toGreyscale($type, true); } } } From aafd614228f7726460e18d2e038d8a442ea486bd Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Wed, 5 Feb 2014 00:57:10 -0600 Subject: [PATCH 09/32] Update ImageWorkshopLayer.php --- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index ba2cfab..d674ba2 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1390,7 +1390,7 @@ public function applyalphamask($mask){ - //imagecopyresampled($imgtemp, $this->image, 0, 0, 0, 0, $this->width, $this->height, -$this->width, $this->height); + unset($this->image); $this->image = $imgtemp; unset($imgtemp); @@ -1505,7 +1505,7 @@ public function mergechannels($group){ for ($h=0; $h<$this->height; $h++){ for ($w=0; $w<$this->width; $w++){ - //$LR = imagecolorsforindex($ChlR,imagecolorat($ChlR, $w, $h)); + $Color["red"] = (imagecolorat($ChlR, $w, $h) >> 16) & 0xFF; $Color["green"] = (imagecolorat($ChlG, $w, $h) >> 8) & 0xFF; $Color["blue"] = imagecolorat($ChlB, $w, $h) & 0xFF; From 455361ed5b5b9d664e65ae4c314f7498b550a749 Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Wed, 5 Feb 2014 00:58:21 -0600 Subject: [PATCH 10/32] Update ImageWorkshopLayer.php --- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index d674ba2..4cd82a3 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1514,6 +1514,11 @@ public function mergechannels($group){ imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Color["red"],$Color["green"],$Color["blue"],$Color["alpha"])); } } + + unset($ChlR); + unset($ChlG); + unset($ChlB); + unset($ChlA); unset($this->image); $this->image = $imgtemp; From b30065da360c66a55452dbd84fa58e76ca33e3d9 Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Wed, 5 Feb 2014 01:00:06 -0600 Subject: [PATCH 11/32] Update ImageWorkshopLayer.php --- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 4cd82a3..ca03614 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1482,7 +1482,7 @@ public function getchannel($channel){ } /** - * get channel by color. + * merge channels. * * @param group of channels * @@ -1514,7 +1514,7 @@ public function mergechannels($group){ imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Color["red"],$Color["green"],$Color["blue"],$Color["alpha"])); } } - + unset($ChlR); unset($ChlG); unset($ChlB); From 551f57b8a33f1d2d2a3569c0e4791a853f8eeeab Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Wed, 5 Mar 2014 23:43:42 -0600 Subject: [PATCH 12/32] move Effects Into own libary injecting layers into effects --- .../Exception/ImageWorkshopLayerException.php | 2 +- .../Exception/ImageWorkshopLibException.php | 2 +- src/PHPImageWorkshop/Core/GLDEffectsLib.php | 354 ++++++++++++++++++ .../Core/ImageWorkshopLayer.php | 40 ++ .../Core/ImageWorkshopLib.php | 2 +- .../Exception/ImageWorkshopException.php | 2 +- src/PHPImageWorkshop/ImageWorkshop.php | 39 +- 7 files changed, 435 insertions(+), 6 deletions(-) create mode 100644 src/PHPImageWorkshop/Core/GLDEffectsLib.php diff --git a/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLayerException.php b/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLayerException.php index 6628b4d..34c1562 100644 --- a/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLayerException.php +++ b/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLayerException.php @@ -5,7 +5,7 @@ use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException; // If no autoloader, uncomment these lines: -//require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php'); +require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php'); /** * ImageWorkshopLayerException diff --git a/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLibException.php b/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLibException.php index 18338f9..aecbed6 100644 --- a/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLibException.php +++ b/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLibException.php @@ -5,7 +5,7 @@ use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException; // If no autoloader, uncomment these lines: -//require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php'); +require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php'); /** * ImageWorkshopLibException diff --git a/src/PHPImageWorkshop/Core/GLDEffectsLib.php b/src/PHPImageWorkshop/Core/GLDEffectsLib.php new file mode 100644 index 0000000..20dd6b0 --- /dev/null +++ b/src/PHPImageWorkshop/Core/GLDEffectsLib.php @@ -0,0 +1,354 @@ +getResult(), $matrix, $div, $offset); + return ImageWorkshop::initFromResourceVar($img); + } + + + + + + } + + public function toGreyscale($layer,$type = null){ + $type = strtolower($type); + $image = $layer->getResult(); + $width = $layer->getWidth; + $height = $layer->getHeight; + + switch ($type) { + case 'lightness': + for ($h=0; $h<$height; $h++){ + for ($w=0; $w<$width; $w++){ + $rgb = imagecolorat($image, $w, $h); + $r = ($rgb >> 16) & 0xFF; + $g = ($rgb >> 8) & 0xFF; + $b = $rgb & 0xFF; + $a = ($rgb & 0x7F000000) >> 24; + + $grey = (max($r,$g,$b)+min($r,$g,$b))/2; + + imagesetpixel($image,$w,$h,imagecolorallocatealpha($image,$grey,$grey,$grey,$a)); + } + } + + break; + + case 'luminosity': + for ($h=0; $h<$height; $h++){ + for ($w=0; $w<$width; $w++){ + $rgb = imagecolorat($image, $w, $h); + $r = ($rgb >> 16) & 0xFF; + $g = ($rgb >> 8) & 0xFF; + $b = $rgb & 0xFF; + $a = ($rgb & 0x7F000000) >> 24; + + $grey = 0.21*$r+0.71*$g+0.07*$b; + + imagesetpixel($image,$w,$h,imagecolorallocatealpha($image,$grey,$grey,$grey,$a)); + } + } + break; + + default://average + for ($h=0; $h<$height; $h++){ + for ($w=0; $w<$width; $w++){ + $rgb = imagecolorat($image, $w, $h); + $r = ($rgb >> 16) & 0xFF; + $g = ($rgb >> 8) & 0xFF; + $b = $rgb & 0xFF; + $a = ($rgb & 0x7F000000) >> 24; + + $grey = ($r+$g+$b)/3; + + imagesetpixel($image,$w,$h,imagecolorallocatealpha($image,$grey,$grey,$grey,$a)); + } + } + break; + } + + } + + /** + * Apply alpha layer mask. + * + * @param layer $mask + * + * @author email goodlittledeveloper@gmail.com + * + */ + + public function applyalphamask($layer, $mask){ + + $masktemp = clone $mask; + + $masktemp->resizeInPixel($layer->width, $layer->height); // make $mask and $layer the same size. + $masktemp->applyFilter(IMG_FILTER_GRAYSCALE); //converts to greyscale if not greyscale; + $masktemp->applyFilter(IMG_FILTER_NEGATE); // inverts the mask so black = 100% transparent and white = 0 + + $layerImg= $layer->getImage(); + $maskImg = $masktemp->getImage(); + + $imgtemp = imageCreateTrueColor($layer->width,$layer->height); + + imagealphablending($imgtemp, false); + imagesavealpha($imgtemp, true); + + + for ($h=0; $h<$this->height; $h++){ + for ($w=0; $w<$this->width; $w++){ + $Lrgb = imagecolorat($layerImg, $w, $h); + $Lcolors = imagecolorsforindex($layerImg, $Lrgb); + + + $alpha = (imagecolorat($maskImg, $w, $h) >> 16) & 0xFF; //faster calc to get red value. + $alpha = $alpha/255*127; // the gets alpha from red value + + imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Lcolors["red"],$Lcolors["green"],$Lcolors["blue"],$alpha)); + }} + + + + + unset($this->image); + return $imgtemp; + unset($imgtemp); + + } + + /** + * split Layer in to channels. + * + * @return a group of 4 layers each one a channel. + * + * @author email goodlittledeveloper@gmail.com + * + */ + + public function splitchannels($layer){ + if($layer->getLastLayerId()!=0){ + throw new ImageWorkshopException('Can\'t split channels of a layer group', static::ERROR_LAYER_GROUP); + } + else{ + + $ChlR = imageCreateTrueColor($layer->width,$layer->height); + $ChlG = imageCreateTrueColor($layer->width,$layer->height); + $ChlB = imageCreateTrueColor($layer->width,$layer->height); + $ChlA = imageCreateTrueColor($layer->width,$layer->height); + + $group = ImageWorkshop::initVirginLayer($layer->width,$layer->height); + $image = $layer->getImage(); + + for ($h=0; $h<$layer->height; $h++){ + for ($w=0; $w<$layer->width; $w++){ + $Lrgb = imagecolorat($image, $w, $h); + $Lcolors = imagecolorsforindex($image, $Lrgb); + + + imagesetpixel($ChlR,$w,$h,imagecolorallocatealpha($ChlR,$Lcolors["red"],0,0,0)); + imagesetpixel($ChlG,$w,$h,imagecolorallocatealpha($ChlG,0,$Lcolors["green"],0,0)); + imagesetpixel($ChlB,$w,$h,imagecolorallocatealpha($ChlB,0,0,$Lcolors["blue"],0)); + imagesetpixel($ChlA,$w,$h,imagecolorallocatealpha($ChlA,127,127,127,$Lcolors["alpha"])); + }} + + + $r = ImageWorkshop::initFromResourceVar($ChlR); + $g = ImageWorkshop::initFromResourceVar($ChlG); + $b = ImageWorkshop::initFromResourceVar($ChlB); + $a = ImageWorkshop::initFromResourceVar($ChlA); + + unset($ChlR); + unset($ChlG); + unset($ChlB); + unset($ChlA); + + + $sublayerInfos = $group->addLayer("1", $r, 0, 0, "LT"); + $sublayerInfos = $group->addLayer("2", $g, 0, 0, "LT"); + $sublayerInfos = $group->addLayer("3", $b, 0, 0, "LT"); + $sublayerInfos = $group->addLayer("4", $a, 0, 0, "LT"); + + return $group; + }} + + /** + * get channel by color. + * + * @param string of channel name + * + * @return a layer based on channel name a channel. + * + * @author email goodlittledeveloper@gmail.com + * + */ + + public function getchannel($layer,$channel){ + switch ($channel) { + case 'red': + return $layer->getLayer(1); + break; + + case 'green': + return $layer->getLayer(2); + break; + + case 'blue': + return $layer->getLayer(3); + break; + + case 'alpha': + return $layer->getLayer(4); + break; + + } + } + + /** + * merge channels. + * + * @param group of channels + * + * @return sets layer image to merge channels. + * + * @author email goodlittledeveloper@gmail.com + * + */ + + public function mergechannels($group){ + $ChlR = $group->getLayer(1)->getResult(); + $ChlG = $group->getLayer(2)->getResult(); + $ChlB = $group->getLayer(3)->getResult(); + $ChlA = $group->getLayer(4)->getResult(); + + $imgtemp = imageCreateTrueColor($group->width,$group->height); + + imagealphablending($imgtemp, false); + imagesavealpha($imgtemp, true); + + for ($h=0; $h<$this->height; $h++){ + for ($w=0; $w<$this->width; $w++){ + + $Color["red"] = (imagecolorat($ChlR, $w, $h) >> 16) & 0xFF; + $Color["green"] = (imagecolorat($ChlG, $w, $h) >> 8) & 0xFF; + $Color["blue"] = imagecolorat($ChlB, $w, $h) & 0xFF; + $Color["alpha"] = (imagecolorat($ChlA, $w, $h) & 0x7F000000) >> 24; + + imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Color["red"],$Color["green"],$Color["blue"],$Color["alpha"])); + } + } + + unset($ChlR); + unset($ChlG); + unset($ChlB); + unset($ChlA); + unset($group); + + return $imgtemp; + unset($imgtemp); + } +} + +?> \ No newline at end of file diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index ca03614..52dbca9 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1193,6 +1193,46 @@ public function opacity($opacity, $recursive = true) unset($transparentImage); } + /** + * Apply extended filters + * + * @param author Email: Goodlittledeveloper@gmail.com + * @param Effect is the name of the effect you wish to apply, + * @param EffectsLib is an object with the method that applys the effect, + * @param it pass anyother varable you send to the method. + */ + + public function Extended_Effects(string $Effect, object $EffectsLib , $recursive = false){ + $args = func_get_args();//get all function arguments + unset($args[0]);// removes $Effect From the array + unset($args[1]);// removes $Effect Lib from the array + unset($args[2]);// removes $recursive from the array + + + + if ($recursive) {// if it is recursive then applys each effect to each layer + + $group = clone $this; + $layers = $group->layers; + + foreach($layers as $layerId => $layer) { + array_unshift($args, $this->layers[$layerId]->Image);// adds current image to the arguments array + $args = array_values($args);// reorginizes the array + $this->layers[$layerId] = call_user_func_array(array($EffectsLib, $Effect), $args);// apply effect and returns an image. + unset($args[0]);// removes the current image from the array allowing the next image to be added. + } + return $group; + } + + else// if not recursive then applays effect to current layer. + { + array_unshift($args, $this->image); // adds current image + $args = array_values($args);// reorders arguments. + $layer = call_user_func_array(array($EffectsLib, $Effect), $args);// applys effect and return image. + return $layer;// doing this allow you to apply an effect on an image and store it in a new or old value. + } + } + /** * Apply a filter on the layer * Be careful: some filters can damage transparent images, use it sparingly ! (A good pratice is to use mergeAll on your layer before applying a filter) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLib.php b/src/PHPImageWorkshop/Core/ImageWorkshopLib.php index 7f619cc..c650218 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLib.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLib.php @@ -5,7 +5,7 @@ use PHPImageWorkshop\Core\Exception\ImageWorkshopLibException as ImageWorkshopLibException; // If no autoloader, uncomment these lines: -//require_once(__DIR__.'/Exception/ImageWorkshopLibException.php'); +require_once(__DIR__.'/Exception/ImageWorkshopLibException.php'); /** * ImageWorkshopLib class diff --git a/src/PHPImageWorkshop/Exception/ImageWorkshopException.php b/src/PHPImageWorkshop/Exception/ImageWorkshopException.php index d7347d9..7663c93 100644 --- a/src/PHPImageWorkshop/Exception/ImageWorkshopException.php +++ b/src/PHPImageWorkshop/Exception/ImageWorkshopException.php @@ -5,7 +5,7 @@ use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException; // If no autoloader, uncomment these lines: -//require_once(__DIR__.'/ImageWorkshopBaseException.php'); +require_once(__DIR__.'/ImageWorkshopBaseException.php'); /** * ImageWorkshopException diff --git a/src/PHPImageWorkshop/ImageWorkshop.php b/src/PHPImageWorkshop/ImageWorkshop.php index d13e4c4..e963054 100644 --- a/src/PHPImageWorkshop/ImageWorkshop.php +++ b/src/PHPImageWorkshop/ImageWorkshop.php @@ -7,8 +7,8 @@ use PHPImageWorkshop\Exception\ImageWorkshopException as ImageWorkshopException; // If no autoloader, uncomment these lines: -//require_once(__DIR__.'/Core/ImageWorkshopLayer.php'); -//require_once(__DIR__.'/Exception/ImageWorkshopException.php'); +require_once(__DIR__.'/Core/ImageWorkshopLayer.php'); +require_once(__DIR__.'/Exception/ImageWorkshopException.php'); /** * ImageWorkshop class @@ -135,6 +135,41 @@ public static function initVirginLayer($width = 100, $height = 100, $backgroundC return new ImageWorkshopLayer(ImageWorkshopLib::generateImage($width, $height, $backgroundColor, $opacity)); } + + /** + * Initialize a layer from a given image url + * + * + * @param string $url + * + * @return ImageWorkshopLayer + */ + + public static function initFromUrl($url) { + + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); + + + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); + + $data = curl_exec($ch); + + curl_close($ch); + + + return $image = self::initFromString($data); + + } /** * Initialize a layer from a resource image var From 88f8a0405c63c47706effb172ff39fb57a79443a Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Wed, 5 Mar 2014 23:52:47 -0600 Subject: [PATCH 13/32] adjusted the readme --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 2f97eee..6333f3e 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,19 @@ ### Summary and features Really flexible and easy-to-use PHP class to work with images using the GD Library +Included Libary for Layer Effects. +to include effect libary please add: + +require_once(_Path_to_.'/PHPImageWorkshop/core/GLDEffectsLib.php'); + +to your require_once request; http://phpimageworkshop.com/ ### Latest updates +**version 2.0.6 - 2014-3-6** +Move Layer effect into there own class, allowing you to. +added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. **Version 2.0.5 - 2013-11-12** From 033fe7eda03ebd2acc252cc738ab76f2ee2eb02b Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Wed, 5 Mar 2014 23:54:41 -0600 Subject: [PATCH 14/32] adjusted the readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6333f3e..ae09d31 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ ### Summary and features Really flexible and easy-to-use PHP class to work with images using the GD Library + Included Libary for Layer Effects. to include effect libary please add: @@ -16,9 +17,10 @@ to your require_once request; http://phpimageworkshop.com/ ### Latest updates -**version 2.0.6 - 2014-3-6** -Move Layer effect into there own class, allowing you to. -added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. +**Version 2.0.6 - 2014-3-6** + +-Move Layer effect into there own class, allowing you to. +-added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. **Version 2.0.5 - 2013-11-12** From 487e83200aea046a0f2bca5e59d200d1b93da6d0 Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Wed, 5 Mar 2014 23:56:24 -0600 Subject: [PATCH 15/32] adjusted the readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ae09d31..45f6013 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ Really flexible and easy-to-use PHP class to work with images using the GD Libra Included Libary for Layer Effects. to include effect libary please add: -require_once(_Path_to_.'/PHPImageWorkshop/core/GLDEffectsLib.php'); +```php +require_once(the_Path_to_.'/PHPImageWorkshop/core/GLDEffectsLib.php'); +``` to your require_once request; @@ -20,6 +22,7 @@ http://phpimageworkshop.com/ **Version 2.0.6 - 2014-3-6** -Move Layer effect into there own class, allowing you to. + -added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. **Version 2.0.5 - 2013-11-12** From 42fb80455e7071b5fddaef92077a35b8c538d608 Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Wed, 5 Mar 2014 23:57:10 -0600 Subject: [PATCH 16/32] adjusted the readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45f6013..44f33f6 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ http://phpimageworkshop.com/ -Move Layer effect into there own class, allowing you to. --added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. +-Added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. **Version 2.0.5 - 2013-11-12** From 84fb9b0d01eeafb30e0fdcbb38652a8912c57051 Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Wed, 5 Mar 2014 23:57:52 -0600 Subject: [PATCH 17/32] adjusted the readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 44f33f6..31118be 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ http://phpimageworkshop.com/ ### Latest updates **Version 2.0.6 - 2014-3-6** --Move Layer effect into there own class, allowing you to. +- Move Layer effect into there own class, allowing you to. --Added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. +- Added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. **Version 2.0.5 - 2013-11-12** From ce3b05dd03d8b4fd46f2b7e4704e09442bf6e336 Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Wed, 5 Mar 2014 23:59:09 -0600 Subject: [PATCH 18/32] adjusted the readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31118be..137247a 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ http://phpimageworkshop.com/ ### Latest updates **Version 2.0.6 - 2014-3-6** -- Move Layer effect into there own class, allowing you to. +- Move Layer effect into there own class, allowing you to use your own effects libaries. - Added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. From 601a55e9d612c70f91a8e93452d25cd8efa6dad8 Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Tue, 6 May 2014 16:49:42 -0600 Subject: [PATCH 19/32] remove extracted Effects (working on solution) --- src/PHPImageWorkshop/Core/GLDEffectsLib.php | 354 ------------------ .../Core/ImageWorkshopLayer.php | 40 -- 2 files changed, 394 deletions(-) delete mode 100644 src/PHPImageWorkshop/Core/GLDEffectsLib.php diff --git a/src/PHPImageWorkshop/Core/GLDEffectsLib.php b/src/PHPImageWorkshop/Core/GLDEffectsLib.php deleted file mode 100644 index 20dd6b0..0000000 --- a/src/PHPImageWorkshop/Core/GLDEffectsLib.php +++ /dev/null @@ -1,354 +0,0 @@ -getResult(), $matrix, $div, $offset); - return ImageWorkshop::initFromResourceVar($img); - } - - - - - - } - - public function toGreyscale($layer,$type = null){ - $type = strtolower($type); - $image = $layer->getResult(); - $width = $layer->getWidth; - $height = $layer->getHeight; - - switch ($type) { - case 'lightness': - for ($h=0; $h<$height; $h++){ - for ($w=0; $w<$width; $w++){ - $rgb = imagecolorat($image, $w, $h); - $r = ($rgb >> 16) & 0xFF; - $g = ($rgb >> 8) & 0xFF; - $b = $rgb & 0xFF; - $a = ($rgb & 0x7F000000) >> 24; - - $grey = (max($r,$g,$b)+min($r,$g,$b))/2; - - imagesetpixel($image,$w,$h,imagecolorallocatealpha($image,$grey,$grey,$grey,$a)); - } - } - - break; - - case 'luminosity': - for ($h=0; $h<$height; $h++){ - for ($w=0; $w<$width; $w++){ - $rgb = imagecolorat($image, $w, $h); - $r = ($rgb >> 16) & 0xFF; - $g = ($rgb >> 8) & 0xFF; - $b = $rgb & 0xFF; - $a = ($rgb & 0x7F000000) >> 24; - - $grey = 0.21*$r+0.71*$g+0.07*$b; - - imagesetpixel($image,$w,$h,imagecolorallocatealpha($image,$grey,$grey,$grey,$a)); - } - } - break; - - default://average - for ($h=0; $h<$height; $h++){ - for ($w=0; $w<$width; $w++){ - $rgb = imagecolorat($image, $w, $h); - $r = ($rgb >> 16) & 0xFF; - $g = ($rgb >> 8) & 0xFF; - $b = $rgb & 0xFF; - $a = ($rgb & 0x7F000000) >> 24; - - $grey = ($r+$g+$b)/3; - - imagesetpixel($image,$w,$h,imagecolorallocatealpha($image,$grey,$grey,$grey,$a)); - } - } - break; - } - - } - - /** - * Apply alpha layer mask. - * - * @param layer $mask - * - * @author email goodlittledeveloper@gmail.com - * - */ - - public function applyalphamask($layer, $mask){ - - $masktemp = clone $mask; - - $masktemp->resizeInPixel($layer->width, $layer->height); // make $mask and $layer the same size. - $masktemp->applyFilter(IMG_FILTER_GRAYSCALE); //converts to greyscale if not greyscale; - $masktemp->applyFilter(IMG_FILTER_NEGATE); // inverts the mask so black = 100% transparent and white = 0 - - $layerImg= $layer->getImage(); - $maskImg = $masktemp->getImage(); - - $imgtemp = imageCreateTrueColor($layer->width,$layer->height); - - imagealphablending($imgtemp, false); - imagesavealpha($imgtemp, true); - - - for ($h=0; $h<$this->height; $h++){ - for ($w=0; $w<$this->width; $w++){ - $Lrgb = imagecolorat($layerImg, $w, $h); - $Lcolors = imagecolorsforindex($layerImg, $Lrgb); - - - $alpha = (imagecolorat($maskImg, $w, $h) >> 16) & 0xFF; //faster calc to get red value. - $alpha = $alpha/255*127; // the gets alpha from red value - - imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Lcolors["red"],$Lcolors["green"],$Lcolors["blue"],$alpha)); - }} - - - - - unset($this->image); - return $imgtemp; - unset($imgtemp); - - } - - /** - * split Layer in to channels. - * - * @return a group of 4 layers each one a channel. - * - * @author email goodlittledeveloper@gmail.com - * - */ - - public function splitchannels($layer){ - if($layer->getLastLayerId()!=0){ - throw new ImageWorkshopException('Can\'t split channels of a layer group', static::ERROR_LAYER_GROUP); - } - else{ - - $ChlR = imageCreateTrueColor($layer->width,$layer->height); - $ChlG = imageCreateTrueColor($layer->width,$layer->height); - $ChlB = imageCreateTrueColor($layer->width,$layer->height); - $ChlA = imageCreateTrueColor($layer->width,$layer->height); - - $group = ImageWorkshop::initVirginLayer($layer->width,$layer->height); - $image = $layer->getImage(); - - for ($h=0; $h<$layer->height; $h++){ - for ($w=0; $w<$layer->width; $w++){ - $Lrgb = imagecolorat($image, $w, $h); - $Lcolors = imagecolorsforindex($image, $Lrgb); - - - imagesetpixel($ChlR,$w,$h,imagecolorallocatealpha($ChlR,$Lcolors["red"],0,0,0)); - imagesetpixel($ChlG,$w,$h,imagecolorallocatealpha($ChlG,0,$Lcolors["green"],0,0)); - imagesetpixel($ChlB,$w,$h,imagecolorallocatealpha($ChlB,0,0,$Lcolors["blue"],0)); - imagesetpixel($ChlA,$w,$h,imagecolorallocatealpha($ChlA,127,127,127,$Lcolors["alpha"])); - }} - - - $r = ImageWorkshop::initFromResourceVar($ChlR); - $g = ImageWorkshop::initFromResourceVar($ChlG); - $b = ImageWorkshop::initFromResourceVar($ChlB); - $a = ImageWorkshop::initFromResourceVar($ChlA); - - unset($ChlR); - unset($ChlG); - unset($ChlB); - unset($ChlA); - - - $sublayerInfos = $group->addLayer("1", $r, 0, 0, "LT"); - $sublayerInfos = $group->addLayer("2", $g, 0, 0, "LT"); - $sublayerInfos = $group->addLayer("3", $b, 0, 0, "LT"); - $sublayerInfos = $group->addLayer("4", $a, 0, 0, "LT"); - - return $group; - }} - - /** - * get channel by color. - * - * @param string of channel name - * - * @return a layer based on channel name a channel. - * - * @author email goodlittledeveloper@gmail.com - * - */ - - public function getchannel($layer,$channel){ - switch ($channel) { - case 'red': - return $layer->getLayer(1); - break; - - case 'green': - return $layer->getLayer(2); - break; - - case 'blue': - return $layer->getLayer(3); - break; - - case 'alpha': - return $layer->getLayer(4); - break; - - } - } - - /** - * merge channels. - * - * @param group of channels - * - * @return sets layer image to merge channels. - * - * @author email goodlittledeveloper@gmail.com - * - */ - - public function mergechannels($group){ - $ChlR = $group->getLayer(1)->getResult(); - $ChlG = $group->getLayer(2)->getResult(); - $ChlB = $group->getLayer(3)->getResult(); - $ChlA = $group->getLayer(4)->getResult(); - - $imgtemp = imageCreateTrueColor($group->width,$group->height); - - imagealphablending($imgtemp, false); - imagesavealpha($imgtemp, true); - - for ($h=0; $h<$this->height; $h++){ - for ($w=0; $w<$this->width; $w++){ - - $Color["red"] = (imagecolorat($ChlR, $w, $h) >> 16) & 0xFF; - $Color["green"] = (imagecolorat($ChlG, $w, $h) >> 8) & 0xFF; - $Color["blue"] = imagecolorat($ChlB, $w, $h) & 0xFF; - $Color["alpha"] = (imagecolorat($ChlA, $w, $h) & 0x7F000000) >> 24; - - imagesetpixel($imgtemp,$w,$h,imagecolorallocatealpha($imgtemp,$Color["red"],$Color["green"],$Color["blue"],$Color["alpha"])); - } - } - - unset($ChlR); - unset($ChlG); - unset($ChlB); - unset($ChlA); - unset($group); - - return $imgtemp; - unset($imgtemp); - } -} - -?> \ No newline at end of file diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 52dbca9..ca03614 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1193,46 +1193,6 @@ public function opacity($opacity, $recursive = true) unset($transparentImage); } - /** - * Apply extended filters - * - * @param author Email: Goodlittledeveloper@gmail.com - * @param Effect is the name of the effect you wish to apply, - * @param EffectsLib is an object with the method that applys the effect, - * @param it pass anyother varable you send to the method. - */ - - public function Extended_Effects(string $Effect, object $EffectsLib , $recursive = false){ - $args = func_get_args();//get all function arguments - unset($args[0]);// removes $Effect From the array - unset($args[1]);// removes $Effect Lib from the array - unset($args[2]);// removes $recursive from the array - - - - if ($recursive) {// if it is recursive then applys each effect to each layer - - $group = clone $this; - $layers = $group->layers; - - foreach($layers as $layerId => $layer) { - array_unshift($args, $this->layers[$layerId]->Image);// adds current image to the arguments array - $args = array_values($args);// reorginizes the array - $this->layers[$layerId] = call_user_func_array(array($EffectsLib, $Effect), $args);// apply effect and returns an image. - unset($args[0]);// removes the current image from the array allowing the next image to be added. - } - return $group; - } - - else// if not recursive then applays effect to current layer. - { - array_unshift($args, $this->image); // adds current image - $args = array_values($args);// reorders arguments. - $layer = call_user_func_array(array($EffectsLib, $Effect), $args);// applys effect and return image. - return $layer;// doing this allow you to apply an effect on an image and store it in a new or old value. - } - } - /** * Apply a filter on the layer * Be careful: some filters can damage transparent images, use it sparingly ! (A good pratice is to use mergeAll on your layer before applying a filter) From b9db84e29ba151e005d75581a690acf5fac8f785 Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Tue, 6 May 2014 16:59:22 -0600 Subject: [PATCH 20/32] added EnableAlpha ( = true/false, = true/false) --- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index ca03614..1fe6017 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1204,6 +1204,11 @@ public function opacity($opacity, $recursive = true) * @param int $arg4 * @param boolean $recursive */ + public function EnableAlpha($enable = true,$save = true){ + imageAlphaBlending($this->image, $enable); + imageSaveAlpha($this->image, $save); + } + public function applyFilter($filterType, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null, $recursive = false) { if ($filterType == IMG_FILTER_COLORIZE) { From e1b8c15d0cd4e3d0c51b06142cc338247e66b715 Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Tue, 6 May 2014 18:12:19 -0600 Subject: [PATCH 21/32] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 137247a..b6de667 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ to your require_once request; http://phpimageworkshop.com/ ### Latest updates +**Version 2.0.7 - 2014-5-6** +- removed Layer Effect class and merged back into main Layer Class(Working to resolve issues with extracted effects). +- add new EnableAlpha: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). + **Version 2.0.6 - 2014-3-6** - Move Layer effect into there own class, allowing you to use your own effects libaries. @@ -109,4 +113,4 @@ The class is designed for PHP 5.3+, but it can work with older PHP versions... C ### @todo - Adding a method to add easily borders to a layer (external, inside and middle border) -- Check given hexa' color and remove # if exists. \ No newline at end of file +- Check given hexa' color and remove # if exists. From f5393582ddd06fdeb27aae2e764324e2b23f026f Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Tue, 6 May 2014 18:13:16 -0600 Subject: [PATCH 22/32] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b6de667..6b359ea 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ http://phpimageworkshop.com/ **Version 2.0.7 - 2014-5-6** - removed Layer Effect class and merged back into main Layer Class(Working to resolve issues with extracted effects). - add new EnableAlpha: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). + $layer->EnabeAlpha(true,true); **Version 2.0.6 - 2014-3-6** From 7cde389c9fd1b24dd5e6b27d1a7f0500f402c2ae Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Tue, 6 May 2014 18:13:49 -0600 Subject: [PATCH 23/32] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6b359ea..bd08eb5 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,9 @@ http://phpimageworkshop.com/ **Version 2.0.7 - 2014-5-6** - removed Layer Effect class and merged back into main Layer Class(Working to resolve issues with extracted effects). - add new EnableAlpha: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). +```php $layer->EnabeAlpha(true,true); +``` **Version 2.0.6 - 2014-3-6** From c093bf8d79800990c0105c1baabfd3aa6c8439f2 Mon Sep 17 00:00:00 2001 From: GoodLittleDev Date: Tue, 6 May 2014 18:17:54 -0600 Subject: [PATCH 24/32] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd08eb5..e68a6c5 100644 --- a/README.md +++ b/README.md @@ -19,19 +19,25 @@ to your require_once request; http://phpimageworkshop.com/ ### Latest updates -**Version 2.0.7 - 2014-5-6** +**Version 2.0.8 - 2014-5-6** - removed Layer Effect class and merged back into main Layer Class(Working to resolve issues with extracted effects). - add new EnableAlpha: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). ```php $layer->EnabeAlpha(true,true); ``` -**Version 2.0.6 - 2014-3-6** +**Version 2.0.7 - 2014-3-6** - Move Layer effect into there own class, allowing you to use your own effects libaries. - Added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. +**Version 2.0.7 - 2014-3-6** +- Forked +- Added Layer Effect: + - applyFilter + - + **Version 2.0.5 - 2013-11-12** - Implementing interlace mode (http://php.net/manual/en/function.imageinterlace.php) on save() method to display progessive JPEG image From 149e433aa5702094ac2d8222d5542f67b9400081 Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Tue, 6 May 2014 18:20:17 -0600 Subject: [PATCH 25/32] added EnableAlpha ( = true/false, = true/false) --- README.md | 9 +++++++-- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e68a6c5..29b1617 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,16 @@ http://phpimageworkshop.com/ - Added Extended_Effects method which request Effect name, EffectsLib object , and if it should apply recursively. -**Version 2.0.7 - 2014-3-6** +**Version 2.0.7 - 2014-2-5** - Forked - Added Layer Effect: - applyFilter - - + - applyimageconvolution + - toGreyscale + - applyalphamask + - splitchannels + - getchannel + - mergeChannels **Version 2.0.5 - 2013-11-12** diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 1fe6017..27dc176 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1497,7 +1497,7 @@ public function getchannel($channel){ * */ - public function mergechannels($group){ + public function mergeChannels($group){ $ChlR = $group->getLayer(1)->getResult(); $ChlG = $group->getLayer(2)->getResult(); $ChlB = $group->getLayer(3)->getResult(); From defc308e2cfae437d45e6716e6cb161c031562f4 Mon Sep 17 00:00:00 2001 From: "Jondalar K. Lee" Date: Tue, 6 May 2014 18:23:35 -0600 Subject: [PATCH 26/32] added EnableAlpha ( = true/false, = true/false) --- README.md | 12 ++++++------ src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 29b1617..e871158 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ http://phpimageworkshop.com/ ### Latest updates **Version 2.0.8 - 2014-5-6** - removed Layer Effect class and merged back into main Layer Class(Working to resolve issues with extracted effects). -- add new EnableAlpha: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). +- add new enableAlpha: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). ```php - $layer->EnabeAlpha(true,true); + $layer->enabeAlpha(true,true); ``` **Version 2.0.7 - 2014-3-6** @@ -36,11 +36,11 @@ http://phpimageworkshop.com/ - Forked - Added Layer Effect: - applyFilter - - applyimageconvolution + - applyImageConvolution - toGreyscale - - applyalphamask - - splitchannels - - getchannel + - applyAlphaMask + - splitChannels + - getChannel - mergeChannels **Version 2.0.5 - 2013-11-12** diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 27dc176..4ede735 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1204,7 +1204,7 @@ public function opacity($opacity, $recursive = true) * @param int $arg4 * @param boolean $recursive */ - public function EnableAlpha($enable = true,$save = true){ + public function enableAlpha($enable = true,$save = true){ imageAlphaBlending($this->image, $enable); imageSaveAlpha($this->image, $save); } @@ -1243,7 +1243,7 @@ public function applyFilter($filterType, $arg1 = null, $arg2 = null, $arg3 = nul * @author Email Goodlittledeveloper@gmail.com * */ - public function applyimageconvolution($matrix, $div=0, $offset=0,$recursive=false){ + public function applyImageConvolution($matrix, $div=0, $offset=0,$recursive=false){ if(is_string($matrix)){ $matrix = strtolower($matrix); switch($matrix){ @@ -1364,7 +1364,7 @@ public function toGreyscale($type = null,$recursive=false){ * */ - public function applyalphamask($mask){ + public function applyAlphaMask($mask){ $masktemp = clone $mask; @@ -1411,7 +1411,7 @@ public function applyalphamask($mask){ * */ - public function splitchannels(){ + public function splitChannels(){ if($this->getLastLayerId()!=0){ throw new ImageWorkshopException('Can\'t split channels of a layer group', static::ERROR_LAYER_GROUP); } @@ -1465,7 +1465,7 @@ public function splitchannels(){ * */ - public function getchannel($channel){ + public function getChannel($channel){ switch ($channel) { case 'red': return $this->getLayer(1); From cbe269490c65b783c805d05f599fba5af00128d1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 May 2014 00:35:41 -0600 Subject: [PATCH 27/32] added setTransparentColor Function --- .../Core/ImageWorkshopLayer.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 4ede735..f6a7366 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1209,6 +1209,24 @@ public function enableAlpha($enable = true,$save = true){ imageSaveAlpha($this->image, $save); } + public function setTransparentColor($r=0,$b=0,$g=0,$t=0,){ + for ($h=0; $h<$this->height; $h++){ + for ($w=0; $w<$this->width; $w++){ + $rgb = imagecolorat($this->image, $w, $h); + $Cr = ($rgb >> 16) & 0xFF; + $Cg = ($rgb >> 8) & 0xFF; + $Cb = $rgb & 0xFF; + + + if($Cr<$r+$t and $Cr>$r-$t and $Cg<$g+$t and $Cg>$g-$t and $Cb<$b+$t and $Cb>$b-$t or $Cr==$r and $Cg==$g and $Cb==$b){ + + imagesetpixel($this->image,$w,$h,imagecolorallocatealpha($this->image,$r,$g,$b,127)); + } + + } + } + } + public function applyFilter($filterType, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null, $recursive = false) { if ($filterType == IMG_FILTER_COLORIZE) { From 183f2620110a319c6a95bac740aa787a254a147f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 May 2014 01:35:40 -0600 Subject: [PATCH 28/32] added setTransparentColor Function --- README.md | 10 +++- .../Core/ImageWorkshopLayer.php | 51 ++++++++++++++----- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e871158..5593d3c 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,17 @@ http://phpimageworkshop.com/ ### Latest updates **Version 2.0.8 - 2014-5-6** - removed Layer Effect class and merged back into main Layer Class(Working to resolve issues with extracted effects). -- add new enableAlpha: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). +- add new enableAlpha method: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). +- add new setTransparentColor method: the first three arguments are RBG values of the color the forth is the tolerance so colors +/- the tolerance will also be made transparent the fifth argument is optional and it locks the tolerance so that only color with the same hue and saturation the same as the base color will be altered, optional feather by tolerance true/false is the sixth argument. this cause the degree of transpanancy to Decay futher the color differs from the base color. ```php + + $layer->enabeAlpha($blend,$save); + example: $layer->enabeAlpha(true,true); + + $layer->setTransparentColor($r,$g,$b,$tolerance,$Lock,$feather); + example: + $layer->setTransparentColor(0,0,0,7,false,true); ``` **Version 2.0.7 - 2014-3-6** diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index f6a7366..898b0b3 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -1194,39 +1194,66 @@ public function opacity($opacity, $recursive = true) } /** - * Apply a filter on the layer - * Be careful: some filters can damage transparent images, use it sparingly ! (A good pratice is to use mergeAll on your layer before applying a filter) + * Enable Alpha + * enable alpha blending and enable saving of the alpha channel. * - * @param int $filterType (http://www.php.net/manual/en/function.imagefilter.php) - * @param int $arg1 - * @param int $arg2 - * @param int $arg3 - * @param int $arg4 - * @param boolean $recursive + * @param boolen $enable - true enables alpha blending + * @param boolen $save - true enables saving of the alpha channel. */ + public function enableAlpha($enable = true,$save = true){ imageAlphaBlending($this->image, $enable); imageSaveAlpha($this->image, $save); } - public function setTransparentColor($r=0,$b=0,$g=0,$t=0,){ + /** + * Set TransparentColor + * makes a color transparent even if the image already has + * + * @param int $filterType (http://www.php.net/manual/en/function.imagefilter.php) + * @param int $r,$g,$b - color value for the color that is to be made transparent + * @param int $t - tolerance (color that are close to the color that is to be made transparent will also be made transparent) + * @param int $f - feather (color that are close will be made transparent by the degree that that are close to the color). + * @param int $L - lock luminissity (color are only considered clode if they have the same hue and saturation as the request color). + * @param boolean $recursive + */ + public function setTransparentColor($r=0,$b=0,$g=0,$t=0,$L = true,$f=false){ + if(!imageistruecolor($this->image)){ throw new ImageWorkshopException('Can\'t set a color to transparent Image is not true color', static::ERROR_LAYER_GROUP);} + for ($h=0; $h<$this->height; $h++){ for ($w=0; $w<$this->width; $w++){ $rgb = imagecolorat($this->image, $w, $h); $Cr = ($rgb >> 16) & 0xFF; $Cg = ($rgb >> 8) & 0xFF; $Cb = $rgb & 0xFF; + $alpha = 127; - if($Cr<$r+$t and $Cr>$r-$t and $Cg<$g+$t and $Cg>$g-$t and $Cb<$b+$t and $Cb>$b-$t or $Cr==$r and $Cg==$g and $Cb==$b){ + if($Cr<$r+$t and $Cr>$r-$t and $Cg<$g+$t and $Cg>$g-$t and $Cb<$b+$t and $Cb>$b-$t or $Cr==$r and $Cg==$g and $Cb==$b){// color comparason + if($Cr-$r == $Cg>$g and $Cg-$g == $Cb>$b or $L == false){// brightness lock + if($f==true){// Feathering + $alpha = 127-(127/$t)*($Cr-$r); + } - imagesetpixel($this->image,$w,$h,imagecolorallocatealpha($this->image,$r,$g,$b,127)); - } + imagesetpixel($this->image,$w,$h,imagecolorallocatealpha($this->image,$r,$g,$b,$alpha)); + } + } } } } + /** + * Apply a filter on the layer + * Be careful: some filters can damage transparent images, use it sparingly ! (A good pratice is to use mergeAll on your layer before applying a filter) + * + * @param int $filterType (http://www.php.net/manual/en/function.imagefilter.php) + * @param int $arg1 + * @param int $arg2 + * @param int $arg3 + * @param int $arg4 + * @param boolean $recursive + */ public function applyFilter($filterType, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null, $recursive = false) { if ($filterType == IMG_FILTER_COLORIZE) { From 60d029eb92c1a151ba3d49af7d5b3852d971f260 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 May 2014 01:36:44 -0600 Subject: [PATCH 29/32] added setTransparentColor Function --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5593d3c..62ce2da 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,13 @@ http://phpimageworkshop.com/ **Version 2.0.8 - 2014-5-6** - removed Layer Effect class and merged back into main Layer Class(Working to resolve issues with extracted effects). - add new enableAlpha method: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). -- add new setTransparentColor method: the first three arguments are RBG values of the color the forth is the tolerance so colors +/- the tolerance will also be made transparent the fifth argument is optional and it locks the tolerance so that only color with the same hue and saturation the same as the base color will be altered, optional feather by tolerance true/false is the sixth argument. this cause the degree of transpanancy to Decay futher the color differs from the base color. +- add new setTransparentColor method: the first three arguments are RBG values of the color the forth is the tolerance so colors +/- the tolerance will also be made transparent the fifth argument is optional and it locks the tolerance so that only color with the same hue and saturation as the base color will be altered, optional feather by tolerance true/false is the sixth argument. this cause the degree of transpanancy to Decay futher the color differs from the base color. ```php $layer->enabeAlpha($blend,$save); example: $layer->enabeAlpha(true,true); - + $layer->setTransparentColor($r,$g,$b,$tolerance,$Lock,$feather); example: $layer->setTransparentColor(0,0,0,7,false,true); From af82408cbbd7961336456ebcad0b8335090de152 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 May 2014 01:42:26 -0600 Subject: [PATCH 30/32] added setTransparentColor Function --- src/PHPImageWorkshop/Core/ImageWorkshopLayer.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 898b0b3..9be2984 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -127,6 +127,13 @@ class ImageWorkshopLayer * @var integer */ const ERROR_LAYER_GROUP = 6; + + /** + * @var integer + */ + const ERROR_IMAGE_TYPE = 7; + + // =================================================================================== // Methods @@ -1218,7 +1225,7 @@ public function enableAlpha($enable = true,$save = true){ * @param boolean $recursive */ public function setTransparentColor($r=0,$b=0,$g=0,$t=0,$L = true,$f=false){ - if(!imageistruecolor($this->image)){ throw new ImageWorkshopException('Can\'t set a color to transparent Image is not true color', static::ERROR_LAYER_GROUP);} + if(!imageistruecolor($this->image)){ throw new ImageWorkshopException('Can\'t set a color to transparent Image is not true color', static::ERROR_IMAGE_TYPE);} for ($h=0; $h<$this->height; $h++){ for ($w=0; $w<$this->width; $w++){ From 44870779118f1934b2f976f9a3b3eba93661e9f9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 May 2014 20:40:43 -0600 Subject: [PATCH 31/32] add loaders if file is not loaded --- README.md | 16 ++++++++++++++++ .../Exception/ImageWorkshopLayerException.php | 6 +++++- .../Exception/ImageWorkshopLibException.php | 6 +++++- .../Core/ImageWorkshopLayer.php | 19 ++++++++++++++++--- .../Core/ImageWorkshopLib.php | 8 +++++++- .../Exception/ImageWorkshopException.php | 6 +++++- src/PHPImageWorkshop/ImageWorkshop.php | 9 +++++++-- 7 files changed, 61 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 62ce2da..9387269 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,22 @@ to your require_once request; http://phpimageworkshop.com/ ### Latest updates +**Version 2.0.8.1 - 2014-5-6** +- Updated includeds to allow load files if the main class is not already defined (like autoloading except), if you still wish to auto load (inorder to add custom load files) then just comment out +```php + + if (!class_exists('classname')) { + require_once(pathandfilename.php'); +} + +// example : +if (!class_exists('ImageWorkshopLayer')) { // auto loads if not already loaded. + require_once(__DIR__.'/Core/ImageWorkshopLayer.php'); +} + +``` + + **Version 2.0.8 - 2014-5-6** - removed Layer Effect class and merged back into main Layer Class(Working to resolve issues with extracted effects). - add new enableAlpha method: the first argument turns on alpha blending for graphic manipuation, the second turns on alpha blending when saving image (this prevents the black background). diff --git a/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLayerException.php b/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLayerException.php index 34c1562..820301b 100644 --- a/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLayerException.php +++ b/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLayerException.php @@ -5,7 +5,11 @@ use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException; // If no autoloader, uncomment these lines: -require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php'); + +if (!class_exists('ImageWorkshopBaseException')) { // auto loads if not already loaded. + require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php'); +} + /** * ImageWorkshopLayerException diff --git a/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLibException.php b/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLibException.php index aecbed6..814117f 100644 --- a/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLibException.php +++ b/src/PHPImageWorkshop/Core/Exception/ImageWorkshopLibException.php @@ -5,7 +5,11 @@ use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException; // If no autoloader, uncomment these lines: -require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php'); + +if (!class_exists('ImageWorkshopBaseException')) { + require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php'); +} + /** * ImageWorkshopLibException diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php index 9be2984..3117e12 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php @@ -7,9 +7,22 @@ use PHPImageWorkshop\Core\Exception\ImageWorkshopLayerException as ImageWorkshopLayerException; // If no autoloader, uncomment these lines: -require_once(__DIR__.'/../ImageWorkshop.php'); -require_once(__DIR__.'/ImageWorkshopLib.php'); -require_once(__DIR__.'/Exception/ImageWorkshopLayerException.php'); +if (!class_exists('ImageWorkshop') and !isset($autoload)) { // auto loads if not already loaded. + require_once(__DIR__.'/../ImageWorkshop.php'); +} + +if (!class_exists('ImageWorkshopLib') and !isset($autoload)) { // auto loads if not already loaded. + require_once(__DIR__.'/ImageWorkshopLib.php'); +} + +if (!class_exists('ImageWorkshopLayerException') and !isset($autoload)) { // auto loads if not already loaded. + require_once(__DIR__.'/Exception/ImageWorkshopLayerException.php'); +} + + + + + /** * ImageWorkshopLayer class diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLib.php b/src/PHPImageWorkshop/Core/ImageWorkshopLib.php index c650218..1f41af7 100644 --- a/src/PHPImageWorkshop/Core/ImageWorkshopLib.php +++ b/src/PHPImageWorkshop/Core/ImageWorkshopLib.php @@ -5,7 +5,13 @@ use PHPImageWorkshop\Core\Exception\ImageWorkshopLibException as ImageWorkshopLibException; // If no autoloader, uncomment these lines: -require_once(__DIR__.'/Exception/ImageWorkshopLibException.php'); + + +if (!class_exists('ImageWorkshopLibException')) { + require_once(__DIR__.'/Exception/ImageWorkshopLibException.php'); +} + + /** * ImageWorkshopLib class diff --git a/src/PHPImageWorkshop/Exception/ImageWorkshopException.php b/src/PHPImageWorkshop/Exception/ImageWorkshopException.php index 7663c93..47458f0 100644 --- a/src/PHPImageWorkshop/Exception/ImageWorkshopException.php +++ b/src/PHPImageWorkshop/Exception/ImageWorkshopException.php @@ -5,7 +5,11 @@ use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException; // If no autoloader, uncomment these lines: -require_once(__DIR__.'/ImageWorkshopBaseException.php'); + +if (!class_exists('ImageWorkshopBaseException')) { + require_once(__DIR__.'/ImageWorkshopBaseException.php'); +} + /** * ImageWorkshopException diff --git a/src/PHPImageWorkshop/ImageWorkshop.php b/src/PHPImageWorkshop/ImageWorkshop.php index e963054..fe948c1 100644 --- a/src/PHPImageWorkshop/ImageWorkshop.php +++ b/src/PHPImageWorkshop/ImageWorkshop.php @@ -7,8 +7,13 @@ use PHPImageWorkshop\Exception\ImageWorkshopException as ImageWorkshopException; // If no autoloader, uncomment these lines: -require_once(__DIR__.'/Core/ImageWorkshopLayer.php'); -require_once(__DIR__.'/Exception/ImageWorkshopException.php'); + +if (!class_exists('ImageWorkshopLayer')) { // auto loads if not already loaded. + require_once(__DIR__.'/Core/ImageWorkshopLayer.php'); +} +if (!class_exists('ImageWorkshopException')) { + require_once(__DIR__.'/Exception/ImageWorkshopException.php'); +} /** * ImageWorkshop class From 7fee153be323ed68753ae60e32e2d32ac8dda0e7 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 May 2014 20:42:43 -0600 Subject: [PATCH 32/32] add loaders if file is not loaded --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 9387269..7a5fe5c 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,7 @@ ### Summary and features Really flexible and easy-to-use PHP class to work with images using the GD Library -Included Libary for Layer Effects. -to include effect libary please add: - -```php -require_once(the_Path_to_.'/PHPImageWorkshop/core/GLDEffectsLib.php'); -``` - -to your require_once request; +Included Layer Effects. http://phpimageworkshop.com/