PHP code example of starcitizentools / thumbro
1. Go to this page and download the library: Download starcitizentools/thumbro 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/ */
starcitizentools / thumbro example snippets
wfLoadExtension( 'Thumbro' );
$wgThumbroLibraries = [
'libvips' => [ 'vipsthumbnail' => '/usr/bin/vipsthumbnail' ], // resize (+ vips-webp encode)
'libwebp' => [
'gif2webp' => '/usr/bin/gif2webp', // animated-GIF encode
'cwebp' => '/usr/bin/cwebp', // static-WebP encode
],
];
$wgThumbroOptions = [
// Static WebP → cwebp (smaller); animated WebP → vips; vips catch-all if cwebp is absent.
'image/webp' => [
'enabled' => true,
'resize' => [ 'options' => [] ],
'encode' => [
[ 'encoder' => 'vips-webp', 'when' => [ 'animated' => true ],
'options' => [ 'strip' => 'true', 'Q' => '90', 'smart_subsample' => 'true' ] ],
[ 'encoder' => 'cwebp', 'options' => [ 'q' => '80', 'm' => '6' ] ],
[ 'encoder' => 'vips-webp',
'options' => [ 'strip' => 'true', 'Q' => '90', 'smart_subsample' => 'true' ] ],
],
],
'image/jpeg' => [
'enabled' => true,
'resize' => [ 'options' => [] ],
'encode' => [ [ 'encoder' => 'vips-webp',
'options' => [ 'strip' => 'true', 'Q' => '80', 'smart_subsample' => 'false', 'effort' => '6' ] ] ],
],
'image/png' => [
'enabled' => true,
'resize' => [ 'options' => [] ],
'encode' => [ [ 'encoder' => 'vips-webp',
'options' => [ 'near_lossless' => 'true', 'Q' => '60', 'strip' => 'true' ] ] ],
],
// GIF: transparent animation → gif2webp; opaque animation → vips animated; else vips first-frame.
'image/gif' => [
'enabled' => true,
'resize' => [ 'options' => [] ],
'encode' => [
[ 'encoder' => 'gif2webp', 'when' => [ 'animated' => true, 'alpha' => true, 'underThreshold' => true ],
'options' => [ 'mixed' => '', 'q' => '80', 'm' => '4' ] ],
[ 'encoder' => 'vips-webp', 'when' => [ 'animated' => true, 'underThreshold' => true ],
'options' => [ 'strip' => 'true', 'Q' => '90', 'smart_subsample' => 'true' ] ],
[ 'encoder' => 'vips-webp',
'options' => [ 'strip' => 'true', 'Q' => '90', 'smart_subsample' => 'true' ] ],
],
],
];
// Enable the Special:ThumbroTest page
$wgThumbroExposeTestPage = true;
// Disable Thumbro site-wide
$wgThumbroEnabled = false;