serafim / ffi-sdl-image
SDL Image FFI 绑定用于 PHP 语言
2.0.1
2023-08-28 00:15 UTC
Requires
- php: ^8.1
- ext-ffi: *
- ffi-headers/contracts: ^1.0
- ffi/env: ^1.0
- ffi/location: ^1.0
- ffi/preprocessor: ^0.2
- ffi/proxy: ^1.0
- ffi/work-directory: ^1.0
- psr/simple-cache: ^1.0|^2.0|^3.0
- serafim/ffi-sdl: ^2.0
Requires (Dev)
- ffi/ide-helper-generator: ^0.1|^1.0
- friendsofphp/php-cs-fixer: ^3.22
- phpunit/phpunit: ^10.3
- symfony/cache: ^5.4|^6.0
- vimeo/psalm: ^5.14
This package is auto-updated.
Last update: 2024-08-28 02:44:34 UTC
README
一个兼容 SDL FFI 绑定用于 PHP 语言 的 SDL_image 扩展 FFI 绑定。
需求
- PHP ^8.1
- ext-ffi
- Windows, Linux, BSD 或 MacOS
- Android, iOS 或其他设备目前不支持
- SDL 和 SDL Image >= 2.0
安装
库作为 composer 仓库可用,可以使用以下命令在项目根目录下安装。
$ composer require serafim/ffi-sdl-image
附加依赖
- 基于 Debian 的 Linux:
sudo apt install libsdl2-image-2.0-0 -y
- MacOS:
brew install sdl2_image
- Windows:可以 从这里下载
文档
库 API 完全支持并重复了 C 语言的类似功能。
初始化
如果需要特定的 SDL 实例,应显式传递
$sdl = new Serafim\SDL\SDL(version: '2.28.3'); $image = new Serafim\SDL\Image\Image(sdl: $sdl); // If no argument is passed, the latest initialized // version will be used. $image = new Serafim\SDL\Image\Image(sdl: null);
! 建议始终显式指定 SDL 依赖。
要显式指定库路径,可以将 library
参数添加到 Serafim\SDL\Image\Image
构造函数中。
默认情况下,库将尝试自动解析二进制文件的路径名称。
// Load library from pathname (it may be relative or part of system-dependent path) $image = new Serafim\SDL\Image\Image(library: __DIR__ . '/path/to/library.so'); // Try to automatically resolve library's pathname $image = new Serafim\SDL\Image\Image(library: null);
您也可以显式指定库版本。根据此版本,将可用相应的 SDL Image 函数。
默认情况下,库将尝试自动解析 SDL Image 版本。
// Use v2.0.5 from string $image = new Serafim\SDL\Image\Image(version: '2.0.5'); // Use v2.6.3 from predefined versions constant $image = new Serafim\SDL\Image\Image(version: \Serafim\SDL\Image\Version::V2_6_3); // Use latest supported version $image = new Serafim\SDL\Image\Image(version: \Serafim\SDL\Image\Version::LATEST);
为了加快头文件编译器,您可以使用任何 PSR-16 兼容的缓存驱动程序。
$image = new Serafim\SDL\Image\Image(cache: new Psr16Cache(...));
此外,您还可以显式控制其他预处理器指令。
$pre = new \FFI\Preprocessor\Preprocessor(); $pre->define('true', 'false'); // happy debugging! $image = new Serafim\SDL\Image\Image(pre: $pre);
示例
use Serafim\SDL\SDL; use Serafim\SDL\Image\Image; $sdl = new SDL(); $image = new Image(sdl: $sdl); $sdl->SDL_Init(SDL::SDL_INIT_EVERYTHING); $image->IMG_Init(Image::IMG_INIT_PNG); $surface = $image->IMG_Load(__DIR__ . '/path/to/image.png'); $image->IMG_SaveJPG($surface, __DIR__ . '/path/to/image.jpg', quality: 80); $image->IMG_Quit(); $sdl->SDL_Quit();