01 #!/usr/local/bin/perl -w 02 use strict; 03 use Sysadm::Install qw(slurp blurt); 04 use Thrift; 05 use Thrift::BinaryProtocol; 06 use Thrift::Socket; 07 use Thrift::BufferedTransport; 08 09 use lib 'gen-perl'; 10 use image_process::Rotator; 11 12 my $socket = 13 Thrift::Socket->new( "localhost", 9001 ); 14 15 my $transport = 16 Thrift::BufferedTransport->new( $socket, 17 1024, 1024 ); 18 19 my $protocol = 20 Thrift::BinaryProtocol->new($transport); 21 my $client = 22 image_process::RotatorClient->new( 23 $protocol); 24 25 my ($image) = @ARGV; 26 die "usage: $0 image" if !defined $image; 27 28 eval { 29 $transport->open(); 30 31 my $image_data = slurp $image; 32 33 my $action = 34 image_process::Rotation->new(); 35 $action->image($image_data); 36 $action->angle(90); 37 38 my $rotated_image_data = 39 $client->rotate($action); 40 41 blurt $rotated_image_data, 42 "rotated-$image"; 43 44 $transport->close(); 45 }; 46 47 if ($@ =~ m/image_process/ and 48 exists $@->{why}) { 49 die $@->{why}; 50 } elsif( $@ ) { 51 die $@; 52 }