3v4l.org

run code in 300+ PHP versions simultaneously
<?php // thumb width $square = 150; $large = 200; $small = 100; ////////////////////////////////////////////////////////////////////////////////// square if( isset($_GET[img]) && ( $_GET[type] == "square" || $_GET[type] == "" ) ){ // thumb size $thumb_width = $square; $thumb_height = $square; // align $align = $_GET[align]; // image source $imgSrc = $_GET[img]; $imgExt = substr($imgSrc,-3); // image extension if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); } if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); } if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); } // getting the image dimensions list($width_orig, $height_orig) = getimagesize($imgSrc); // ratio $ratio_orig = $width_orig/$height_orig; // landscape or portrait? if ($thumb_width/$thumb_height > $ratio_orig) { $new_height = $thumb_width/$ratio_orig; $new_width = $thumb_width; } else { $new_width = $thumb_height*$ratio_orig; $new_height = $thumb_height; } // middle $x_mid = $new_width/2; $y_mid = $new_height/2; // create new image $process = imagecreatetruecolor(round($new_width), round($new_height)); imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); // alignment if($align == ""){ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "top"){ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), 0, $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "bottom"){ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($new_height-$thumb_height), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "left"){ imagecopyresampled($thumb, $process, 0, 0, 0, ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "right"){ imagecopyresampled($thumb, $process, 0, 0, ($new_width-$thumb_width), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } imagedestroy($process); imagedestroy($myImage); if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); } if($imgExt == "gif"){ imagegif($thumb); } if($imgExt == "png"){ imagepng($thumb, null, 9); } } ////////////////////////////////////////////////////////////////////////////////// normal if( isset($_GET[img]) && ( $_GET[type] == "large" || $_GET[type] == "small" ) ){ if( $_GET[type] == "large" ){ $thumb_width = $large; } if( $_GET[type] == "small" ){ $thumb_width = $small; } // image source $imgSrc = $_GET[img]; $imgExt = substr($imgSrc,-3); // image extension if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); } if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); } if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); } //getting the image dimensions list($width_orig, $height_orig) = getimagesize($imgSrc); // ratio $ratio_orig = $width_orig/$height_orig; $thumb_height = $thumb_width/$ratio_orig; // new dimensions $new_width = $thumb_width; $new_height = $thumb_height; // middle $x_mid = $new_width/2; $y_mid = $new_height/2; // create new image $process = imagecreatetruecolor(round($new_width), round($new_height)); imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); } if($imgExt == "gif"){ imagegif($thumb); } if($imgExt == "png"){ imagepng($thumb, null, 9); } } ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Undefined constant "img" in /in/Cj6kP:9 Stack trace: #0 {main} thrown in /in/Cj6kP on line 9
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant img - assumed 'img' (this will throw an Error in a future version of PHP) in /in/Cj6kP on line 9 Warning: Use of undefined constant img - assumed 'img' (this will throw an Error in a future version of PHP) in /in/Cj6kP on line 78
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Notice: Use of undefined constant img - assumed 'img' in /in/Cj6kP on line 9 Notice: Use of undefined constant img - assumed 'img' in /in/Cj6kP on line 78

preferences:
256.4 ms | 402 KiB | 329 Q