Guest User

Untitled

a guest
May 21st, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. <?php
  2. /*
  3. * (c) 2017/08/21- yoya@awm.jp
  4. * $ composer require meyfa/php-svg
  5. */
  6. require_once("vendor/autoload.php");
  7.  
  8. use SVG\SVGImage;
  9. use SVG\Nodes\Structures\SVGStyle;
  10. use SVG\Nodes\Structures\SVGDefs;
  11. use SVG\Nodes\Gradients\SVGStop;
  12. use SVG\Nodes\Gradients\SVGRadialGradient;
  13. use SVG\Nodes\Shapes\SVGRect;
  14.  
  15. list($width, $height) = [1000, 1000];
  16.  
  17. $image = new SVGImage($width, $height);
  18. $doc = $image->getDocument();
  19.  
  20. $style = new SVGStyle();
  21. $style->setCss(":root{background-color:black;}");
  22.  
  23. $doc->addChild($style);
  24.  
  25. $defs = new SVGDefs();
  26. $doc->addChild($defs);
  27.  
  28. $gradTable = [
  29. "rgrad" => ["#F00", "#D00", "black"],
  30. "ggrad" => ["#0F0", "#0D0", "black"],
  31. "bgrad" => ["#22F", "#11D", "black"],
  32. ];
  33.  
  34. foreach ($gradTable as $id => $colors) {
  35. $grad = new SVGRadialGradient(0.5, 0.5, 0.7);
  36. $grad->setAttribute("id", $id);
  37. $stop0 = new SVGStop("40%", $colors[0]);
  38. $stop1 = new SVGStop("60%", $colors[1]);
  39. $stop2 = new SVGStop("100%",$colors[2]);
  40. $grad->addChild($stop0);
  41. $grad->addChild($stop1);
  42. $grad->addChild($stop2);
  43. $defs->addChild($grad);
  44. }
  45.  
  46. $scale = 2;
  47. list($unitX, $unitY) = [10*$scale, 40*$scale];
  48. list($marginX1 , $marginY1) = [4*$scale, 2*$scale];
  49. list($marginX2 , $marginY2) = [4*$scale, 4*$scale];
  50.  
  51. $dy = $unitY + $marginY1 +$marginY2;
  52. for ($y = 0, $row = 0 ; $y < $height ; $y+=$dy, $row++) {
  53. for ($x = 0, $column = 0 ; $x < $width ; $column++) {
  54. for ($i = 0 ; $i < 3 ; $i++) {
  55. $rect = new SVGRect($x, $y - (($column%2)?0:($dy/2)), $unitX, $unitY, $unitX/2, $unitY/7);
  56. //$color = ["#F00", "#0F0", "#44F"][$i];
  57. $color = ["url(#rgrad)","url(#ggrad)","url(#bgrad)"][$i];
  58. $rect->setStyle('fill', $color);
  59. $doc->addChild($rect);
  60. $x += $unitX + $marginX1;
  61. }
  62. $x += $marginX2;
  63. }
  64. }
  65.  
  66. //header('Content-Type: image/svg+xml');
  67. //echo $image;
  68. //exit (0);
  69.  
  70. //$rasterImage = $image->toRasterImage($width*2, $height*2);
  71. //header('Content-Type: image/png');
  72. //imagepng($rasterImage);
Add Comment
Please, Sign In to add comment