PHP code example of php-sdl / sdl3-image

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,
]

[
    'ptr'      => int,   // SDL_Texture pointer
    'format'   => int,   // SDL pixel format enum
    'w'        => int,   // texture width
    'h'        => int,   // texture height
    'refcount' => int,   // currently fixed to 1
]
bash
pie install php-sdl/sdl3
pie install php-sdl/sdl3-image
ini
; /etc/php/8.4/cli/conf.d/30-sdl3image.ini
extension=sdl3image.so