3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $width = 150; $height = 100; // create new image $img = imagecreatetruecolor($width, $height); // transparent background $background = imagecolorallocate($img, 0xFF, 0xFF, 0xFF); imagefilledrectangle ($img, 0,0, $width,$height, $background); imagecolortransparent($img, $background); // helper function, draws pixel and mirrors it function setpixel4($img, $centerX, $centerY, $deltaX, $deltaY, $color) { imagesetpixel($img, $centerX + $deltaX, $centerY + $deltaY, $color); imagesetpixel($img, $centerX - $deltaX, $centerY + $deltaY, $color); imagesetpixel($img, $centerX + $deltaX, $centerY - $deltaY, $color); imagesetpixel($img, $centerX - $deltaX, $centerY - $deltaY, $color); } // red ellipse, 2*10px border $color = imagecolorallocate($img, 0xFF, 0x00, 0x00); $centerX = $width /2; $radiusX = ($width -20) / 2; $centerY = $height/2; $radiusY = ($height-20) / 2; static $maxTransparency = 0x7F; // 127 $radiusX2 = $radiusX * $radiusX; $radiusY2 = $radiusY * $radiusY; // upper and lower halves $quarter = round($radiusX2 / sqrt($radiusX2 + $radiusY2)); for ($x = 0; $x <= $quarter; $x++) { $y = $radiusY * sqrt(1-$x*$x/$radiusX2); $error = $y - floor($y); $transparency = round($error * $maxTransparency); $alpha = $color | ($transparency << 24); $alpha2 = $color | (($maxTransparency - $transparency) << 24); setpixel4($img, $centerX, $centerY, $x, floor($y), $alpha); setpixel4($img, $centerX, $centerY, $x, floor($y)+1, $alpha2); } // right and left halves $quarter = round($radiusY2 / sqrt($radiusX2 + $radiusY2)); for ($y = 0; $y <= $quarter; $y++) { $x = $radiusX * sqrt(1-$y*$y/$radiusY2); $error = $x - floor($x); $transparency = round($error * $maxTransparency); $alpha = $color | ($transparency << 24); $alpha2 = $color | (($maxTransparency - $transparency) << 24); setpixel4($img, $centerX, $centerY, floor($x), $y, $alpha); setpixel4($img, $centerX, $centerY, floor($x)+1, $y, $alpha2); } // send PNG to browser header("Content-type: image/png"); imagepng($img, "", 9, PNG_ALL_FILTERS); ?>
Output for 7.0.0 - 7.2.6
Fatal error: Uncaught Error: Call to undefined function imagecreatetruecolor() in /in/B3WE9:6 Stack trace: #0 {main} thrown in /in/B3WE9 on line 6
Process exited with code 255.
Output for 5.0.0 - 5.6.28
Fatal error: Call to undefined function imagecreatetruecolor() in /in/B3WE9 on line 6
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: imagecreatetruecolor() in /in/B3WE9 on line 6
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: imagecreatetruecolor() in /in/B3WE9 on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: imagecreatetruecolor() in /in/B3WE9 on line 6