コード例 #1
0
 public function testFilter()
 {
     $image = $this->getOriginalImage(ImageType::PNG);
     $filter = new ImageFilterGrayScale();
     $rasterizer = new Rasterizer($image, new GridRasterStrategy(25, 25, true));
     $segments = $rasterizer->getSegments();
     $rasterizer->filter($filter, $segments->offsetGet(0));
     $rasterizer->filter($filter, $segments->offsetGet(5));
     $originalColor = "ff0000";
     $filteredColor = "4c4c4c";
     $color = ColorUtil::getColorAt($rasterizer->getResource(), Coordinate::create(50, 50));
     $this->assertEquals($filteredColor, $color->getHexColor());
     $color = ColorUtil::getColorAt($rasterizer->getResource(), Coordinate::create(160, 50));
     $this->assertEquals($originalColor, $color->getHexColor());
     $color = ColorUtil::getColorAt($rasterizer->getResource(), Coordinate::create(50, 160));
     $this->assertEquals($originalColor, $color->getHexColor());
     $color = ColorUtil::getColorAt($rasterizer->getResource(), Coordinate::create(160, 160));
     $this->assertEquals($filteredColor, $color->getHexColor());
 }
コード例 #2
0
<?php

use imagemanipulation\rasterize\Rasterizer;
use imagemanipulation\rasterize\strategy\GridRasterStrategy;
use imagemanipulation\filter\ImageFilterGrayScale;
use imagemanipulation\ImageType;
const EVEN = 0;
const ODD = 1;
$rasterizer = new Rasterizer(new \SplFileInfo(__DIR__ . DIRECTORY_SEPARATOR . 'uglydog.png'), new GridRasterStrategy(10, 10, true));
$filter = new ImageFilterGrayScale();
// create a checkers board
foreach ($rasterizer->getSegments() as $i => $segment) {
    $check = floor($i / 10) % 2 ? ODD : EVEN;
    // 10 segments per row
    if ($i % 2 === $check) {
        $resource = $rasterizer->createResource($segment);
        $resource->filter($filter);
        $rasterizer->writeSegment($resource, $segment);
    }
}
$rasterizer->getResource()->render(ImageType::PNG, 80);