blib/lib/Apache/GD/Thumbnail.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Apache::GD::Thumbnail;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use GD;
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Image::GD::Thumbnail;
8 use Apache::File;
9 use Apache::Constants qw(OK NOT_FOUND);
10  
11 BEGIN {
12 $VERSION = "0.03";
13 $Apache::GD::Thumbnail::DEBUG=0;
14 }
15  
16 ### ChangeLog
17 #
18 # 0.01 - Jan 21, 2002 - Started
19 # 0.02 - Jan 22, 2002 - Removed some debug code that shouldn't have been there
20  
21 sub handler
22 {
23 my $r=shift;
24 # Read config
25 my $uri=$r->path_info;
26 my $base=$r->dir_config("ThumbnailBaseDir") || "0";
27 if ($base eq "0") {
28 my $subr=$r->lookup_uri($r->uri."/../../");
29 $base=$subr->filename;
30 }
31 $base=~s/\/$//;
32 my $loc=$base.$uri;
33 my $MaxSize=$r->dir_config("ThumbnailMaxSize") || 50;
34 # Verify file
35 if (!(-e $loc)) {
36 return NOT_FOUND;
37 }
38 # Prepare response
39 $r->set_last_modified((stat $loc)[9]);
40 $r->content_type('image/jpeg');
41 if ((my $rc=$r->meets_conditions) != OK) {
42 return $rc;
43 }
44 $r->send_http_header;
45 if ($r->header_only)
46 {
47 return OK;
48 }
49 # Read JPEG
50 my $fh=Apache::File->new($loc) || die ("Couldn't open $loc for reading: $!");
51 my $src=undef;
52 $src=GD::Image->newFromJpeg(*{$fh});
53 $fh->close || die "Error closing $loc: $!";
54 warn $loc if _conf("DEBUG") > 0;
55 #Create thumbnail
56 my ($thumb,$x,$y)=Image::GD::Thumbnail::create($src,$MaxSize);
57 $r->print($thumb->jpeg);
58 return OK;
59 }
60  
61 sub _conf($)
62 {
63 my $arg=shift;
64 return eval("\$".__PACKAGE__."::".$arg);
65 }
66  
67  
68 1;
69  
70 __END__
↑ Summary