From e6dadb215e9e08491ae57ab851960a0973d3f704 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Tue, 5 Feb 2019 23:03:03 +0100 Subject: Refactor photo_driver to use namespaces. Add simple UnitTest, but it is not yet very meaningful. --- include/photo/photo_gd.php | 162 --------------------------------------------- 1 file changed, 162 deletions(-) delete mode 100644 include/photo/photo_gd.php (limited to 'include/photo/photo_gd.php') diff --git a/include/photo/photo_gd.php b/include/photo/photo_gd.php deleted file mode 100644 index e98ac2827..000000000 --- a/include/photo/photo_gd.php +++ /dev/null @@ -1,162 +0,0 @@ -valid = false; - if(! $data) - return; - - $this->image = @imagecreatefromstring($data); - if($this->image !== FALSE) { - $this->valid = true; - $this->setDimensions(); - imagealphablending($this->image, false); - imagesavealpha($this->image, true); - } - } - - function setDimensions() { - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - } - - - public function clearexif() { - return; - } - - - public function destroy() { - if($this->is_valid()) { - imagedestroy($this->image); - } - } - - public function getImage() { - if(!$this->is_valid()) - return FALSE; - - return $this->image; - } - - public function doScaleImage($dest_width,$dest_height) { - - $dest = imagecreatetruecolor( $dest_width, $dest_height ); - $width = imagesx($this->image); - $height = imagesy($this->image); - - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->setDimensions(); - } - - public function rotate($degrees) { - if(!$this->is_valid()) - return FALSE; - - $this->image = imagerotate($this->image,$degrees,0); - $this->setDimensions(); - } - - public function flip($horiz = true, $vert = false) { - if(!$this->is_valid()) - return FALSE; - - $w = imagesx($this->image); - $h = imagesy($this->image); - $flipped = imagecreate($w, $h); - if($horiz) { - for ($x = 0; $x < $w; $x++) { - imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h); - } - } - if($vert) { - for ($y = 0; $y < $h; $y++) { - imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1); - } - } - $this->image = $flipped; - $this->setDimensions(); // Shouldn't really be necessary - } - - public function cropImage($max,$x,$y,$w,$h) { - if(!$this->is_valid()) - return FALSE; - - $dest = imagecreatetruecolor( $max, $max ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->setDimensions(); - } - - public function cropImageRect($maxx,$maxy,$x,$y,$w,$h) { - if(!$this->is_valid()) - return FALSE; - - $dest = imagecreatetruecolor( $maxx, $maxy ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $maxx, $maxy, $w, $h); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->setDimensions(); - } - - - - public function imageString() { - if(!$this->is_valid()) - return FALSE; - - $quality = FALSE; - - ob_start(); - - switch($this->getType()){ - case "image/png": - $quality = get_config('system','png_quality'); - if((! $quality) || ($quality > 9)) - $quality = PNG_QUALITY; - imagepng($this->image,NULL, $quality); - break; - case "image/jpeg": - default: - $quality = get_config('system','jpeg_quality'); - if((! $quality) || ($quality > 100)) - $quality = JPEG_QUALITY; - imagejpeg($this->image,NULL,$quality); - break; - } - $string = ob_get_contents(); - ob_end_clean(); - - return $string; - } - -} -- cgit v1.2.3