3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pixelDataArray = array( "11101010111", "10101010101", "11101110111", "10001010100", "10001010100", ); //First to convert the input into a pixel array or bitmap data, each line on the pixel array should be dword/32bit/4bytes aligned. $pixelWidth = strlen($pixelDataArray[0]); $pixelHeight = count($pixelDataArray); $dwordAlignment = 32 - ($pixelWidth % 32); if ($dwordAlignment == 32) { $dwordAlignment = 0; } $dwordAlignedLength = $pixelWidth + $dwordAlignment; //Now we can proper align the string then convert it to a array of 1 byte integers and after to a binary string. $pixelArray = ''; foreach (array_reverse($pixelDataArray) as $row) { $dwordAlignedPixelRow = str_pad($row, $dwordAlignedLength, '0', STR_PAD_RIGHT); $integerPixelRow = array_map('bindec', str_split($dwordAlignedPixelRow, 8)); $pixelArray .= implode('', array_map('chr', $integerPixelRow)); } $pixelArraySize = \strlen($pixelArray); //Then lets build the color table $colorTable = pack( 'CCCxCCCx', //blue, green, red 255, 255, 255, // 0 color 0, 0, 0 // 1 color ); $colorTableSize = \strlen($colorTable); //Now the bitmap information header, for better support BITMAPINFOHEADER (40 bytes header) will be used. $dibHeaderSize = 40; $colorPlanes = 1; $bitPerPixel = 1; $compressionMethod = 0; //BI_RGB/NONE $horizontal_pixel_per_meter = 2835; $vertical_pixel_per_meter = 2835; $colorInPalette = 2; $importantColors = 0; $dibHeader = \pack('VVVvvVVVVVV', $dibHeaderSize, $pixelWidth, $pixelHeight, $colorPlanes, $bitPerPixel, $compressionMethod, $pixelArraySize, $horizontal_pixel_per_meter, $vertical_pixel_per_meter, $colorInPalette, $importantColors); //The last part is the file header $bmpFileHeaderSize = 14; $pixelArrayOffset = $bmpFileHeaderSize + $dibHeaderSize + $colorTableSize; $fileSize = $pixelArrayOffset + $pixelArraySize; $bmpFileHeader = pack('CCVxxxxV', \ord('B'), \ord('M'), $fileSize, $pixelArrayOffset); //Then just concat all into a single string $bmpFile = $bmpFileHeader . $dibHeader . $colorTable . $pixelArray; $bmpBase64File = base64_encode($bmpFile); ?> <img src="data:image/bitmap;base64, <?= $bmpBase64File ?>" style="image-rendering: crisp-edges;width: 100px;height: ;"/>

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.70.0100.01016.58
8.3.60.0130.01018.43
8.3.50.0100.01016.45
8.3.40.0140.00718.98
8.3.30.0060.01318.75
8.3.20.0050.00224.18
8.3.10.0040.00424.66
8.3.00.0050.00326.16
8.2.190.0150.00616.58
8.2.180.0070.00725.92
8.2.170.0100.01022.96
8.2.160.0070.00722.96
8.2.150.0080.00025.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00426.35
8.2.110.0050.00522.26
8.2.100.0090.00617.72
8.2.90.0060.00317.75
8.2.80.0040.00418.77
8.2.70.0030.00517.93
8.2.60.0040.00418.22
8.2.50.0050.00318.10
8.2.40.0050.00321.14
8.2.30.0030.00519.36
8.2.20.0040.00418.13
8.2.10.0040.00419.21
8.2.00.0000.00819.38
8.1.280.0070.01425.92
8.1.270.0060.00323.99
8.1.260.0040.00428.09
8.1.250.0080.00028.09
8.1.240.0110.00023.91
8.1.230.0080.00321.04
8.1.220.0050.00317.76
8.1.210.0050.00518.77
8.1.200.0040.00417.36
8.1.190.0030.00617.36
8.1.180.0000.00818.10
8.1.170.0040.00418.50
8.1.160.0040.00418.90
8.1.150.0060.00318.83
8.1.140.0000.00818.99
8.1.130.0020.00520.06
8.1.120.0100.00017.38
8.1.110.0000.00917.46
8.1.100.0000.00817.37
8.1.90.0040.00417.43
8.1.80.0000.00817.36
8.1.70.0040.00417.51
8.1.60.0000.00817.55
8.1.50.0000.00817.52
8.1.40.0040.00417.44
8.1.30.0060.00317.62
8.1.20.0000.01017.68
8.1.10.0040.00417.63
8.1.00.0050.00317.41
8.0.300.0040.00418.77
8.0.290.0030.00616.75
8.0.280.0080.00018.45
8.0.270.0050.00216.91
8.0.260.0000.00718.51
8.0.250.0040.00417.01
8.0.240.0000.00716.95
8.0.230.0070.00016.96
8.0.220.0000.00716.90
8.0.210.0030.00316.92
8.0.200.0000.00716.85
8.0.190.0070.00016.99
8.0.180.0030.00516.93
8.0.170.0050.00316.82
8.0.160.0000.00716.89
8.0.150.0000.00716.86
8.0.140.0040.00416.89
8.0.130.0050.00013.30
8.0.120.0030.00516.74
8.0.110.0030.00517.02
8.0.100.0000.00816.77
8.0.90.0040.00416.81
8.0.80.0100.00816.85
8.0.70.0050.00316.82
8.0.60.0040.00416.86
8.0.50.0070.00016.94
8.0.30.0100.00616.89
8.0.20.0110.00716.93
8.0.10.0210.00417.20
8.0.00.0130.00616.82
7.4.330.0000.00515.55
7.4.320.0000.00716.63
7.4.300.0070.00016.59
7.4.290.0040.00416.56
7.4.280.0080.00016.50
7.4.270.0050.00216.50
7.4.260.0070.00016.65
7.4.250.0070.00016.59
7.4.240.0030.00316.67
7.4.230.0000.00716.62
7.4.220.0040.00416.61
7.4.210.0110.00416.61
7.4.200.0030.00316.40
7.4.140.0100.01016.46
7.4.130.0200.00016.34
7.4.120.0100.01316.44
7.4.110.0130.01316.26
7.4.100.0090.01316.22
7.4.90.0130.00716.39
7.4.80.0150.00916.44
7.4.70.0180.00616.41
7.4.60.0090.01216.50
7.4.50.0150.01216.52
7.4.40.0170.00316.45
7.4.30.0110.01016.43
7.4.20.0130.01015.89
7.4.10.0100.01016.22
7.4.00.0070.01315.89
7.3.330.0030.00316.31
7.3.320.0060.00013.20
7.3.310.0050.00316.35
7.3.300.0000.00716.30
7.3.290.0080.00616.31
7.3.260.0120.00916.43
7.3.250.0040.01616.30
7.3.240.0160.00916.22
7.3.230.0150.00916.27
7.3.220.0150.00316.18
7.3.210.0070.01716.37
7.3.200.0130.00616.36
7.3.190.0130.00716.58
7.3.180.0160.00316.24
7.3.170.0030.01616.35
7.3.160.0070.01516.38
7.3.150.0120.01016.28
7.3.140.0100.00716.14
7.3.130.0040.01316.25
7.3.120.0130.00716.21
7.3.110.0090.00915.94
7.3.100.0130.00616.38
7.3.90.0150.00616.28
7.3.80.0090.00916.51
7.3.70.0080.01216.21
7.3.60.0100.01016.20
7.3.50.0120.00916.27
7.3.40.0090.01316.27
7.3.30.0100.01016.20
7.3.20.0090.00916.27
7.3.10.0060.01416.45
7.3.00.0120.00916.16

preferences:
64.13 ms | 401 KiB | 5 Q