Created
November 23, 2010 16:37
-
-
Save plu/712050 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Gearman::XS::Worker; | |
use Gearman::XS qw(:constants); | |
use Imager; | |
my $worker = Gearman::XS::Worker->new; | |
$worker->add_server( 'localhost', 4730 ); | |
$worker->add_function( "convert_to_jpeg", 0, \&convert_to_jpeg, {} ); | |
while (1) { | |
my $ret = $worker->work(); | |
if ( $ret != GEARMAN_SUCCESS ) { | |
printf( STDERR "%s\n", $worker->error() ); | |
} | |
} | |
sub convert_to_jpeg { | |
my ($job) = @_; | |
return _convert( $job->workload, 'jpeg' ); | |
} | |
sub _convert { | |
my ( $in_data, $format ) = @_; | |
my $img = Imager->new(); | |
my $out_data; | |
$img->read( data => $in_data ) or die; | |
$img->write( data => \$out_data, type => $format ) or die; | |
return $out_data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment