Quickstart — PHP
composer require dusmamud/dusimagezRequires PHP 8.1+ with the FFI extension enabled.
The prebuilt library step — read this first
Section titled “The prebuilt library step — read this first”Composer installs PHP code only; it cannot install the compiled Rust library the wrapper calls. Before using the package, build (or download) the shared library and point the wrapper at it:
# Build the C library from the repo (produces libdusimagez_ffi.so)cargo build -p dusimagez-ffi --release<?phpuse Dusrel\Dusimagez\Dusimagez;
// Point at the compiled library, then use it.$dz = new Dusimagez('/path/to/libdusimagez_ffi.so');There is no Composer-direct install of the Rust .so — any guide that
claims otherwise is wrong.
Compress
Section titled “Compress”<?php$input = file_get_contents('input.jpg');$output = $dz->compress($input, ['quality' => 80]);file_put_contents('output.jpg', $output);Compress to a target size
Section titled “Compress to a target size”<?php// 200 KB or less, or a DusimagezException with code TARGET_SIZE_UNREACHABLE.$output = $dz->compressToSize($input, 200_000, []);Report and info
Section titled “Report and info”<?php$info = $dz->getInfo($input);// $info['format'], $info['width'], $info['height']
$report = $dz->compressWithReport($input, ['preset' => 'Web']);// $report['original_size'], $report['output_size'],// $report['saved_percent'], $report['quality_used'], $report['resized']<?php$results = $dz->bulkCompress([$data1, $data2, ''], []);foreach ($results as $r) { if ($r['ok']) { // $r['report']['saved_bytes'] } else { // per-item error: $r['error']['code'], $r['error']['message_en'] }}Errors
Section titled “Errors”Failures throw DusimagezException with ->code, ->messageEn and
->messageHi — see Error codes for all 9 codes.
Full option list: Options reference.