8 |
8 |
|
9 |
9 |
use utf8;
|
10 |
10 |
use Encode qw(decode);
|
|
11 |
use English qw( -no_match_vars );
|
11 |
12 |
use URI::Escape;
|
12 |
13 |
use Cwd;
|
13 |
14 |
use DateTime;
|
14 |
15 |
use File::stat;
|
|
16 |
use File::Slurp qw(slurp);
|
15 |
17 |
use File::Spec::Unix;
|
16 |
18 |
use File::Spec::Win32;
|
17 |
19 |
use File::MimeInfo::Magic;
|
... | ... | |
29 |
31 |
use SL::Helper::CreatePDF qw(:all);
|
30 |
32 |
use SL::Locale::String;
|
31 |
33 |
use SL::SessionFile;
|
|
34 |
use SL::SessionFile::Random;
|
32 |
35 |
use SL::File;
|
33 |
|
use SL::Controller::Helper::ThumbnailCreator qw(file_probe_image_type);
|
|
36 |
use SL::Controller::Helper::ThumbnailCreator qw(file_probe_image_type file_probe_type);
|
34 |
37 |
|
35 |
38 |
use constant DO_DELETE => 0;
|
36 |
39 |
use constant DO_UNIMPORT => 1;
|
... | ... | |
393 |
396 |
}
|
394 |
397 |
$self->files(\@files);
|
395 |
398 |
|
|
399 |
$_->{thumbnail} = _create_thumbnail($_) for @files;
|
|
400 |
|
396 |
401 |
if($self->object_type eq 'shop_image'){
|
397 |
402 |
$self->js
|
398 |
403 |
->run('kivi.ShopPart.show_images', $self->object_id)
|
... | ... | |
601 |
606 |
return @sources;
|
602 |
607 |
}
|
603 |
608 |
|
|
609 |
# ignores all errros
|
|
610 |
# todo: cache thumbs?
|
|
611 |
sub _create_thumbnail {
|
|
612 |
my ($file) = @_;
|
|
613 |
|
|
614 |
my $filename;
|
|
615 |
if (!eval { $filename = $file->get_file(); 1; }) {
|
|
616 |
$::lxdebug->message(LXDebug::WARN(), "SL::File::_create_thumbnail get_file failed: " . $EVAL_ERROR);
|
|
617 |
return;
|
|
618 |
}
|
|
619 |
|
|
620 |
# Workaround for pfds which are not handled by file_probe_type.
|
|
621 |
# Maybe use mime info stored in db?
|
|
622 |
my $mime_type = File::MimeInfo::Magic::magic($filename);
|
|
623 |
if ($mime_type =~ m{pdf}) {
|
|
624 |
$filename = _convert_pdf_to_png($filename);
|
|
625 |
}
|
|
626 |
return if !$filename;
|
|
627 |
|
|
628 |
my $content;
|
|
629 |
if (!eval { $content = slurp $filename; 1; }) {
|
|
630 |
$::lxdebug->message(LXDebug::WARN(), "SL::File::_create_thumbnail slurp failed: " . $EVAL_ERROR);
|
|
631 |
return;
|
|
632 |
}
|
|
633 |
|
|
634 |
my $ret;
|
|
635 |
if (!eval { $ret = file_probe_type($content); 1; }) {
|
|
636 |
$::lxdebug->message(LXDebug::WARN(), "SL::File::_create_thumbnail file_probe_type failed: " . $EVAL_ERROR);
|
|
637 |
return;
|
|
638 |
}
|
|
639 |
|
|
640 |
# file_probe_type returns a hash ref with thumbnail info and content
|
|
641 |
# or an error message
|
|
642 |
if ('HASH' ne ref $ret) {
|
|
643 |
$::lxdebug->message(LXDebug::WARN(), "SL::File::_create_thumbnail file_probe_type returned an error: " . $ret);
|
|
644 |
return;
|
|
645 |
}
|
|
646 |
|
|
647 |
return $ret;
|
|
648 |
}
|
|
649 |
|
|
650 |
sub _convert_pdf_to_png {
|
|
651 |
my ($filename) = @_;
|
|
652 |
|
|
653 |
my $sfile = SL::SessionFile::Random->new();
|
|
654 |
|
|
655 |
my $command = 'pdftoppm -singlefile -scale-to 64 -png' . ' ' . $filename . ' ' . $sfile->file_name;
|
|
656 |
|
|
657 |
if (system($command) == -1) {
|
|
658 |
$::lxdebug->message(LXDebug::WARN(), "SL::File::_convert_pdf_to_png: system call failed: " . $ERRNO);
|
|
659 |
return;
|
|
660 |
}
|
|
661 |
if ($CHILD_ERROR) {
|
|
662 |
$::lxdebug->message(LXDebug::WARN(), "SL::File::_convert_pdf_to_png: pdftoppm failed with error code: " . ($CHILD_ERROR >> 8));
|
|
663 |
return;
|
|
664 |
}
|
|
665 |
|
|
666 |
return $sfile->file_name . '.png';
|
|
667 |
}
|
|
668 |
|
604 |
669 |
1;
|
605 |
670 |
|
606 |
671 |
__END__
|
Dateimanagement: Thumbnails erzeugen und anzeigen