Files
archived-pecl-networking-ge…/examples/image_thumbnail_worker.php
jluedke 2a12523919 - Fixed build issue with 5.1.x
Merged eday changes
    - Added wait functions, uncommented other worker functions.
    - Added timeout functions.
    - Updated function list from C library and removed free methods 
      (should use unset).
    - Added stubs for new functions, fixed tests, fixed some of the 
      existing functions from changes.
2009-10-01 08:03:18 +00:00

56 lines
1.3 KiB
PHP

<?php
/*
* Gearman PHP Extension
*
* Copyright (C) 2008 James M. Luedke (jluedke@jamesluedke.com)
* Eric Day (eday@oddments.org)
* All rights reserved.
*
* Use and distribution licensed under the PHP license. See
* the LICENSE file in this directory for full text.
*/
echo "Starting Thumbnail creator\n";
$gmw= new GearmanWorker();
$gmw->addServer();
# optional config paramsj
$args;
$gmw->addFunction("shrink_image", "resize_image", $args);
while($gmw->work())
{
switch ($gmw->returnCode())
{
case GEARMAN_SUCCESS:
break;
default:
echo "ERROR RET: " . $gmc->returnCode() . "\n";
exit;
}
}
echo "DONE\n";
/* simple function to resize an image
* Requires the Imagick extension */
function resize_image($job, $args)
{
$wrk= $job->workload();
$data= unserialize($wrk);
if (! $data['src'] || ! $data['dest'] || ! $data['x'])
{ $job->sendFail(); print_r($data); return; }
echo $job->handle() . " - creating: $data[dest] x:$data[x] y:$data[y]\n";
$im= new Imagick();
$im->readimage($data['src']);
$im->thumbnailImage($data['x'], $data['y']);
$im->writeImage($data['dest']);
$im->destroy();
$job->sendStatus(1, 1);
return $data['dest'];
}
?>