image_thumbnail_worker.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * Gearman PHP Extension
  4. *
  5. * Copyright (C) 2008 James M. Luedke (jluedke@jamesluedke.com)
  6. * Eric Day (eday@oddments.org)
  7. * All rights reserved.
  8. *
  9. * Use and distribution licensed under the PHP license. See
  10. * the LICENSE file in this directory for full text.
  11. */
  12. echo "Starting Thumbnail creator\n";
  13. $gmw= new GearmanWorker();
  14. $gmw->addServer();
  15. # optional config paramsj
  16. $args;
  17. $gmw->addFunction("shrink_image", "resize_image", $args);
  18. while($gmw->work())
  19. {
  20. switch ($gmw->returnCode())
  21. {
  22. case GEARMAN_SUCCESS:
  23. break;
  24. default:
  25. echo "ERROR RET: " . $gmc->returnCode() . "\n";
  26. exit;
  27. }
  28. }
  29. echo "DONE\n";
  30. /* simple function to resize an image
  31. * Requires the Imagick extension */
  32. function resize_image($job, $args)
  33. {
  34. $wrk= $job->workload();
  35. $data= unserialize($wrk);
  36. if (! $data['src'] || ! $data['dest'] || ! $data['x'])
  37. { $job->sendFail(); print_r($data); return; }
  38. echo $job->handle() . " - creating: $data[dest] x:$data[x] y:$data[y]\n";
  39. $im= new Imagick();
  40. $im->readimage($data['src']);
  41. $im->thumbnailImage($data['x'], $data['y']);
  42. $im->writeImage($data['dest']);
  43. $im->destroy();
  44. $job->sendStatus(1, 1);
  45. return $data['dest'];
  46. }
  47. ?>