SVN: toys/rsget.pl/RSGet: Captcha.pm CaptchaImage.pm

sparky sparky at pld-linux.org
Mon Nov 2 16:45:08 CET 2009


Author: sparky
Date: Mon Nov  2 16:45:08 2009
New Revision: 10926

Modified:
   toys/rsget.pl/RSGet/Captcha.pm
   toys/rsget.pl/RSGet/CaptchaImage.pm
Log:
- removed unused code
- require GD, instead of use


Modified: toys/rsget.pl/RSGet/Captcha.pm
==============================================================================
--- toys/rsget.pl/RSGet/Captcha.pm	(original)
+++ toys/rsget.pl/RSGet/Captcha.pm	Mon Nov  2 16:45:08 2009
@@ -76,9 +76,11 @@
 		if ( $@ ) {
 			warn "Captcha process problem: $@\n";
 		} else {
-			p "Captcha process returned: " . $text
+			p "Captcha process returned: " . ( defined $text ? $text : "undef" )
 				if verbose( 2 );
-			$text = undef unless $text =~ /^$check$/;
+			if ( defined $text ) {
+				$text = undef unless $text =~ /^$check$/;
+			}
 			return $self->solved_delay( $text );
 		}
 	}

Modified: toys/rsget.pl/RSGet/CaptchaImage.pm
==============================================================================
--- toys/rsget.pl/RSGet/CaptchaImage.pm	(original)
+++ toys/rsget.pl/RSGet/CaptchaImage.pm	Mon Nov  2 16:45:08 2009
@@ -7,8 +7,6 @@
 
 use strict;
 use warnings;
-use GD;
-use Math::Trig;
 use RSGet::Tools;
 set_rev qq$Id$;
 
@@ -18,6 +16,7 @@
 	my $class = shift;
 	my $imgdata = shift;
 
+	require GD;
 	GD::Image->trueColor( 1 );
 	my $img = GD::Image->new( $$imgdata );
 
@@ -256,36 +255,6 @@
 	return @parts;
 } # }}}
 
-sub img_rotate # {{{
-{
-=later
-	my $self = shift;
-	my $opts = shift;
-
-	my $select = $opts->{select} || 0;
-	$select = [ $select ] unless ref $select;
-
-	my $angle = $opts->{angle};
-	$angle = [ -$angle, +$angle ] unless ref $angle;
-
-	foreach my $i ( @$select ) {
-		my $img = $self->[ $i ];
-		my $best;
-		my $max = 0;
-		for ( my $a = $angle->[0]; $a <= $angle->[1]; $a += 15 ) {
-			my $r = $img->rotate( $a );
-			my $sum = $r->sum_columns( $opts->{sum} );
-			#print "Sum $i: $sum\n";
-			if ( $sum > $max ) {
-				$best = $r;
-				$max = $sum;
-			}
-		}
-		$self->add( $best );
-	}
-=cut
-} # }}}
-
 # call ocr program
 sub ocr # {{{
 {
@@ -301,12 +270,14 @@
 	
 	system "tesseract $bmp cap$rand 2>/dev/null";
 	
-	open my $f_in, "<", $txt;
-	my $text = <$f_in>;
-	close $f_in;
+	my $text;
+	if ( open my $f_in, "<", $txt ) {
+		$text = <$f_in>;
+		close $f_in;
+	}
 	unlink $bmp, $txt;
 
-	return undef unless $text;
+	return "" unless $text;
 	chomp $text;
 	return $text;
 } # }}}


More information about the pld-cvs-commit mailing list