1. Go to this page and download the library: Download php-sdl/sdl3-image library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-sdl / sdl3-image example snippets
use Sdl3image\SDLImage\IMG;
$surface = IMG::IMGLoad(__DIR__ . '/assets/logo.png');
if (empty($surface)) {
fwrite(STDERR, "IMGLoad failed\n");
exit(1);
}
printf(
"Loaded image: %dx%d, pitch=%d, pixels=%d\n",
$surface['w'],
$surface['h'],
$surface['pitch'],
count($surface['pixels']['data'])
);
// Pass $surface['ptr'] into SDL3 renderer APIs from php-sdl/sdl3 as needed.
[
'ptr' => int, // SDL_Surface pointer
'flags' => int, // surface flags
'format' => int, // SDL pixel format enum
'w' => int, // width in pixels
'h' => int, // height in pixels
'pitch' => int, // bytes per row
'pixels' => [
'ptr' => int, // raw pixel buffer pointer
'data' => int[], // packed 32-bit pixels in row-major order
],
'refcount' => int,
]