private static function loopThroughBodyAndCalculatePixels(BitmapBodyModel $bitmapBodyModel)
    {
        for ($i = 0; $i < $bitmapBodyModel->bodySize; $i += 3) {
            //    Calculate line-ending and padding
            if ($bitmapBodyModel->x >= $bitmapBodyModel->width) {
                //    If padding needed, ignore image-padding. Shift i to the ending of the current 32-bit-block
                if ($bitmapBodyModel->usePadding) {
                    $i += $bitmapBodyModel->width % 4;
                }
                //    Reset horizontal position
                $bitmapBodyModel->x = 0;
                //    Raise the height-position (bottom-up)
                $bitmapBodyModel->y++;
                //    Reached the image-height? Break the for-loop
                if ($bitmapBodyModel->y > $bitmapBodyModel->height) {
                    break;
                }
            }
            //    Calculation of the RGB-pixel (defined as BGR in image-data). Define $iPos as absolute position in the body
            $iPos = $i * 2;
            $r = hexdec($bitmapBodyModel->body[$iPos + 4] . $bitmapBodyModel->body[$iPos + 5]);
            $g = hexdec($bitmapBodyModel->body[$iPos + 2] . $bitmapBodyModel->body[$iPos + 3]);
            $b = hexdec($bitmapBodyModel->body[$iPos] . $bitmapBodyModel->body[$iPos + 1]);
            //    Calculate and draw the pixel
            $color = imagecolorallocate($bitmapBodyModel->image, (int)$r, (int)$g, (int)$b);
            imagesetpixel($bitmapBodyModel->image, $bitmapBodyModel->x, $bitmapBodyModel->height - $bitmapBodyModel->y, $color);
            //    Raise the horizontal position
            $bitmapBodyModel->x++;
        }
    }
private static function loopThroughBodyAndCalculatePixels(BitmapBodyModel $bitmapBodyModel)
    {
        for ($i = 0; $i < $bitmapBodyModel->bodySize; $i += 3) {
            //    Calculate line-ending and padding
            if ($bitmapBodyModel->x >= $bitmapBodyModel->width) {
                //    If padding needed, ignore image-padding. Shift i to the ending of the current 32-bit-block
                if ($bitmapBodyModel->usePadding) {
                    $i += $bitmapBodyModel->width % 4;
                }
                //    Reset horizontal position
                $bitmapBodyModel->x = 0;
                //    Raise the height-position (bottom-up)
                $bitmapBodyModel->y++;
                //    Reached the image-height? Break the for-loop
                if ($bitmapBodyModel->y > $bitmapBodyModel->height) {
                    break;
                }
            }
            //    Calculation of the RGB-pixel (defined as BGR in image-data). Define $iPos as absolute position in the body
            $iPos = $i * 2;
            $r = hexdec($bitmapBodyModel->body[$iPos + 4] . $bitmapBodyModel->body[$iPos + 5]);
            $g = hexdec($bitmapBodyModel->body[$iPos + 2] . $bitmapBodyModel->body[$iPos + 3]);
            $b = hexdec($bitmapBodyModel->body[$iPos] . $bitmapBodyModel->body[$iPos + 1]);
            //    Calculate and draw the pixel
            $color = imagecolorallocate($bitmapBodyModel->image, (int)$r, (int)$g, (int)$b);
            imagesetpixel($bitmapBodyModel->image, $bitmapBodyModel->x, $bitmapBodyModel->height - $bitmapBodyModel->y, $color);
            //    Raise the horizontal position
            $bitmapBodyModel->x++;
        }
    }
private static function loopThroughBodyAndCalculatePixels ( BitmapBodyModel $ bitmapBodyModel ) { for ( $ i = 0 ; $ i < $ bitmapBodyModel -> bodySize ; $ i += 3 ) { //    Calculate line-ending and padding if ( $ bitmapBodyModel -> x >= $ bitmapBodyModel -> width ) { //    If padding needed, ignore image-padding. Shift i to the ending of the current 32-bit-block if ( $ bitmapBodyModel -> usePadding ) { $ i += $ bitmapBodyModel -> width % 4 ; } //    Reset horizontal position $ bitmapBodyModel -> x = 0 ; //    Raise the height-position (bottom-up) $ bitmapBodyModel -> y ++ ; //    Reached the image-height? Break the for-loop if ( $ bitmapBodyModel -> y > $ bitmapBodyModel -> height ) { break ; } } //    Calculation of the RGB-pixel (defined as BGR in image-data). Define $iPos as absolute position in the body $ iPos = $ i * 2 ; $ r = hexdec ( $ bitmapBodyModel -> body [ $ iPos + 4 ] . $ bitmapBodyModel -> body [ $ iPos + 5 ] ) ; $ g = hexdec ( $ bitmapBodyModel -> body [ $ iPos + 2 ] . $ bitmapBodyModel -> body [ $ iPos + 3 ] ) ; $ b = hexdec ( $ bitmapBodyModel -> body [ $ iPos ] . $ bitmapBodyModel -> body [ $ iPos + 1 ] ) ; //    Calculate and draw the pixel $ color = imagecolorallocate ( $ bitmapBodyModel -> image , ( int ) $ r , ( int ) $ g , ( int ) $ b ) ; imagesetpixel ( $ bitmapBodyModel -> image , $ bitmapBodyModel -> x , $ bitmapBodyModel -> height - $ bitmapBodyModel -> y , $ color ) ; //    Raise the horizontal position $ bitmapBodyModel -> x ++ ; } }
Loop through the data in the body of the bitmap
file and calculate each individual pixel based on the
bytes

Using a for-loop with index-calculation instead of str_split to avoid large memory consumption
Calculate the next DWORD-position in the body

@param BitmapBodyModel $bitmapBodyModel
Loop through the data in the body of the bitmap file and calculate each individual pixel based on the bytes