ecourtial / php-bmp-parser
解析 Windows 位图文件的库
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: 2024-09-06 14:48:17 UTC
README
描述
- 这个小型库允许您解析标准的 Windows BMP 文件(通用信息和逐像素)。
- 不需要第三方库。它只基于原生的 PHP 函数。
- 它还提供了一个基本的功能来编辑现有的 BMP 文件(为此功能您需要 gd PHP 扩展)。
限制
到目前为止,这个库只能处理以下文件
- 24 位(真彩色)
- 8 位(256 种颜色)带调色板
- 4 位(16 种颜色)带调色板
另一个限制,在编辑时:当前版本的库只允许编辑 24 位文件。
安装
composer require ecourtial/php-bmp-parser
使用
$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);