annotate GD/Image.pm @ 0:e94de0ea3351 draft default tip

Uploaded
author dereeper
date Wed, 11 Sep 2013 09:08:15 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
1 # DO NOT EDIT! THIS FILE IS AUTOGENERATED BY GD/Image.pm.PLS
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
2 package GD::Image;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
3
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
4 use strict;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
5 use GD;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
6 use Symbol 'gensym','qualify_to_ref';
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
7 use vars '$VERSION';
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
8 $VERSION = '2.38';
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
9
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
10 =head1 NAME
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
11
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
12 GD::Image - Image class for the GD image library
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
13
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
14 =head1 SYNOPSIS
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
15
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
16 See L<GD>
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
17
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
18 =head1 DESCRIPTION
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
19
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
20 See L<GD>
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
21
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
22 =head1 AUTHOR
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
23
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
24 The GD.pm interface is copyright 1995-2005, Lincoln D. Stein. It is
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
25 distributed under the same terms as Perl itself. See the "Artistic
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
26 License" in the Perl source code distribution for licensing terms.
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
27
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
28 The latest versions of GD.pm are available on CPAN:
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
29
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
30 http://www.cpan.org
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
31
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
32 =head1 SEE ALSO
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
33
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
34 L<GD>
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
35 L<GD::Polyline>,
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
36 L<GD::SVG>,
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
37 L<GD::Simple>,
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
38 L<Image::Magick>
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
39
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
40 =cut
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
41
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
42 # Copyright 1995 Lincoln D. Stein. See accompanying README file for
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
43 # usage information
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
44
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
45 *stringTTF = \&GD::Image::stringFT;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
46
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
47 sub _make_filehandle {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
48 shift; # get rid of class
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
49 no strict 'refs';
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
50 my $thing = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
51 return $thing if defined(fileno $thing);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
52
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
53 # otherwise try qualifying it into caller's package
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
54 my $fh;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
55 {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
56 local $^W = 0; # to avoid uninitialized variable warning from Symbol.pm
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
57 $fh = qualify_to_ref($thing,caller(2));
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
58 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
59 return $fh if defined(fileno $fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
60
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
61 # otherwise treat it as a file to open
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
62 $fh = gensym;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
63 open($fh,$thing) || return;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
64 return $fh;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
65 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
66
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
67 sub new {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
68 my $pack = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
69 if (@_ == 1) {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
70 if (my $type = _image_type($_[0])) {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
71 my $method = "newFrom${type}Data";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
72 return unless $pack->can($method);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
73 return $pack->$method($_[0]);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
74 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
75 return unless my $fh = $pack->_make_filehandle($_[0]);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
76 my $magic;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
77 return unless read($fh,$magic,4);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
78 return unless my $type = _image_type($magic);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
79 seek($fh,0,0);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
80 my $method = "newFrom${type}";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
81 return $pack->$method($fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
82 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
83 return $pack->_new(@_);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
84 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
85
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
86 sub newTrueColor {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
87 my $pack = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
88 return $pack->_new(@_, 1);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
89 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
90
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
91 sub newPalette {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
92 my $pack = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
93 return $pack->_new(@_, 0);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
94 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
95
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
96 sub newFromGd {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
97 croak("Usage: newFromGd(class,filehandle)") unless @_==2;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
98 my($class,$f) = @_;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
99 my $fh = $class->_make_filehandle($f);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
100 binmode($fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
101 $class->_newFromGd($fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
102 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
103
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
104 sub newFromGd2 {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
105 croak("Usage: newFromGd2(class,filehandle)") unless @_==2;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
106 my($class,$f) = @_;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
107 my $fh = $class->_make_filehandle($f);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
108 binmode($fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
109 $class->_newFromGd2($fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
110 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
111
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
112 sub newFromGd2Part {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
113 croak("Usage: newFromGd2(class,filehandle,srcX,srcY,width,height)") unless @_==6;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
114 my($class,$f) = splice(@_,0,2);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
115 my $fh = $class->_make_filehandle($f);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
116 binmode($fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
117 $class->_newFromGd2Part($fh,@_);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
118 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
119
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
120 sub ellipse ($$$$$) {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
121 my ($self,$cx,$cy,$width,$height,$color) = @_;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
122 $self->arc($cx,$cy,$width,$height,0,360,$color);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
123 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
124
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
125 # draws closed polygon with the specified color
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
126 sub polygon {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
127 my $self = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
128 my($p,$c) = @_;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
129 $self->openPolygon($p, $c);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
130 $self->line( @{$p->{'points'}->[0]},
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
131 @{$p->{'points'}->[$p->{'length'}-1]}, $c);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
132 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
133
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
134 sub width {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
135 my $self = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
136 my @bounds = $self->getBounds;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
137 $bounds[0];
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
138 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
139
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
140 sub height {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
141 my $self = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
142 my @bounds = $self->getBounds;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
143 $bounds[1];
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
144 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
145
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
146 sub _image_type {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
147 my $data = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
148 my $magic = substr($data,0,4);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
149 return 'Png' if $magic eq "\x89PNG";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
150 return 'Jpeg' if $magic eq "\377\330\377\340";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
151 return 'Jpeg' if $magic eq "\377\330\377\341";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
152 return 'Jpeg' if $magic eq "\377\330\377\355";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
153 return 'Jpeg' if $magic eq "\377\330\377\356";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
154 return 'Gif' if $magic eq "GIF8";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
155 return 'Gd2' if $magic eq "gd2\000";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
156 return 'Xpm' if substr($data,0,9) eq "/* XPM */";
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
157 return;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
158 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
159
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
160
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
161 sub clone {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
162 croak("Usage: clone(\$image)") unless @_ == 1;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
163 my $self = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
164 my ($x,$y) = $self->getBounds;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
165 my $new = $self->new($x,$y);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
166 return unless $new;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
167 $new->copy($self,0,0,0,0,$x,$y);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
168 return $new;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
169 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
170
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
171 sub newFromPng {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
172 croak("Usage: newFromPng(class,filehandle,[truecolor])") unless @_>=2;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
173 my($class) = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
174 my($f) = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
175 my $fh = $class->_make_filehandle($f);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
176 binmode($fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
177 $class->_newFromPng($fh,@_);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
178 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
179
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
180 sub newFromJpeg {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
181 croak("Usage: newFromJpeg(class,filehandle,[truecolor])") unless @_>=2;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
182 my($class) = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
183 my($f) = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
184 my $fh = $class->_make_filehandle($f);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
185 binmode($fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
186 $class->_newFromJpeg($fh,@_);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
187 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
188
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
189 sub newFromGif {
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
190 croak("Usage: newFromGif(class,filehandle,[truecolor])") unless @_>=2;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
191 my($class) = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
192 my($f) = shift;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
193 my $fh = $class->_make_filehandle($f);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
194 binmode($fh);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
195 $class->_newFromGif($fh,@_);
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
196 }
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
197
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
198 # Autoload methods go after __END__, and are processed by the autosplit program.
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
199 1;
e94de0ea3351 Uploaded
dereeper
parents:
diff changeset
200 __END__