01 #!/usr/local/bin/perl -w 02 use strict; 03 use Thrift::Socket; 04 use Thrift::Server; 05 06 use lib 'gen-perl'; 07 use image_process::Rotator; 08 09 ########################################### 10 package RotateHandler; 11 ########################################### 12 use base qw(image_process::RotatorIf); 13 use Sysadm::Install qw(slurp blurt tap); 14 use File::Temp qw(tempfile); 15 16 ########################################### 17 sub new { 18 ########################################### 19 my( $class ) = @_; 20 21 return bless {}, $class; 22 } 23 24 ########################################### 25 sub rotate { 26 ########################################### 27 my ( $self, $rotation ) = @_; 28 29 my ( $fh1, $infile ) = 30 tempfile( UNLINK => 1 ); 31 my ( $fh2, $outfile ) = 32 tempfile( UNLINK => 1 ); 33 34 blurt $rotation->{image}, $infile; 35 my ( $stdout, $stderr, $rc ) = 36 tap "convert", "-rotate", 37 $rotation->{angle}, $infile, $outfile; 38 39 if ( $rc != 0 ) { 40 my $x = image_process::Failed->new(); 41 $x->why($stderr); 42 die $x; 43 } 44 45 return slurp $outfile; 46 } 47 48 ########################################### 49 package main; 50 ########################################### 51 use Log::Log4perl qw(:easy); 52 Log::Log4perl->easy_init($DEBUG); 53 54 my $port = 9001; 55 my $handler = RotateHandler->new(); 56 my $processor = 57 image_process::RotatorProcessor->new( 58 $handler); 59 my $serversocket = 60 Thrift::ServerSocket->new($port); 61 my $forkingserver = 62 Thrift::ForkingServer->new( $processor, 63 $serversocket ); 64 65 DEBUG "Server starting on port $port"; 66 $forkingserver->serve();