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); } } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0120.00317.00
8.3.50.0100.00921.15
8.3.40.0070.00718.86
8.3.30.0070.00718.78
8.3.20.0070.00020.46
8.3.10.0000.00821.77
8.3.00.0040.00423.65
8.2.180.0120.00316.63
8.2.170.0110.00722.96
8.2.160.0040.01120.50
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0000.00819.82
8.2.120.0040.00426.35
8.2.110.0090.00019.30
8.2.100.0090.00418.05
8.2.90.0040.00419.35
8.2.80.0060.00317.97
8.2.70.0040.00417.63
8.2.60.0080.00017.93
8.2.50.0080.00018.10
8.2.40.0030.00820.58
8.2.30.0000.00819.55
8.2.20.0000.00717.87
8.2.10.0040.00418.26
8.2.00.0040.00418.23
8.1.280.0040.01125.92
8.1.270.0070.00020.45
8.1.260.0040.00428.09
8.1.250.0030.00628.09
8.1.240.0070.00321.25
8.1.230.0110.00019.54
8.1.220.0000.00817.91
8.1.210.0000.00818.77
8.1.200.0000.01017.36
8.1.190.0070.00317.48
8.1.180.0000.00818.10
8.1.170.0040.00418.76
8.1.160.0040.00420.81
8.1.150.0000.00718.89
8.1.140.0090.00019.58
8.1.130.0020.00517.88
8.1.120.0000.00717.50
8.1.110.0040.00417.62
8.1.100.0070.00017.64
8.1.90.0040.00417.49
8.1.80.0080.00017.57
8.1.70.0030.00517.55
8.1.60.0000.00817.59
8.1.50.0000.00817.71
8.1.40.0040.00417.66
8.1.30.0040.00417.83
8.1.20.0040.00417.67
8.1.10.0080.00017.64
8.1.00.0030.00517.67
8.0.300.0000.00718.77
8.0.290.0080.00016.88
8.0.280.0050.00318.58
8.0.270.0040.00417.31
8.0.260.0060.00017.49
8.0.250.0050.00317.13
8.0.240.0030.00317.12
8.0.230.0040.00417.12
8.0.220.0050.00217.10
8.0.210.0030.00417.15
8.0.200.0040.00417.13
8.0.190.0050.00317.14
8.0.180.0040.00417.00
8.0.170.0050.00317.17
8.0.160.0040.00416.98
8.0.150.0000.00716.86
8.0.140.0070.00016.93
8.0.130.0040.00413.47
8.0.120.0000.00917.05
8.0.110.0040.00417.05
8.0.100.0030.00517.14
8.0.90.0000.00816.95
8.0.80.0070.01017.09
8.0.70.0000.00817.11
8.0.60.0040.00417.10
8.0.50.0000.00817.08
8.0.30.0100.00917.28
8.0.20.0070.01117.40
8.0.10.0000.00817.01
8.0.00.0130.00616.89
7.4.330.0020.00216.77
7.4.320.0030.00316.63
7.4.300.0050.00316.64
7.4.290.0070.00316.73
7.4.280.0000.00916.64
7.4.270.0030.00516.63
7.4.260.0040.00416.74
7.4.250.0040.00416.50
7.4.240.0000.00716.69
7.4.230.0000.00816.81
7.4.220.0140.00316.83
7.4.210.0120.00316.79
7.4.200.0030.00316.66
7.4.160.0100.00716.79
7.4.150.0140.00317.40
7.4.140.0190.00317.86
7.4.130.0090.01216.65
7.4.120.0120.00916.57
7.4.110.0120.00816.69
7.4.100.0170.00616.57
7.4.90.0090.00916.76
7.4.80.0060.01219.39
7.4.70.0070.01016.86
7.4.60.0040.01316.75
7.4.50.0060.00916.76
7.4.40.0100.01316.89
7.4.30.0070.01116.61
7.4.10.0070.01416.61
7.4.00.0060.01015.53
7.3.330.0060.00013.31
7.3.320.0050.00213.20
7.3.310.0030.00516.47
7.3.300.0080.00016.39
7.3.290.0080.01116.41
7.3.280.0100.00916.38
7.3.270.0130.00317.40
7.3.260.0070.01016.30
7.3.240.0100.00716.40
7.3.230.0140.00316.49
7.3.210.0070.01116.27
7.3.200.0080.01119.39
7.3.190.0130.00316.59
7.3.180.0100.00716.54
7.3.170.0090.00916.45
7.3.160.0120.00416.22
7.3.130.0060.01316.34
7.3.120.0080.01115.57
7.3.110.0050.01115.67
7.3.100.0050.01015.61
7.3.90.0050.00915.75
7.3.80.0070.01015.73
7.3.70.0050.00815.73
7.3.60.0010.01015.61
7.3.50.0050.00915.39
7.3.40.0090.00715.59
7.3.30.0050.01215.54
7.3.20.0040.01017.24
7.3.10.0060.00717.33
7.3.00.0080.00517.32
7.2.330.0120.00916.93
7.2.320.0130.00616.81
7.2.310.0060.01616.70
7.2.300.0090.01216.68
7.2.290.0090.01516.75
7.2.260.0000.02016.84
7.2.250.0110.00815.99
7.2.240.0080.00915.74
7.2.230.0030.01215.85
7.2.220.0060.00615.91
7.2.210.0060.00815.80
7.2.200.0090.00215.74
7.2.190.0080.00615.82
7.2.180.0050.01215.83
7.2.170.0040.00915.75
7.2.160.0070.00716.54
7.2.150.0110.00418.43
7.2.140.0040.01118.30
7.2.130.0070.01018.25
7.2.120.0060.00918.39
7.2.110.0070.00718.15
7.2.100.0030.00918.40
7.2.90.0000.01318.15
7.2.80.0070.00718.28
7.2.70.0070.00418.32
7.2.60.0060.00917.52
7.2.50.0000.01118.32
7.2.40.0120.00618.34
7.2.30.0040.01118.43
7.2.20.0090.00618.39
7.2.10.0060.00618.34
7.2.00.0060.00818.80
7.1.330.0030.01216.62
7.1.320.0080.00716.40
7.1.310.0110.00516.56
7.1.300.0100.00316.41
7.1.290.0060.00916.25
7.1.280.0090.00516.37
7.1.270.0040.00916.57
7.1.260.0060.00616.43
7.1.250.0070.00317.04
7.1.240.0060.01017.12
7.1.230.0060.00617.26
7.1.220.0070.00317.10
7.1.210.0100.00317.16
7.1.200.0030.00816.41
7.1.190.0100.00017.03
7.1.180.0100.00716.93
7.1.170.0110.00717.15
7.1.160.0070.01017.28
7.1.150.0080.00517.19
7.1.140.0080.00417.08
7.1.130.0030.01117.23
7.1.120.0040.01117.13
7.1.110.0060.00917.29
7.1.100.0010.01017.52
7.1.90.0000.01417.34
7.1.80.0060.00917.26
7.1.70.0060.00617.04
7.1.60.0110.00818.11
7.1.50.0080.00617.05
7.1.40.0040.00817.23
7.1.30.0050.00817.02
7.1.20.0040.01217.25
7.1.10.0080.00417.27
7.1.00.0000.04519.72
7.0.330.0070.00416.86
7.0.320.0040.00716.82
7.0.310.0040.01116.98
7.0.300.0050.00516.88
7.0.290.0080.00817.04
7.0.280.0030.01016.81
7.0.270.0040.00716.77
7.0.260.0090.00916.68
7.0.250.0040.01116.86
7.0.240.0130.00316.96
7.0.230.0070.01116.80
7.0.220.0100.00716.82
7.0.210.0000.01516.90
7.0.200.0040.00816.69
7.0.190.0070.00417.04
7.0.180.0030.00816.89
7.0.170.0030.01016.77
7.0.160.0000.01416.77
7.0.150.0130.00316.73
7.0.140.0090.00316.80
7.0.130.0090.00317.07
7.0.120.0090.00616.94
7.0.110.0030.01016.89
7.0.100.0090.00616.85
7.0.90.0070.00716.83
7.0.80.0080.00416.75
7.0.70.0040.01116.63
7.0.60.0080.02719.38
7.0.50.0080.02517.42
7.0.40.0050.02617.54
7.0.30.0140.02417.38
7.0.20.0130.02317.42
7.0.10.0030.03717.45
7.0.00.0020.02717.63
5.6.400.0070.01016.02
5.6.390.0060.00616.00
5.6.380.0120.00315.97
5.6.370.0070.00715.88
5.6.360.0060.01015.87
5.6.350.0070.01015.95
5.6.340.0070.00715.96
5.6.330.0000.01515.77
5.6.320.0040.01516.04
5.6.310.0110.00415.88
5.6.300.0120.00315.85
5.6.290.0030.01015.94
5.6.280.0100.02718.54
5.6.270.0060.01015.89
5.6.260.0060.00615.99
5.6.250.0060.00915.88
5.6.240.0000.01216.02
5.6.230.0080.00415.93
5.6.220.0040.01115.93
5.6.210.0100.02218.24
5.6.200.0080.04017.15
5.6.190.0080.03018.04
5.6.180.0320.03618.10
5.6.170.0200.04018.14
5.6.160.0070.02918.24
5.6.150.0000.05117.04
5.6.140.0100.01817.08
5.6.130.0070.03017.01
5.6.120.0050.02518.57
5.6.110.0070.03718.42
5.6.100.0070.02218.45
5.6.90.0100.04418.33
5.6.80.0050.04718.14
5.6.70.0000.01415.71
5.6.60.0040.00815.89
5.6.50.0080.00415.63
5.6.40.0070.00315.99
5.6.30.0070.01015.73
5.6.20.0030.01315.84
5.6.10.0030.00615.69
5.6.00.0030.00715.68
5.5.380.0120.00415.73
5.5.370.0000.01415.70
5.5.360.0060.00615.75
5.5.350.0050.02918.01
5.5.340.0030.03717.00
5.5.330.0070.04717.93
5.5.320.0330.03717.92
5.5.310.0190.04418.24
5.5.300.0000.04316.90
5.5.290.0080.04316.92
5.5.280.0040.02918.46
5.5.270.0050.04718.11
5.5.260.0070.04618.33
5.5.250.0090.04218.23
5.5.240.0030.03817.94
5.5.230.0000.01515.73
5.5.220.0040.01115.71
5.5.210.0040.00715.79
5.5.200.0000.01315.95
5.5.190.0050.00515.43
5.5.180.0000.01415.83
5.5.170.0060.00615.78
5.5.160.0060.00915.70
5.5.150.0080.00415.78
5.5.140.0040.01115.74
5.5.130.0030.01415.70
5.5.120.0090.00915.56
5.5.110.0030.01715.64
5.5.100.0100.00715.16
5.5.90.0070.01415.60
5.5.80.0060.00915.89
5.5.70.0060.01315.75
5.5.60.0130.00715.59
5.5.50.0100.01015.55
5.5.40.0090.00615.68
5.5.30.0080.00815.80
5.5.20.0070.01015.59
5.5.10.0030.01315.66
5.5.00.0040.00815.72

preferences:
60.41 ms | 401 KiB | 5 Q