ecourtial/php-bmp-parser

A library to parse Windows Bitmap files

0.2.1 2022-03-06 09:37 UTC

This package is auto-updated.

Last update: 2024-05-06 14:12:02 UTC


README

CircleCI Version codecov Infection MSI Maintenance Ask Me Anything ! GitHub license PHP Version

Description

  • This small library allows you to parse a standard Windows BMP file (generic information + pixel by pixel).
  • No third party libraries required. It is only based on native PHP functions.
  • It also provides a basic feature to edit an existing BMP file (for this feature you will need the gd PHP extension).

Limitations

So far the library only handles the following files:

  • 24 bits (true colors)
  • 8 bits (256 colors) with palette
  • 4 bits (16 colors) with palette

Another limitation, when editing: the current version of the library only allows editing 24 bits files.

Installation

composer require ecourtial/php-bmp-parser

Utilization

$service = new BmpService();
$image = $service->getImage('myBmpFile.bmp');

// Get a pixel object, with specific coordinates. I am able to check the RGB and hex values.
$image->getPixel(2, 0);

// Now I want to edit the file and change the path to not alter the original one
$image->setPath('myNewBmpFile.bmp);

// Change the color of one specific pixel
$image->getPixel(0, 1)->setR(0)->setG(0)->setB(126);

// Change the size of the image (extra pixels filled with white).
$image->setDimensions(3, 4);

// Change the color of some pixels added because we increased the width.
$image->getPixel(0, 3)->setR(200)->setG(0)->setB(200);
$image->getPixel(1, 3)->setR(0)->setG(0)->setB(255);

// The image object is reloaded on update
$image = $service->update($image);