This repository has been archived by the owner on Jul 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileDetails.pm
168 lines (137 loc) · 4.12 KB
/
FileDetails.pm
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package FileDetails;
# Copyright 2008, The Regents of The University of Michigan, All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject
# to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# 3rd Party
use Image::Magick;
use strict;
use File::Basename;
# ----------------------------------------------------------------------
# NAME : new
# PURPOSE : create new object
# CALLED BY :
# CALLS : $self->_initialize
# INPUT :
# RETURNS : NONE
# NOTES :
# ----------------------------------------------------------------------
sub new
{
my $class = shift;
my $self = {};
bless $self, $class;
$self->_initialize(@_);
return $self;
}
# ----------------------------------------------------------------------
# NAME : _initialize
# PURPOSE : create structure for object
# CALLED BY : new
# CALLS :
# INPUT : see new
# RETURNS :
# NOTES :
# ----------------------------------------------------------------------
sub _initialize
{
my $self = shift;
my ($binaries_hr)=(@_);
$self->Set('binaries', $binaries_hr);
}
sub Set
{
my $self = shift;
my ( $key, $value ) = @_;
$self->{ $key } = $value;
}
sub Get
{
my $self = shift;
my $key = shift;
return $self->{ $key };
}
sub GetBinary
{
my $self=shift;
my $key=shift;
my $binaries_hr=$self->Get('binaries');
return( $$binaries_hr{$key} );
}
sub GetFileDetails
{
my $self=shift;
my ($fileinfo_hr) = (@_);
$self->Set('success', 0);
if (! -e $$fileinfo_hr{file})
{
$self->Set('errormsg', qq{no file } . $$fileinfo_hr{file} . qq{\n});
return;
}
my $image = new Image::Magick;
my ($width, $height, $size, $format) = $image->Ping( $$fileinfo_hr{file} );
$$fileinfo_hr{width} = $width;
$$fileinfo_hr{height} = $height;
$$fileinfo_hr{size} = $size;
$$fileinfo_hr{format} = $format;
$$fileinfo_hr{maxwidth} = $width;
$$fileinfo_hr{maxheight} = $height;
$self->_ParseFilePath( $fileinfo_hr );
# it is important to set success
$self->Set('success', 1);
}
sub _ParseFilePath
{
my $self = shift;
my ($fileinfo_hr) = (@_);
( $$fileinfo_hr{base}, $$fileinfo_hr{path}, $$fileinfo_hr{ext} )
= fileparse($$fileinfo_hr{file}, '\.[^.]*');
}
# some file formats don't have "levels" the way jpeg2000 does.
# for the sake of uniform processing, however, we'll assign
# the file a number of levels based on the maximum dimension of the image.
sub FakeNumberOfLevels
{
my $self=shift;
my ($fileinfo_hr) = (@_);
return if ( defined $$fileinfo_hr{levels} );
my $Tmax;
if (($$fileinfo_hr{height} - $$fileinfo_hr{width}) >= 0) {
$Tmax = $$fileinfo_hr{height};
} else {
$Tmax = $$fileinfo_hr{width};
}
my $nlev;
if (($Tmax > 0) && ($Tmax <= 800)) {
$nlev = 2;
} elsif (($Tmax > 800) && ($Tmax <= 1600)) {
$nlev = 3;
} elsif (($Tmax > 1600) && ($Tmax <= 3200)) {
$nlev = 4;
} elsif (($Tmax > 3200) && ($Tmax <= 6400)) {
$nlev = 5;
} elsif (($Tmax > 6400) && ($Tmax <= 12800)) {
$nlev = 6;
} else {
$nlev = 7;
}
$$fileinfo_hr{levels}=$nlev;
return($nlev);
}
# ----------------------------------------------------------------------
1;