/**
  * Returns a copy of the image
  * 
  * @param $trueColor True if the new image should be truecolor
  * @return GDImage_Image
  */
 protected function copyAsNew($trueColor = false)
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     if ($trueColor) {
         $new = GDImage_TrueColorImage::create($width, $height);
     } else {
         $new = GDImage_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 a resized image
  *
  * @param GDImage_Image $img
  * @param smart_coordinate $width
  * @param smart_coordinate $height
  * @param string $fit
  * @param string $scale
  * @return GDImage_Image
  */
 function execute($img, $width, $height, $fit, $scale = 'any')
 {
     $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) {
         JError::raiseError(500, JText::_('JLIB_GDIMAGE_ERROR_DIMENSIONS_ZERO'));
         return false;
     }
     if ($img->isTransparent()) {
         $new = GDImage_PaletteImage::create($dim['width'], $dim['height']);
         $new->copyTransparencyFrom($img);
         imagecopyresized($new->getHandle(), $img->getHandle(), 0, 0, 0, 0, $new->getWidth(), $new->getHeight(), $img->getWidth(), $img->getHeight());
     } else {
         $new = GDImage_TrueColorImage::create($dim['width'], $dim['height']);
         $new->alphaBlending(false);
         $new->saveAlpha(true);
         imagecopyresampled($new->getHandle(), $img->getHandle(), 0, 0, 0, 0, $new->getWidth(), $new->getHeight(), $img->getWidth(), $img->getHeight());
         $new->alphaBlending(true);
     }
     return $new;
 }
 /**
  * Factory method for creating a palette image
  * 
  * @param int $width
  * @param int $height
  */
 static function createPaletteImage($width, $height)
 {
     return GDImage_PaletteImage::create($width, $height);
 }