3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ColorShifter{ private $colors; public function __construct($colors) { $this->colors = new ArrayObject($colors); } public function getNext() { $this->colors->getIterator()->next(); return $this->colors->getIterator()->current(); } } $imageWidth = 300; $imageHeight = 350; $image = imagecreate($imageWidth, $imageHeight); $red = imagecolorallocate($image, 255, 10 , 10); $blue = imagecolorallocate($image, 10, 10 , 255); $gold = imagecolorallocate($image, 255, 240, 0); $colors = new ArrayObject(array($red, $blue, $gold)); $iterator = $colors->getIterator(); for($i = 0; $i<$imageWidth; $i += 10){ if(!$iterator->valid()) $iterator->rewind(); $iterator->next(); imagefilledrectangle($image, 0 , 0, $imageWidth - $i , $imageHeight-$i, $iterator->current()); } $iterator->next(); imagefilledrectangle($image, 0, 0, 10, 10, $iterator->current()); imagepng($image); header('Content-Type: image/png'); echo $image;

preferences:
47.64 ms | 402 KiB | 5 Q