protected function render($name) { $action = "render"; $animation = __DIR__ . "/gifs/{$name}.gif"; $checksumPath = __DIR__ . "/gifs/{$name}.{$action}.json"; $dir = __DIR__ . "/output/{$action}/{$name}"; $frameCount = 0; $checksums = []; $hasChecksums = $this->loadChecksums($checksumPath, $checksums); $this->createDirOrClear($dir); $stream = new MemoryStream(); $stream->loadFromFile($animation); $decoder = new Decoder($stream); $renderer = new Renderer($decoder); $renderer->start(function ($gd, $index) use(&$checksums, $hasChecksums, &$frameCount, $name, $dir) { $frameCount++; $paddedIndex = str_pad($index, 3, '0', STR_PAD_LEFT); $outputPath = "{$dir}/frame{$paddedIndex}.png"; imagepng($gd, $outputPath, 4, PNG_ALL_FILTERS); $checksum = sha1(file_get_contents($outputPath)); if ($hasChecksums) { $this->assertEquals($checksum, $checksums[$index]); } $checksums[$index] = $checksum; }); file_put_contents("{$dir}/{$name}.{$action}.json", json_encode($checksums, JSON_PRETTY_PRINT)); }
protected function render(Sample $sample) { $frameCount = 0; $checksums = []; $dir = $sample->emptyRenderedFramesDir(); $stream = new FileStream($sample->localPath()); $decoder = new Decoder($stream); $renderer = new Renderer($decoder); $renderer->start(function (FrameRenderedEvent $event) use(&$checksums, &$frameCount, $dir, $sample) { $frameCount++; $stream = new MemoryStream(); ob_start(); imagepng($event->renderedFrame, null, 4, PNG_ALL_FILTERS); $stream->writeString(ob_get_contents()); ob_end_clean(); //$paddedIndex = str_pad($event->frameIndex, 3, '0', STR_PAD_LEFT); //$stream->copyContentsToFile("$dir/frame{$paddedIndex}.gif"); $checksum = sha1($stream->getContents()); $this->assertEquals($checksum, $sample->getFrameRenderedSHA1($event->frameIndex)); $checksums[$event->frameIndex] = $checksum; }); file_put_contents("{$dir}/_sha1.json", json_encode($checksums, JSON_PRETTY_PRINT)); }