Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7de440bf

Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt

  • ID 7de440bfb460ac0e011b7a833390c980c0753984
  • Vorgänger ca96627e
  • Nachfolger 2ee2cbc5

Dateimanagement: größere Vorschaubilder beim Drüberfahren

Unterschiede anzeigen:

SL/Controller/File.pm
17 17
use File::Spec::Unix;
18 18
use File::Spec::Win32;
19 19
use File::MimeInfo::Magic;
20
use MIME::Base64;
20 21
use SL::DB::Helper::Mappings;
21 22
use SL::DB::Order;
22 23
use SL::DB::DeliveryOrder;
......
310 311
  }
311 312
}
312 313

  
314
sub action_ajax_get_thumbnail {
315
  my ($self) = @_;
316

  
317
  my $file      = SL::File->get(id => $::form->{file_id});
318
  my $thumbnail = _create_thumbnail($file, $::form->{size});
319

  
320
  my $overlay_selector = '#enlarged_thumb_' . $::form->{file_id};
321
  $self->js
322
    ->attr($overlay_selector, 'src', 'data:' . $thumbnail->{thumbnail_img_content_type} . ';base64,' . MIME::Base64::encode_base64($thumbnail->{thumbnail_img_content}))
323
    ->data($overlay_selector, 'is-overlay-loaded', '1')
324
    ->render;
325
}
326

  
327

  
313 328
#
314 329
# filters
315 330
#
......
609 624
# ignores all errros
610 625
# todo: cache thumbs?
611 626
sub _create_thumbnail {
612
  my ($file) = @_;
627
  my ($file, $size) = @_;
628

  
629
  $size //= 64;
613 630

  
614 631
  my $filename;
615 632
  if (!eval { $filename = $file->get_file(); 1; }) {
......
621 638
  # Maybe use mime info stored in db?
622 639
  my $mime_type = File::MimeInfo::Magic::magic($filename);
623 640
  if ($mime_type =~ m{pdf}) {
624
    $filename = _convert_pdf_to_png($filename);
641
    $filename = _convert_pdf_to_png($filename, size => $size);
625 642
  }
626 643
  return if !$filename;
627 644

  
......
632 649
  }
633 650

  
634 651
  my $ret;
635
  if (!eval { $ret = file_probe_type($content); 1; }) {
652
  if (!eval { $ret = file_probe_type($content, size => $size); 1; }) {
636 653
    $::lxdebug->message(LXDebug::WARN(), "SL::File::_create_thumbnail file_probe_type failed: " . $EVAL_ERROR);
637 654
    return;
638 655
  }
......
648 665
}
649 666

  
650 667
sub _convert_pdf_to_png {
651
  my ($filename) = @_;
652

  
653
  my $sfile = SL::SessionFile::Random->new();
668
  my ($filename, %params) = @_;
654 669

  
655
  my $command = 'pdftoppm -singlefile -scale-to 64 -png' . ' ' . $filename . ' ' . $sfile->file_name;
670
  my $size    = $params{size} // 64;
671
  my $sfile   = SL::SessionFile::Random->new();
672
  my $command = 'pdftoppm -singlefile -scale-to ' . $size . ' -png' . ' ' . $filename . ' ' . $sfile->file_name;
656 673

  
657 674
  if (system($command) == -1) {
658 675
    $::lxdebug->message(LXDebug::WARN(), "SL::File::_convert_pdf_to_png: system call failed: " . $ERRNO);

Auch abrufbar als: Unified diff