Coder Social home page Coder Social logo

ffi-sdl-image's Introduction

FFI SDL Image Bindings

PHP 8.1+ SDL_image Latest Stable Version Latest Unstable Version Total Downloads License MIT

A SDL_image extension FFI bindings for the PHP language compatible with SDL FFI bindings for the PHP language.

Requirements

  • PHP ^8.1
  • ext-ffi
  • Windows, Linux, BSD or MacOS
    • Android, iOS or something else are not supported yet
  • SDL and SDL Image >= 2.0

Installation

Library is available as composer repository and can be installed using the following command in a root of your project.

$ composer require serafim/ffi-sdl-image

Additional dependencies:

  • Debian-based Linux: sudo apt install libsdl2-image-2.0-0 -y
  • MacOS: brew install sdl2_image
  • Window: Can be downloaded from here

Documentation

The library API completely supports and repeats the analogue in the C language.

Initialization

In the case that you need a specific SDL instance, it should be passed explicitly:

$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);

! It is recommended to always specify the SDL dependency explicitly.

To specify a library pathname explicitly, you can add the library argument to the Serafim\SDL\Image\Image constructor.

By default, the library will try to resolve the binary's pathname automatically.

// 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);

You can also specify the library version explicitly. Depending on this version, the corresponding functions of the SDL Image will be available.

By default, the library will try to resolve SDL Image version automatically.

// 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);

To speed up the header compiler, you can use any PSR-16 compatible cache driver.

$image = new Serafim\SDL\Image\Image(cache: new Psr16Cache(...));

In addition, you can control other preprocessor directives explicitly:

$pre = new \FFI\Preprocessor\Preprocessor();
$pre->define('true', 'false'); // happy debugging!

$image = new Serafim\SDL\Image\Image(pre: $pre);

Example

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();

ffi-sdl-image's People

Contributors

serafimarts avatar

Watchers

 avatar  avatar  avatar

ffi-sdl-image's Issues

Add library versions support

PHP Fatal error: Uncaught FFI\Exception: Failed resolving C function 'IMG_isSVG' in /mnt/Development/opengl-demo/vendor/serafim/ffi-sdl/src/Loader/LibraryLoader.php:82

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.