Exemplo n.º 1
0
 /**
  * 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;
 }
 function testCreate()
 {
     $img = WideImage_TrueColorImage::create(10, 10);
     $this->assertTrue($img instanceof WideImage_TrueColorImage);
     $this->assertTrue($img->isValid());
     $this->assertTrue($img->isTrueColor());
 }
Exemplo n.º 3
0
 /**
  * Returns a copy of the image
  * 
  * @param $trueColor True if the new image should be truecolor
  * @return WideImage_Image
  */
 protected function copyAsNew($trueColor = false)
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     if ($trueColor) {
         $new = WideImage_TrueColorImage::create($width, $height);
     } else {
         $new = WideImage_PaletteImage::create($width, $height);
     }
     // copy transparency of source to target
     if ($this->isTransparent()) {
         $rgb = $this->getTransparentColorRGB();
         if (is_array($rgb)) {
             $tci = $new->allocateColor($rgb['red'], $rgb['green'], $rgb['blue']);
             $new->fill(0, 0, $tci);
             $new->setTransparentColor($tci);
         }
     }
     imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height);
     return $new;
 }
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * Factory method for creating a true-color image
  * 
  * @param int $width
  * @param int $height
  * @return WideImage_TrueColorImage
  */
 static function createTrueColorImage($width, $height)
 {
     return WideImage_TrueColorImage::create($width, $height);
 }
Exemplo n.º 6
0
 /**
 * Returns a resized image
 *
 * @param WideImage_Image  $img
 * @param smart_coordinate $width
 * @param smart_coordinate $height
 * @param UTF8String       $fit
 * @param UTF8String       $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;
 }
Exemplo n.º 7
0
 function testResizeBug214()
 {
     $img = WideImage_TrueColorImage::create(1600, 1200);
     $resized = $img->resize(214, null, 'outside');
     $this->assertEquals(214, $resized->getWidth());
     $this->assertEquals(161, $resized->getHeight());
 }
Exemplo n.º 8
0
 /**
  * (non-PHPdoc)
  * @see WideImage_Image#asTrueColor()
  */
 function asTrueColor()
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $new = WideImage_TrueColorImage::create($width, $height);
     if ($this->isTransparent()) {
         $new->copyTransparencyFrom($this);
     }
     imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height);
     return $new;
 }
Exemplo n.º 9
0
 function testInternalOpCaseInsensitive()
 {
     $img = WideImage_TrueColorImage::create(10, 10);
     $result = $img->AUTOcrop();
     $this->assertTrue($result instanceof WideImage_Image);
 }