/** * 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; }
/** * 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); }
/** * 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; }