1. Go to this page and download the library: Download mkcg/qoi-php 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/ */
mkcg / qoi-php example snippets
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);
}
}
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);
}
}
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);
}