Image.drawing.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Test: Nette\Utils\Image drawing.
  4. * @phpExtension gd
  5. */
  6. declare(strict_types=1);
  7. use Nette\Utils\Image;
  8. use Nette\Utils\ImageColor;
  9. use Tester\Assert;
  10. require __DIR__ . '/../bootstrap.php';
  11. $size = 300;
  12. $image = Image::fromBlank($size, $size);
  13. $image->filledRectangleWH(0, 0, 300, 300, ImageColor::rgb(255, 255, 255));
  14. $image->rectangleWH(0, 0, 300, 300, ImageColor::rgb(0, 0, 0));
  15. $image->filledRectangleWH(20, 20, -5, -5, ImageColor::rgb(100, 0, 0));
  16. $image->rectangleWH(20, 20, -5, -5, ImageColor::rgb(100, 255, 255));
  17. $image->filledRectangleWH(30, 30, 0, 0, ImageColor::rgb(127, 127, 0));
  18. $image->rectangleWH(35, 35, 0, 0, ImageColor::rgb(127, 127, 0));
  19. $radius = 150;
  20. $image->filledEllipse(100, 75, $radius, $radius, Image::rgb(255, 255, 0, 75));
  21. $image->filledEllipse(120, 168, $radius, $radius, Image::rgb(255, 0, 0, 75));
  22. $image->filledEllipse(187, 125, $radius, $radius, Image::rgb(0, 0, 255, 75));
  23. $image->copyResampled($image, 200, 200, 0, 0, 80, 80, $size, $size);
  24. Assert::same(file_get_contents(__DIR__ . '/expected/Image.drawing.1.png'), $image->toString($image::PNG));
  25. // palette-based image
  26. $image = Image::fromFile(__DIR__ . '/fixtures.images/logo.gif');
  27. $image->filledEllipse(100, 50, 50, 50, Image::rgb(255, 255, 0, 75));
  28. $image->filledEllipse(100, 150, 50, 50, Image::rgb(255, 255, 0, 75));
  29. Assert::same(file_get_contents(__DIR__ . '/expected/Image.drawing.2.png'), $image->toString($image::PNG));