/** * Create a new image with specified width, height and color * * @param int $width The new image width in pixels * @param int $height The new image height in pixels * @param Color $color The new image color * * @return \imagemanipulation\ImageResource */ public static function create($width, $height, Color $color) { Args::int($width, 'width')->required()->min(1); Args::int($height, 'height')->required()->min(1); $res = new ImageResource(imagecreatetruecolor($width, $height)); $color = ImageUtil::allocateColor($res->getResource(), $color); imagefill($res->getResource(), 0, 0, $color); $res->saveAlpha(); return $res; }
public function apply() { $res = ImageUtil::createTransparentImage($this->width, $this->height); $horizontal = 0; $vertical = 0; while ($horizontal < $this->width && $vertical < $this->height) { $width = min(500, $this->width - $horizontal); $height = min(500, $this->height - $vertical); $result = imagecopy($res, $this->resource->getResource(), $horizontal, $vertical, 0, 0, $width, $height); if (!$result) { throw new \Exception('Could not copy image'); } $horizontal += $this->resource->getX(); if ($horizontal >= $this->width) { $horizontal = 0; $vertical += $this->resource->getY(); } } return new ImageResource($res); }
/** * Create a new resource from the location of the segment * * @param Segment $segment * * @return \imagemanipulation\ImageResource */ public function createResource(Segment $segment) { $resource = new ImageResource(ImageUtil::createImage($segment->getWidth(), $segment->getHeight())); imagecopy($resource->getResource(), $this->resource->getResource(), 0, 0, $segment->getCoordinate()->getX(), $segment->getCoordinate()->getY(), $segment->getWidth(), $segment->getHeight()); return $resource; }