(
$VERSION
) =
'$Revisioning: 0.3a11 $'
=~ /\
$Revisioning
:\s+([^\s]+)/;
sub
new {
my
(
$class
,
$pdf
,
$file
,
$tt
)=
@_
;
my
(
$obj
,
$buf
);
if
(
ref
$file
) {
if
(UNIVERSAL::isa(
$file
,
'GD::Image'
)) {
eval
' use PDF::API2::PDF::ImageGD; '
;
die
"unable to load PDF::API2::PDF::ImageGD (did you install correctly?) "
if
($@);
$obj
=PDF::API2::PDF::ImageGD->new(
$pdf
,
'IMGxGDx'
.pdfkey(
$file
),
$file
);
$obj
->{
' apiname'
}=
'IMGxGDx'
.pdfkey(
$file
);
}
else
{
die
"Unknown Object '$file'"
;
}
}
else
{
open
(INF,
$file
);
binmode
(INF);
read
(INF,
$buf
,10,0);
close
(INF);
if
(
$buf
=~/^\xFF\xD8/) {
eval
' use PDF::API2::PDF::ImageJPEG; '
;
die
"unable to load PDF::API2::PDF::ImageJPEG (did you install correctly?) "
if
($@);
$obj
=PDF::API2::PDF::ImageJPEG->new(
$pdf
,
'IMGxJPEGx'
.pdfkey(
$file
),
$file
);
$obj
->{
' apiname'
}=
'IMGxJPEGx'
.pdfkey(
$file
);
}
elsif
(
$buf
=~/^\x89PNG/) {
eval
' use PDF::API2::PDF::ImagePNG; '
;
die
"unable to load PDF::API2::PDF::ImagePNG (did you install correctly?) "
if
($@);
$obj
=PDF::API2::PDF::ImagePNG->new(
$pdf
,
'IMGxPNGx'
.pdfkey(
$file
),
$file
);
$obj
->{
' apiname'
}=
'IMGxPNGx'
.pdfkey(
$file
);
}
elsif
(
$buf
=~/^P[456][\s\n]/) {
eval
' use PDF::API2::PDF::ImagePPM; '
;
die
"unable to load PDF::API2::PDF::ImagePPM (did you install correctly?) "
if
($@);
$obj
=PDF::API2::PDF::ImagePPM->new(
$pdf
,
'IMGxPPMx'
.pdfkey(
$file
),
$file
);
$obj
->{
' apiname'
}=
'IMGxPPMx'
.pdfkey(
$file
);
}
else
{
die
sprintf
(
"image '$file' has unknown format with signature '%02x%02x%02x%02x%02x%02x'"
,
ord
(
substr
(
$buf
,0,1)),
ord
(
substr
(
$buf
,1,1)),
ord
(
substr
(
$buf
,2,1)),
ord
(
substr
(
$buf
,3,1)),
ord
(
substr
(
$buf
,4,1)),
ord
(
substr
(
$buf
,5,1))
);
}
}
return
(
$obj
);
}
sub
newMask {
my
(
$class
,
$pdf
,
$img
,
$file
,
$tt
)=
@_
;
my
(
$obj
,
$buf
);
open
(INF,
$file
);
binmode
(INF);
read
(INF,
$buf
,10,0);
close
(INF);
if
(
$buf
=~/^\xFF\xD8/) {
$obj
=PDF::API2::JPEG->newMask(
$img
,
$file
,
$tt
);
}
elsif
(
$buf
=~/^\x89PNG/) {
$obj
=PDF::API2::PNG->newMask(
$img
,
$file
,
$tt
);
}
elsif
(
$buf
=~/^P[456][\s\n]/) {
$obj
=PDF::API2::PPM->newMask(
$img
,
$file
,
$tt
);
}
else
{
die
sprintf
(
"image '$file' has unknown format with signature '%02x%02x%02x%02x%02x%02x'"
,
ord
(
substr
(
$buf
,0,1)),
ord
(
substr
(
$buf
,1,1)),
ord
(
substr
(
$buf
,2,1)),
ord
(
substr
(
$buf
,3,1)),
ord
(
substr
(
$buf
,4,1)),
ord
(
substr
(
$buf
,5,1))
);
}
$pdf
->new_obj(
$obj
);
$obj
->{
' apipdf'
}.=
$pdf
;
return
(
$obj
);
}
sub
width {
my
$self
=
shift
@_
;
return
(
$self
->{
' width'
});
}
sub
height {
my
$self
=
shift
@_
;
return
(
$self
->{
' height'
});
}
1;