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);
css/common.css
221 221
  border-style: solid;
222 222
  background-color: whitesmoke;
223 223
}
224

  
225
.ovlerlay_div {
226
  position: relative;
227
}
228

  
229
.overlay_img {
230
  position: absolute;
231
  top: -100px;
232
  left: -100px;
233
  z-index: 2;
234
  cursor: pointer;
235
}
js/kivi.File.js
301 301
    return false;
302 302
  }
303 303

  
304
  ns.add_enlarged_thumbnail = function(e) {
305
    var file_id        = $(e.target).data('file-id');
306
    var overlay_img_id = 'enlarged_thumb_' + file_id;
307
    var overlay_img    = $('#' + overlay_img_id);
308

  
309
    if (overlay_img.data('is-overlay-shown') == 1) return;
310

  
311
    $('.thumbnail').off('mouseover');
312
    overlay_img.data('is-overlay-shown', 1);
313
    overlay_img.show();
314

  
315
    if (overlay_img.data('is-overlay-loaded') == 1) return;
316

  
317
    var data = {
318
      action:         'File/ajax_get_thumbnail',
319
      file_id:        file_id,
320
      file_version:   $(e.target).data('file-version'),
321
      size:           512
322
    };
323

  
324
    $.post("controller.pl", data, kivi.eval_json_result);
325
  };
326

  
327
  ns.remove_enlarged_thumbnail = function(e) {
328
    $(e.target).hide();
329
    $(e.target).data('is-overlay-shown', 0);
330
    $('.thumbnail').on('mouseover', ns.add_enlarged_thumbnail);
331
  };
332

  
304 333
  ns.init = function() {
305 334
    // Preventing page from redirecting
306 335
    $("#" + ns.list_div_id).on("dragover", function(e) {
......
341 370
      ns.upload_files(object_id, object_type, file_type, maxsize, is_global, files);
342 371
    });
343 372

  
373
    $('.thumbnail').on('mouseover', ns.add_enlarged_thumbnail);
374
    $('.overlay_img').on('click', ns.remove_enlarged_thumbnail);
375
    $('.overlay_img').on('mouseout', ns.remove_enlarged_thumbnail);
344 376
  };
345 377

  
346 378
});
templates/webpages/file/list.html
65 65
      [%- ELSE %]
66 66
       <td align="left">
67 67
        [%- IF file.thumbnail %]
68
         <a href="controller.pl?action=File/download&id=[% file.id %][%- IF file.version %]&version=[%- file.version %][%- END %]">
69
          <img src="data:[% HTML.escape(file.thumbnail.thumbnail_img_content_type) %];base64,[% file.thumbnail.thumbnail_img_content.encode_base64 %]" alt="[% file.file_name %]">
70
         </a>
68
         <div class="ovlerlay_div">
69
          <img id="thumb_[% file.id %]" class="thumbnail"
70
               data-file-id="[% file.id %]" data-file-version="[% file.version %]"
71
               src="data:[% HTML.escape(file.thumbnail.thumbnail_img_content_type) %];base64,[% file.thumbnail.thumbnail_img_content.encode_base64 %]"
72
               alt="[% file.file_name %]">
73
          <img id="enlarged_thumb_[% file.id %]" class="overlay_img">
74
         </div>
71 75
        [%- ELSE %]
72 76
         -
73 77
        [%- END %]

Auch abrufbar als: Unified diff