| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package meon::Web::Form::ImageUpload; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
8946294
|
use File::Copy 'copy'; |
|
|
2
|
|
|
|
|
5343
|
|
|
|
2
|
|
|
|
|
322
|
|
|
4
|
2
|
|
|
2
|
|
1960
|
use Imager; |
|
|
2
|
|
|
|
|
80165
|
|
|
|
2
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
680
|
use HTML::FormHandler::Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends 'HTML::FormHandler'; |
|
8
|
|
|
|
|
|
|
with 'meon::Web::Role::Form'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has '+name' => (default => 'form-image-upload'); |
|
11
|
|
|
|
|
|
|
has '+widget_wrapper' => ( default => 'Bootstrap' ); |
|
12
|
|
|
|
|
|
|
has '+enctype' => ( default => 'multipart/form-data'); |
|
13
|
|
|
|
|
|
|
#sub build_form_element_class { ['form-horizontal'] }; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has_field 'file' => ( type => 'Upload', required=>1, label => ''); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has_field 'submit' => ( |
|
18
|
|
|
|
|
|
|
type => 'Submit', |
|
19
|
|
|
|
|
|
|
value => 'Upload', |
|
20
|
|
|
|
|
|
|
max_size => 1024*4000, |
|
21
|
|
|
|
|
|
|
css_class => 'form-row', |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub submitted { |
|
25
|
|
|
|
|
|
|
my ($self) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $c = $self->c; |
|
28
|
|
|
|
|
|
|
my $upload = $self->field('file')->value; |
|
29
|
|
|
|
|
|
|
my $upload_to = $self->get_config_folder('upload-to'); |
|
30
|
|
|
|
|
|
|
my $upload_as = |
|
31
|
|
|
|
|
|
|
eval { $self->get_config_text('upload-as') } |
|
32
|
|
|
|
|
|
|
|| $upload->filename |
|
33
|
|
|
|
|
|
|
; |
|
34
|
|
|
|
|
|
|
my $max_width = |
|
35
|
|
|
|
|
|
|
eval { $self->get_config_text('max-width') } |
|
36
|
|
|
|
|
|
|
|| 640 |
|
37
|
|
|
|
|
|
|
; |
|
38
|
|
|
|
|
|
|
my $max_height = |
|
39
|
|
|
|
|
|
|
eval { $self->get_config_text('max-height') } |
|
40
|
|
|
|
|
|
|
|| 640 |
|
41
|
|
|
|
|
|
|
; |
|
42
|
|
|
|
|
|
|
my $redirect = $self->get_config_text('redirect'); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
unless (-e $upload_to) { |
|
45
|
|
|
|
|
|
|
$upload_to->mkpath || die 'failed to create archive folder - '.$upload_to; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
my $img = Imager->new(file => $upload->tempname) |
|
48
|
|
|
|
|
|
|
or die Imager->errstr(); |
|
49
|
|
|
|
|
|
|
if ($img->getwidth > $max_width) { |
|
50
|
|
|
|
|
|
|
$img = $img->scale(xpixels => $max_width) |
|
51
|
|
|
|
|
|
|
|| die 'failed to scale image - '.$img->errstr; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
if ($img->getheight > $max_height) { |
|
54
|
|
|
|
|
|
|
$img = $img->scale(ypixels => $max_height) |
|
55
|
|
|
|
|
|
|
|| die 'failed to scale image - '.$img->errstr; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
$img->write(file => $upload_to->file($upload_as).'') || die 'failed to save image - '.$img->errstr; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->redirect($redirect); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
no HTML::FormHandler::Moose; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |