ecourtial / php-bmp-parser
A library to parse Windows Bitmap files
0.2.1
2022-03-06 09:37 UTC
Requires
- php: >=7.4
Requires (Dev)
- infection/infection: ^0.21.0
- ondram/ci-detector: ^3.5
- phpstan/phpstan: ^0.12
- phpstan/phpstan-deprecation-rules: ^0.12.6
- phpstan/phpstan-phpunit: ^0.12.17
- phpstan/phpstan-strict-rules: ^0.12.9
- phpunit/phpunit: ^9.5
- wizaplace/phpcs: ^1.3
This package is auto-updated.
Last update: 2025-03-06 15:47:55 UTC
README
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);