PHPackages                             mkcg/qoi-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. mkcg/qoi-php

ActiveLibrary[Image &amp; Media](/categories/media)

mkcg/qoi-php
============

QOI image encoder and decoder written in pure PHP

1.2.1(4y ago)861[1 issues](https://github.com/MKCG/php-qoi/issues)MITPHPPHP ^8.1

Since Jan 1Pushed 4y ago2 watchersCompare

[ Source](https://github.com/MKCG/php-qoi)[ Packagist](https://packagist.org/packages/mkcg/qoi-php)[ RSS](/packages/mkcg-qoi-php/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (3)DependenciesVersions (6)Used By (0)

QOI encoder / decoder
=====================

[](#qoi-encoder--decoder)

QOI Image encoder and decoder written in pure PHP.

It can encode and decode a few megabytes per second with a small memory footprint.

On x86\_64 architectures, it will automatically use the [FFI extension](https://www.php.net/manual/en/book.ffi.php) to encode the file using the provided C library.

Usage
-----

[](#usage)

Convert a PNG file using a stream :
-----------------------------------

[](#convert-a-png-file-using-a-stream-)

```
use MKCG\Image\QOI\Codec;
use MKCG\Image\QOI\Driver\Dynamic;
use MKCG\Image\QOI\Writer\StreamWriter;

$inputFilepath  = "/foobar.png";
$outputFilepath = "/foobar.qoi";

$context = Dynamic::loadFromFile($inputFilepath);

if ($context) {
    $outputFile = fopen($outputFilepath, 'w');

    if ($outputFile) {
        $writer = new StreamWriter($outputFile);
        Codec::encode($context->iterator, $context->descriptor, $writer);
        fclose($outputFile);
    }
}
```

Convert a PNG file in-memory :
------------------------------

[](#convert-a-png-file-in-memory-)

```
use MKCG\Image\QOI\Codec;
use MKCG\Image\QOI\Driver\Dynamic;
use MKCG\Image\QOI\Writer\InMemoryWriterFactory;

$inputFilepath  = "/foobar.png";
$outputFilepath = "/foobar.qoi";

$context = Dynamic::loadFromFile($inputFilepath);

if ($context) {
    $outputFile = fopen($outputFilepath, 'w');

    if ($outputFile) {
        $writer = (new Writer\InMemoryWriterFactory)->createWriter($context->descriptor);
        Codec::encode($context->iterator, $context->descriptor, $writer);
        fwrite($outputFile, (string) $writer, $writer->countWritten());
        fclose($outputFile);
    }
}
```

Create an image from scratch :
------------------------------

[](#create-an-image-from-scratch-)

```
use MKCG\Image\QOI\Codec;
use MKCG\Image\QOI\Colorspace;
use MKCG\Image\QOI\Context;
use MKCG\Image\QOI\ImageDescriptor;
use MKCG\Image\QOI\Writer\StreamWriter;

$outputFilepath = "/white.qoi";

$width    = 800;
$height   = 600;
$channels = 3;

$context = new Context(
    new ImageDescriptor($width, $height, $channels, Colorspace::SRGB),
    (function() use ($width, $height, $channels) {
        $size = $width * $height * $channels;
        for ($i = 0; $i < $size; $i++) {
            yield [ 255, 255, 255, 255 ];
        }
    })(),
);

$outputFile = fopen($outputFilepath, 'w');

if ($outputFile) {
    $writer = new StreamWriter($outputFile);
    Codec::encode($context->iterator, $context->descriptor, $writer);
    fclose($outputFile);
}
```

### Decode a QOI image

[](#decode-a-qoi-image)

```
use MKCG\Image\QOI\Codec;

function createFileIterator($filepath): \Generator
{
    $bytes = file_get_contents($filepath);

    for ($i = 0; $i < strlen($bytes); $i++) {
        yield $bytes[$i];
    }
};

$filepath = "/input.qoi";

$reader = Codec::decode(createFileIterator($filepath));

$width    = $reader->descriptor->width;
$height   = $reader->descriptor->height;
$channels = $reader->descriptor->channels;

$pixels = iterator_to_array($reader->iterator);
```

### Convert a QOI image

[](#convert-a-qoi-image)

```
use MKCG\Image\QOI\Codec;
use MKCG\Image\QOI\Format;
use MKCG\Image\QOI\Driver\Dynamic;

function createFileIterator($filepath): \Generator
{
    $handler = fopen($filepath, 'r');

    while (($bytes = fread($handler, 8192)) !== false) {
        for ($i = 0; $i < strlen($bytes); $i++) {
            yield $bytes[$i];
        }
    }

    fclose($handler);
};

$filepath = "/input.qoi";

$reader = Codec::decode(createFileIterator($filepath));
Dynamic::convertInto($reader, "/output.png", Format::PNG);

// Important: you need to create another reader
$reader = Codec::decode(createFileIterator($filepath));
Dynamic::convertInto($reader, "/output.jpg", Format::JPG);
```

Drivers
-------

[](#drivers)

NameRequirementsDescriptionDynamicat least one of the extManipulates images using the appropriate PHP image extensionGdext-gdgd use only 7 bits for the alpha channel instead of 8Imagickext-imagickimagick must have been compiled against ImageMagick &gt;= 6.4.0Vipsext-vipsSupported images format
-----------------------

[](#supported-images-format)

Driver GdImage : png and jpeg only

Driver Imagick : any image format that can be loaded by \\Imagick

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

1632d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8983434?v=4)[Kevin Masseix](/maintainers/MKCG)[@MKCG](https://github.com/MKCG)

---

Top Contributors

[![MKCG](https://avatars.githubusercontent.com/u/8983434?v=4)](https://github.com/MKCG "MKCG (14 commits)")

---

Tags

imageencoderdecoderffiqoi

### Embed Badge

![Health badge](/badges/mkcg-qoi-php/health.svg)

```
[![Health](https://phpackages.com/badges/mkcg-qoi-php/health.svg)](https://phpackages.com/packages/mkcg-qoi-php)
```

###  Alternatives

[intervention/image

PHP Image Processing

14.3k203.8M2.5k](/packages/intervention-image)[league/glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.

2.6k52.6M137](/packages/league-glide)[liip/imagine-bundle

This bundle provides an image manipulation abstraction toolkit for Symfony-based projects.

1.7k39.4M238](/packages/liip-imagine-bundle)[spatie/image

Manipulate images with an expressive API

1.4k58.5M175](/packages/spatie-image)[intervention/image-laravel

Laravel Integration of Intervention Image

1558.1M159](/packages/intervention-image-laravel)[intervention/gif

PHP GIF Encoder/Decoder

6025.4M14](/packages/intervention-gif)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
