public function execute(Dm_Image $image) { $w = $this->width; $h = $this->height; $x = (int) (($image->getWidth() - $w) * 0.5); $y = (int) (($image->getHeight() - $h) * 0.5); $resampledResource = imagecreatetruecolor($w, $h); //背景色設定(透過を有効化) imagesavealpha($resampledResource, true); // imagealphablending($imageResource, false); $colorId = Dm_Color::argb(0)->imagecolorallocatealpha($resampledResource); // imagefilledrectangle($imageResource, 0, 0, $width-1, $height-1, $colorId); imagefill($resampledResource, 0, 0, $colorId); imagecopyresampled($resampledResource, $image->getImageResource(), 0, 0, $x, $y, $image->getWidth(), $image->getHeight(), $image->getWidth(), $image->getHeight()); return $resampledResource; }
public function execute(Dm_Image $image) { $width = $this->width; $height = $this->height; $ratio = 1; $wRatio = $width / $image->getWidth(); $hRatio = $height / $image->getHeight(); if ($wRatio > $hRatio) { $ratio = $this->bounding ? $wRatio : $hRatio; } else { $ratio = $this->bounding ? $hRatio : $wRatio; } $w = $image->getWidth() * $ratio; $h = $image->getHeight() * $ratio; $resampledResource = imagecreatetruecolor($w, $h); //背景色設定(透過を有効化) imagesavealpha($resampledResource, true); // imagealphablending($imageResource, false); $colorId = Dm_Color::argb(0)->imagecolorallocatealpha($resampledResource); // imagefilledrectangle($imageResource, 0, 0, $width-1, $height-1, $colorId); imagefill($resampledResource, 0, 0, $colorId); imagecopyresampled($resampledResource, $image->getImageResource(), 0, 0, 0, 0, $w, $h, $image->getWidth(), $image->getHeight()); return $resampledResource; }
/** * Copy and merge part of an image * @param DmImage * @param int x-coordinate of source point. * @param int y-coordinate of source point. * @param int Source width. * @param int Source height. * @return bool Returns TRUE on success or FALSE on failure. */ public function draw(Dm_Image $image, $x = 0, $y = 0, $width = null, $height = null) { $srcImageResource = $image->getImageResource(); if (is_null($width)) { $width = $image->getWidth(); } if (is_null($height)) { $height = $image->getHeight(); } return imagecopy($this->getImageResource(), $srcImageResource, $x, $y, 0, 0, $width, $height); }