如何使用dropzone为存储在服务器上的图像生成缩略图? [英] How to generate thumbnails for images stored on the server using dropzone?
问题描述
我正在尝试显示已存储在服务器上的图像。我使用以下代码显示在dropzone中:
I'm trying to display images already stored on the server. I display in dropzone, using the following code:
myDropzone.emit("addedfile", mockFile);
myDropzone.emit("thumbnail", mockFile, "url/image");
但是如果出现问题,生成的缩略图只会将大小缩小为指定的thumnail大小而不会裁剪。
But with a problem, the thumbnail generated only reduces the size to thumnail sizes as specified without crop.
问题是,当我调用功能缩略图失真时,裁剪图像没有完成。
The problem is this is not done the crop image when I call the function thumbnail image is distorted.
它可以使用现有方法生成临时缩略图并在缩略图函数调用中发送吗?
It would be possible to generate a temporary thumbnail using existing methods and sends it in the thumbnail function call?
推荐答案
我建议你创建服务器上的缩略图,因为否则您的用户需要以原始大小下载所有图像,只是为了查看小缩略图。
I am recommending you create thumbnails on the server, because otherwise your users need to download all images in their original size, just to view small thumbnails.
话虽如此,如果你还想去提前,下载原件并在浏览器中调整大小,我刚刚发布了 Dropzone v4.0.1 包括函数 createThumbnailFromUrl()
。
That being said, if you still want to go ahead, and download the originals and resize in the browser, I just released Dropzone v4.0.1 to include the function createThumbnailFromUrl()
.
像这样使用它:
myDropzone.emit("addedfile", mockFile);
myDropzone.createThumbnailFromUrl(mockFile, '/your-image.jpg');
(旁注:图片需要托管在同一台服务器上,否则你会得到一个Cross-Origin错误)
(Side note: the image needs to be hosted on the same server, otherwise you'll get a Cross-Origin error)
这篇关于如何使用dropzone为存储在服务器上的图像生成缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!