将 imagemagick 与 uploadcare 结合使用以显示 PSD、PDF 文件类型的缩略图
Use imagemagick with uploadcare to display thumbnail for PSD, PDF file types
我有一个表单,用户可以在其中使用 uploadcare 小部件上传文件。上传后,我可以 output/show 预览,但前提是文件类型是 jpg、png 等图像。但我还需要能够显示其他文件类型,如 PSD、PDF。我正在尝试为此实现 imagemagick,但混淆了如何将它与 uploadcare 一起使用,因为小部件使用 jquery 来获取图像 cdn。而我在网上找到的大多数教程都是针对 php 的。
您可以查看此 fiddle 中的小部件片段:https://jsfiddle.net/kamela101/e6ac6jb4/
$ = uploadcare.jQuery;
// Create uploaded image list and append additional form fields to each item
function installWidgetPreviewMultiple(widget, list) {
widget.onChange(function(fileGroup) {
list.empty();
if (fileGroup) {
$.when.apply(null, fileGroup.files()).done(function() {
$.each(arguments, function(i, fileInfo) {
// display file preview
var $filename = fileInfo.name;// display file name
var $fileurl = fileInfo.cdnUrl;// get file url
var $src = fileInfo.cdnUrl + '-/resize/100x100/filename.jpg';// preview image source, resize to 100X100px and jpeg file type
// append preview and name and form fields to each file uploaded inside thumb_list
list.append(
$('<li class="thumb_list_item"><img src="' + $src+ '" alt="File Preview" class="preview-img">' + '<h4 class="filename">' + $filename + '</h4>' + '<div class="get-layer-wraper"><ul class="get-layer"><li class="layer-name"><label for="white-layer" class="layer-title">White Layer : </label></li><li><input id="white-layer" name="white-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="adhesive-layer" class="layer-title">Adhesive Layer : </label></li><li><input id="adhesive-layer" name="adhesive-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="block-layer" class="layer-title">Blocking Layer : </label></li><li><input id="block-layer" name="block-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="clear-layer" class="layer-title">Clear Layer : </label></li><li><input id="clear-layer" name="clear-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul></div></li>').appendTo(".thumb_list")
);
});
});
}
});
}
$(function() {
$('.upload-area').each(function() {
installWidgetPreviewMultiple(
uploadcare.MultipleWidget($(this).children('input')),
$(this).children('.thumb_list')
);
});
});
Uploadcare 目前不支持 PSD 和 PDF 预览功能。您必须使用允许您这样做的第三方服务。
我有一个表单,用户可以在其中使用 uploadcare 小部件上传文件。上传后,我可以 output/show 预览,但前提是文件类型是 jpg、png 等图像。但我还需要能够显示其他文件类型,如 PSD、PDF。我正在尝试为此实现 imagemagick,但混淆了如何将它与 uploadcare 一起使用,因为小部件使用 jquery 来获取图像 cdn。而我在网上找到的大多数教程都是针对 php 的。
您可以查看此 fiddle 中的小部件片段:https://jsfiddle.net/kamela101/e6ac6jb4/
$ = uploadcare.jQuery;
// Create uploaded image list and append additional form fields to each item
function installWidgetPreviewMultiple(widget, list) {
widget.onChange(function(fileGroup) {
list.empty();
if (fileGroup) {
$.when.apply(null, fileGroup.files()).done(function() {
$.each(arguments, function(i, fileInfo) {
// display file preview
var $filename = fileInfo.name;// display file name
var $fileurl = fileInfo.cdnUrl;// get file url
var $src = fileInfo.cdnUrl + '-/resize/100x100/filename.jpg';// preview image source, resize to 100X100px and jpeg file type
// append preview and name and form fields to each file uploaded inside thumb_list
list.append(
$('<li class="thumb_list_item"><img src="' + $src+ '" alt="File Preview" class="preview-img">' + '<h4 class="filename">' + $filename + '</h4>' + '<div class="get-layer-wraper"><ul class="get-layer"><li class="layer-name"><label for="white-layer" class="layer-title">White Layer : </label></li><li><input id="white-layer" name="white-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="adhesive-layer" class="layer-title">Adhesive Layer : </label></li><li><input id="adhesive-layer" name="adhesive-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="block-layer" class="layer-title">Blocking Layer : </label></li><li><input id="block-layer" name="block-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="clear-layer" class="layer-title">Clear Layer : </label></li><li><input id="clear-layer" name="clear-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul></div></li>').appendTo(".thumb_list")
);
});
});
}
});
}
$(function() {
$('.upload-area').each(function() {
installWidgetPreviewMultiple(
uploadcare.MultipleWidget($(this).children('input')),
$(this).children('.thumb_list')
);
});
});
Uploadcare 目前不支持 PSD 和 PDF 预览功能。您必须使用允许您这样做的第三方服务。