Adding possibility to create empty images with ImageAdapter
authorTim Düsterhus <timwolla@arcor.de>
Sat, 31 Mar 2012 19:49:34 +0000 (21:49 +0200)
committerTim Düsterhus <timwolla@arcor.de>
Sat, 31 Mar 2012 19:49:34 +0000 (21:49 +0200)
wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php
wcfsetup/install/files/lib/system/image/adapter/IImageAdapter.class.php
wcfsetup/install/files/lib/system/image/adapter/ImageAdapter.class.php
wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php

index 9b727763edbf6e4c386c6baafe6f0cc8beb01fcd..306838f0f35ddf48b2e35ecf85dc851720225b5a 100644 (file)
@@ -86,6 +86,16 @@ class GDImageAdapter implements IImageAdapter {
                }
        }
        
+       /**
+        * @see wcf\system\image\adapter\IImageAdapter::createEmptyImage()
+        */
+       public function createEmptyImage($width, $height) {
+               $this->image = imageCreate($width, $height);
+               $this->type = IMAGETYPE_PNG;
+               $this->setColor(0xFF, 0xFF, 0xFF);
+               $this->color = null;
+       }
+       
        /**
         * @see wcf\system\image\adapter\IImageAdapter::createThumbnail()
         */     
@@ -201,10 +211,10 @@ class GDImageAdapter implements IImageAdapter {
                        imageJPEG($image, '', 90);
                }
                
-               $thumbnail = ob_get_contents();
+               $stream = ob_get_contents();
                ob_end_clean();
                
-               file_put_contents($filename, $thumbnail);
+               file_put_contents($filename, $stream);
        }
        
        /**
index 9abcfc142c97711c04fa116ffb530cc1819cc787..449dc7ce3ff3a37ccf64324fd4fea90698f344a3 100644 (file)
@@ -27,6 +27,14 @@ interface IImageAdapter {
         */
        public function loadFile($file);
        
+       /**
+        * Creates a new empty image.
+        * 
+        * @param       integer         $width
+        * @param       integer         $height
+        */
+       public function createEmptyImage($width, $height);
+       
        /**
         * Creates a thumbnail from previously loaded image.
         * 
index 8de65cf7006510c53dfb6f9315af911a94520f85..9e6b8d68fa7fe40b99758964e11e0855b909a74c 100644 (file)
@@ -46,6 +46,13 @@ class ImageAdapter implements IImageAdapter {
                $this->adapter->loadFile($file);
        }
        
+       /**
+        * @see wcf\system\image\adapter\IImageAdapter::createEmptyImage()
+        */
+       public function createEmptyImage($width, $height) {
+               $this->adapter->createEmptyImage($width, $height);
+       }
+       
        /**
         * @see wcf\system\image\adapter\IImageAdapter::createThumbnail()
         */
@@ -127,7 +134,12 @@ class ImageAdapter implements IImageAdapter {
        /**
         * @see wcf\system\image\adapter\IImageAdapter::writeImage()
         */
-       public function writeImage($image, $filename) {
+       public function writeImage($image, $filename = null) {
+               if ($filename === null) {
+                       $filename = $image;
+                       $image = $this->adapter->getImage();
+               }
+               
                $this->adapter->writeImage($image, $filename);
        }
        
index ac21484cfe439074f0130ade4842a3355a58cec6..656907e1849c19675f0994b8f2dd3cdb0ea02391 100644 (file)
@@ -71,6 +71,14 @@ class ImagickImageAdapter implements IImageAdapter {
                $this->width = $this->imagick->getImageWidth();
        }
        
+       /**
+        * @see wcf\system\image\adapter\IImageAdapter::createEmptyImage()
+        */
+       public function createEmptyImage($width, $height) {
+               $this->imagick->newImage($width, $height, 'white');
+       }
+       
+       
        /**
         * @see wcf\system\image\adapter\IImageAdapter::createThumbnail()
         */