3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class BannerCreator{ public $im; private function createSpacedString(){ $s = ""; for($i=0;$i<$num;$i++){ $s = $s . " "; } return $s; } public function __construct() { $this->$im = imagecreate(912, 384); //set a background imagefill($this->$im,0,0,imagecolorallocate($this->$im, 14, 14, 14)); } public function getPicture(){ return imagepng($this->$im); } public function fillImage($date,$numberOfAdmins,$numberOfGuests){ $text_color = imagecolorallocate($this->$im, 20, 160, 20); $text_color2 = imagecolorallocate($this->$im, 160, 20, 20); //Prepare the string $text = "100110010010010101000011000100100011110100010000110111010111 110100110100100011111001001011100110010111100000000101011 010111111011011111011100001001100111100000110111001101110 010110101000110001110110000000001011011001011001011010011 000011101111000111001110010101111000010111111111001100101 110110001000001100010101001000000000111001011001100011110 000100000011011000001101000111011101110010100011000111100 111010000111110110111000111101010101110011010000100001100 011000000110111010000011110111000011010000000101101100100 001111100111010101000111110010001100000000100000011111001 100110010010010101000011000100100011110100010000110111111 110110001000001100010101001000000000111001011001100011110 110100110100100011111001001011100110010111100000000101011 010100100011011001001101000111011101110010100011000111100 "; $textar = explode("\n",$text); $newlinestr = ""; //Load the font $font = '/var/www/html/php/test/Lucida Console.ttf'; //Generate the strings $adminstr = "Admins 0x".dechex($numberOfAdmins); $userstr = "Guests 0x".dechex($numberOfGuests); for($i=0;$i<count($textar);$i++){ switch($i){ case 2: //print a clock: $onezro = "011111011011100011110100011011"; $padstr = createSpacedString(strlen($onezro)); $onezroend = createSpacedString(strlen($date.$padstr)).substr("0110100011001101010101",0,57-strlen($date.$padstr)); imagettftext($this->$im, 20, 0, 0, 20, $text_color, $font, $newlinestr.$onezro); imagettftext($this->$im, 20, 0, 0, 20, $text_color2, $font, $newlinestr.$padstr.$date); imagettftext($this->$im, 20, 0, 0, 20, $text_color, $font, $newlinestr.$onezroend); break; case 9: $start = "100110010"; $padstr = createSpacedString(strlen($start)); $end = createSpacedString(strlen($adminstr.$padstr)).substr("010101000111110010001100000000100000011111001",0,57-strlen($adminstr.$padstr)); imagettftext($this->$im, 20, 0, 0, 20, $text_color, $font, $newlinestr.$start); imagettftext($this->$im, 20, 0, 0, 20, $text_color2, $font, $newlinestr.$padstr.$adminstr); imagettftext($this->$im, 20, 0, 0, 20, $text_color, $font, $newlinestr.$end); break; case 10: $start = "100110010"; $padstr = createSpacedString(strlen($start)); $end = createSpacedString(strlen($userstr.$padstr)).substr("010010101000011000100100011110100010000110111111",0,57-strlen($userstr.$padstr)); imagettftext($this->$im, 20, 0, 0, 20, $text_color, $font, $newlinestr.$start); imagettftext($this->$im, 20, 0, 0, 20, $text_color2, $font, $newlinestr.$padstr.$userstr); imagettftext($this->$im, 20, 0, 0, 20, $text_color, $font, $newlinestr.$end); break; default: imagettftext($this->$im, 20, 0, 0, 20, $text_color, $font, $newlinestr.$textar[$i]); }//End of switch $newlinestr = $newlinestr . "\n"; }//End of for loop }//EnfillImage() }//End offillImage() //Output error_reporting(E_ALL); header("Content-type: image/png"); $banner = new BannerCreator(); $banner->fillImage(date("l jS F H:i"),1,2); echo $banner->getPicture(); ?>
Output for 7.1.0 - 7.3.0beta1
Fatal error: Uncaught Error: Call to undefined function imagecreate() in /in/niBol:13 Stack trace: #0 /in/niBol(91): BannerCreator->__construct() #1 {main} thrown in /in/niBol on line 13
Process exited with code 255.
Output for hhvm-3.22.0
Notice: Undefined variable: im in /in/niBol on line -1 Fatal error: Uncaught Error: Cannot access empty property in /in/niBol:-1 Stack trace: #0 /in/niBol(-1): BannerCreator->__construct() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Notice: Undefined variable: im in /in/niBol on line 13 Fatal error: Uncaught Error: Cannot access empty property in /in/niBol:13 Stack trace: #0 /in/niBol(91): BannerCreator->__construct() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Fatal error: Call to undefined function imagecreate() in /in/niBol on line 13
Process exited with code 255.