use File::Spec::Unix;
use File::Spec::Win32;
use File::MimeInfo::Magic;
+use MIME::Base64;
use SL::DB::Helper::Mappings;
use SL::DB::Order;
use SL::DB::DeliveryOrder;
}
}
+sub action_ajax_get_thumbnail {
+ my ($self) = @_;
+
+ my $file = SL::File->get(id => $::form->{file_id});
+ my $thumbnail = _create_thumbnail($file, $::form->{size});
+
+ my $overlay_selector = '#enlarged_thumb_' . $::form->{file_id};
+ $self->js
+ ->attr($overlay_selector, 'src', 'data:' . $thumbnail->{thumbnail_img_content_type} . ';base64,' . MIME::Base64::encode_base64($thumbnail->{thumbnail_img_content}))
+ ->data($overlay_selector, 'is-overlay-loaded', '1')
+ ->render;
+}
+
+
#
# filters
#
# ignores all errros
# todo: cache thumbs?
sub _create_thumbnail {
- my ($file) = @_;
+ my ($file, $size) = @_;
+
+ $size //= 64;
my $filename;
if (!eval { $filename = $file->get_file(); 1; }) {
# Maybe use mime info stored in db?
my $mime_type = File::MimeInfo::Magic::magic($filename);
if ($mime_type =~ m{pdf}) {
- $filename = _convert_pdf_to_png($filename);
+ $filename = _convert_pdf_to_png($filename, size => $size);
}
return if !$filename;
}
my $ret;
- if (!eval { $ret = file_probe_type($content); 1; }) {
+ if (!eval { $ret = file_probe_type($content, size => $size); 1; }) {
$::lxdebug->message(LXDebug::WARN(), "SL::File::_create_thumbnail file_probe_type failed: " . $EVAL_ERROR);
return;
}
}
sub _convert_pdf_to_png {
- my ($filename) = @_;
-
- my $sfile = SL::SessionFile::Random->new();
+ my ($filename, %params) = @_;
- my $command = 'pdftoppm -singlefile -scale-to 64 -png' . ' ' . $filename . ' ' . $sfile->file_name;
+ my $size = $params{size} // 64;
+ my $sfile = SL::SessionFile::Random->new();
+ my $command = 'pdftoppm -singlefile -scale-to ' . $size . ' -png' . ' ' . $filename . ' ' . $sfile->file_name;
if (system($command) == -1) {
$::lxdebug->message(LXDebug::WARN(), "SL::File::_convert_pdf_to_png: system call failed: " . $ERRNO);
border-style: solid;
background-color: whitesmoke;
}
+
+.ovlerlay_div {
+ position: relative;
+}
+
+.overlay_img {
+ position: absolute;
+ top: -100px;
+ left: -100px;
+ z-index: 2;
+ cursor: pointer;
+}
return false;
}
+ ns.add_enlarged_thumbnail = function(e) {
+ var file_id = $(e.target).data('file-id');
+ var overlay_img_id = 'enlarged_thumb_' + file_id;
+ var overlay_img = $('#' + overlay_img_id);
+
+ if (overlay_img.data('is-overlay-shown') == 1) return;
+
+ $('.thumbnail').off('mouseover');
+ overlay_img.data('is-overlay-shown', 1);
+ overlay_img.show();
+
+ if (overlay_img.data('is-overlay-loaded') == 1) return;
+
+ var data = {
+ action: 'File/ajax_get_thumbnail',
+ file_id: file_id,
+ file_version: $(e.target).data('file-version'),
+ size: 512
+ };
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.remove_enlarged_thumbnail = function(e) {
+ $(e.target).hide();
+ $(e.target).data('is-overlay-shown', 0);
+ $('.thumbnail').on('mouseover', ns.add_enlarged_thumbnail);
+ };
+
ns.init = function() {
// Preventing page from redirecting
$("#" + ns.list_div_id).on("dragover", function(e) {
ns.upload_files(object_id, object_type, file_type, maxsize, is_global, files);
});
+ $('.thumbnail').on('mouseover', ns.add_enlarged_thumbnail);
+ $('.overlay_img').on('click', ns.remove_enlarged_thumbnail);
+ $('.overlay_img').on('mouseout', ns.remove_enlarged_thumbnail);
};
});
[%- ELSE %]
<td align="left">
[%- IF file.thumbnail %]
- <a href="controller.pl?action=File/download&id=[% file.id %][%- IF file.version %]&version=[%- file.version %][%- END %]">
- <img src="data:[% HTML.escape(file.thumbnail.thumbnail_img_content_type) %];base64,[% file.thumbnail.thumbnail_img_content.encode_base64 %]" alt="[% file.file_name %]">
- </a>
+ <div class="ovlerlay_div">
+ <img id="thumb_[% file.id %]" class="thumbnail"
+ data-file-id="[% file.id %]" data-file-version="[% file.version %]"
+ src="data:[% HTML.escape(file.thumbnail.thumbnail_img_content_type) %];base64,[% file.thumbnail.thumbnail_img_content.encode_base64 %]"
+ alt="[% file.file_name %]">
+ <img id="enlarged_thumb_[% file.id %]" class="overlay_img">
+ </div>
[%- ELSE %]
-
[%- END %]