code: public function processBitmapGd($image)
      {
          $width = imagesx($image);
          $height = imagesy($image);
  
          $data = pack('Vvvvv', 0x000c, $width, $height, 0x01, 0x18);
          for ($j = $height; --$j;) {
              for ($i = 0; $i < $width; ++$i) {
                  $color = imagecolorsforindex($image, imagecolorat($image, $i, $j));
                  foreach (['red', 'green', 'blue'] as $key) {
                      $color[$key] = $color[$key] + round((255 - $color[$key]) * $color['alpha'] / 127);
                  }
                  $data .= chr($color['blue']) . chr($color['green']) . chr($color['red']);
              }
              if (3 * $width % 4) {
                  $data .= str_repeat("\x00", 4 - 3 * $width % 4);
              }
          }
  
          return [$width, $height, strlen($data), $data];
      }
docs: Convert a GD-image into the internal format.
  
  @param resource $image The image to process
  
  @return array Array with data and properties of the bitmap