From ee5e044fa0fd1e13b8c85a9007bf7bf22d6b33b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Dartigues?= Date: Thu, 5 Feb 2015 16:00:35 +0100 Subject: [PATCH] preserve alpha transparency in png loaded as string Peer to Bruno Ratnieks's answer to the following question on stackoverflow: http://stackoverflow.com/questions/2017826/php-imagecreatefromstring-and-file-get-contents --- src/PHPThumb/GD.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/PHPThumb/GD.php b/src/PHPThumb/GD.php index 350bf19..bb4f6a7 100644 --- a/src/PHPThumb/GD.php +++ b/src/PHPThumb/GD.php @@ -1380,6 +1380,25 @@ protected function verifyFormatCompatiblity() */ protected function preserveAlpha() { + + // preserve alpha transparency in png loaded as string + if ( $this->format == 'STRING' && $this->options['preserveAlpha']===true) + { + imagealphablending($this->workingImage, true); + + $colorTransparent = imagecolorallocatealpha + ( + $this->workingImage, + $this->options['alphaMaskColor'][0], + $this->options['alphaMaskColor'][1], + $this->options['alphaMaskColor'][2], + 0 + ); + + imagefill($this->workingImage, 0, 0, $colorTransparent); + imagesavealpha($this->workingImage, true); + } + if ($this->format == 'PNG' && $this->options['preserveAlpha'] === true) { imagealphablending($this->workingImage, false);