Skip to content

Instantly share code, notes, and snippets.

@benharri
Last active January 2, 2018 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benharri/ee3417390fe740b42f8e4ef87d440eef to your computer and use it in GitHub Desktop.
Save benharri/ee3417390fe740b42f8e4ef87d440eef to your computer and use it in GitHub Desktop.
generate thumbnails for h5ai
#!/usr/bin/env php
<?php
require_once __DIR__ . '/_h5ai/private/php/class-bootstrap.php';
//Dummy parameters
$_SERVER['REQUEST_METHOD'] = 'get';
$_SERVER['SCRIPT_NAME'] = __DIR__.'/'.__DIR__.'/';
$_SERVER['SERVER_SOFTWARE'] = 'apache';
$_SERVER['HTTP_USER_AGENT'] = 'mozilla';
spl_autoload_register(['Bootstrap', 'autoload']);
$session = new Session($_SESSION);
$request = new Request($_REQUEST, file_get_contents('php://input'));
$setup = new Setup($request->query_boolean('refresh', false));
$context = new Context($session, $request, $setup);
$thumb = new Thumb($context);
// __DIR__ - which directory to scan for images
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__));
$it->rewind();
while($it->valid()) {
if (!$it->isDot()
&& $it->isFile()
&& strpos($it->getBasename(), 'thumb-') !== 0
&& in_array($it->getExtension(), ['jpg', 'png', 'jpeg'])
) {
printf("Generating thumb for: %s\n\n", $it->key());
printf("Generated 320x240: %s\n\n", $thumb->thumb('img', $it->key(), 320, 240));
printf("Generated 240x240: %s\n\n", $thumb->thumb('img', $it->key(), 240, 240));
echo "----------------------------\r\n";
}
$it->next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment