File: image_thumbnail_worker.php

package info (click to toggle)
php-gearman 2.0.2%2B1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 868 kB
  • ctags: 723
  • sloc: ansic: 7,092; php: 826; xml: 570; sh: 32; makefile: 1
file content (55 lines) | stat: -rw-r--r-- 1,293 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?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'];
}
?>