Repository navigation
Expand file tree
/
Copy pathWebGD.pm
More file actions
84 lines (59 loc) · 1.47 KB
/
Copy pathWebGD.pm
File metadata and controls
84 lines (59 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package WebGD;
use strict;
use warnings;
use GD;
use GD::Polyline;
use base qw( GD::Image );
use CGI;
use MIME::Base64;
use File::Temp qw( tempfile );
use Conf;
1;
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
if (-f $_[0] && $_[0] =~ /png$/) {
$self = $class->SUPER::newFromPng(@_);
}
if (-f $_[0] && ($_[0] =~ /jpg$/ || $_[0] =~ /jpeg$/)) {
$self = $class->SUPER::newFromJpeg(@_);
}
bless($self, $class);
return $self;
}
sub newFromPng {
my $class = shift;
# for now this only works on filepath
return undef unless(-f $_[0]);
my $self = $class->SUPER::newFromPng(@_);
bless($self, $class);
return $self;
}
sub newFromJpeg {
my $class = shift;
# for now this only works on filepath
return undef unless(-f $_[0]);
my $self = $class->SUPER::newFromJpeg(@_);
bless($self, $class);
return $self;
}
sub image_src {
my ($self) = @_;
my $cgi = new CGI;
my $image_link = "";
my $user_agent = $ENV{HTTP_USER_AGENT};
if ($user_agent =~ /MSIE/) {
$user_agent = 'IE';
}
if ($user_agent eq 'IE' || $Conf::file_images_only) {
my ($fh, $filename) = tempfile( TEMPLATE => 'webimageXXXXX', DIR => $Conf::temp, SUFFIX => '.png' );
print $fh $self->png();
close $fh;
$filename =~ s/.*\/(\w+\.png)$/$1/;
$image_link = $Conf::temp_url."/".$filename;
} else {
my $mime = MIME::Base64::encode($self->png(), "");
$image_link = "data:image/gif;base64,$mime";
}
return $image_link;
}