コード例 #1
0
 /**
  * Returns an image with only specified channels copied
  *
  * @param WideImage_PaletteImage $img
  * @param array $channels
  * @return WideImage_PaletteImage
  */
 function execute($img, $channels)
 {
     $blank = array('red' => 0, 'green' => 0, 'blue' => 0);
     if (isset($channels['alpha'])) {
         unset($channels['alpha']);
     }
     $width = $img->getWidth();
     $height = $img->getHeight();
     $copy = WideImage_PaletteImage::create($width, $height);
     if ($img->isTransparent()) {
         $otci = $img->getTransparentColor();
         $TRGB = $img->getColorRGB($otci);
         $tci = $copy->allocateColor($TRGB);
     } else {
         $otci = null;
         $tci = null;
     }
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $ci = $img->getColorAt($x, $y);
             if ($ci === $otci) {
                 $copy->setColorAt($x, $y, $tci);
                 continue;
             }
             $RGB = $img->getColorRGB($ci);
             $newRGB = $blank;
             foreach ($channels as $channel) {
                 $newRGB[$channel] = $RGB[$channel];
             }
             $color = $copy->getExactColor($newRGB);
             if ($color == -1) {
                 $color = $copy->allocateColor($newRGB);
             }
             $copy->setColorAt($x, $y, $color);
         }
     }
     if ($img->isTransparent()) {
         $copy->setTransparentColor($tci);
     }
     return $copy;
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: WideImage.php プロジェクト: Kangaro97/PalmUp
 /**
  * Factory method for creating a palette image
  * 
  * @param int $width
  * @param int $height
  * @return WideImage_PaletteImage
  */
 static function createPaletteImage($width, $height)
 {
     return WideImage_PaletteImage::create($width, $height);
 }
コード例 #4
0
 /**
  * Returns a resized image
  *
  * @param WideImage_Image $img
  * @param smart_coordinate $width
  * @param smart_coordinate $height
  * @param string $fit
  * @param string $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;
 }