最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dropzone.js resize image to fit the thumbnail size - Stack Overflow

programmeradmin4浏览0评论

I'm trying to resize the image in the thumbnail to fix the box size. I've tried this :

Dropzone.options.myAwesomeDropzone = {
            maxFiles: 20,
            maxFilesize: 2,
            maxThumbnailFilesize: 20,
            acceptedFiles: 'image/*,.jpg,.png,.jpeg',
            thumbnailWidth:"250",
            thumbnailHeight:"250",
            init: function() {
                var dropzone = this, xhrs = [];
                $.each(uploadedImages, function (index, path) {
                    var xhr = new XMLHttpRequest();
                    xhr.open('GET', path);
                    xhr.responseType = 'blob';//force the HTTP response, response-type header to be blob
                    xhr.onload = function() {
                        var file = new File([xhr.response], '', {'type': xhr.response.type});
                        //dropzone.addUploadedFile(file);
                        dropzone.emit("addedfile", file);
                        dropzone.emit("thumbnail", file, path);
                        dropzone.emit("plete", file);
                    };
                    xhrs.push(xhr);
                    xhr.send();
                });
                this.options.maxFiles = this.options.maxFiles - uploadedImages.count;
            }
        };

This is the original Image how it looks : .jpg

And this is how it's displayed :

Also I've tried :

thumbnailWidth:"300",
thumbnailHeight:"300",
===
thumbnailWidth:"400",
thumbnailHeight:"400",

But nothing changed, thumbnailWidth and thumbnailHeight have no effect

I'm trying to resize the image in the thumbnail to fix the box size. I've tried this :

Dropzone.options.myAwesomeDropzone = {
            maxFiles: 20,
            maxFilesize: 2,
            maxThumbnailFilesize: 20,
            acceptedFiles: 'image/*,.jpg,.png,.jpeg',
            thumbnailWidth:"250",
            thumbnailHeight:"250",
            init: function() {
                var dropzone = this, xhrs = [];
                $.each(uploadedImages, function (index, path) {
                    var xhr = new XMLHttpRequest();
                    xhr.open('GET', path);
                    xhr.responseType = 'blob';//force the HTTP response, response-type header to be blob
                    xhr.onload = function() {
                        var file = new File([xhr.response], '', {'type': xhr.response.type});
                        //dropzone.addUploadedFile(file);
                        dropzone.emit("addedfile", file);
                        dropzone.emit("thumbnail", file, path);
                        dropzone.emit("plete", file);
                    };
                    xhrs.push(xhr);
                    xhr.send();
                });
                this.options.maxFiles = this.options.maxFiles - uploadedImages.count;
            }
        };

This is the original Image how it looks : http://files.parsetfss./12917a88-ac80-4e5e-a009-fc634161b79c/tfss-6c59b59f-8f57-4610-966e-31bbc203707b-samsung-galaxy-note-4-7290-002.jpg

And this is how it's displayed :

Also I've tried :

thumbnailWidth:"300",
thumbnailHeight:"300",
===
thumbnailWidth:"400",
thumbnailHeight:"400",

But nothing changed, thumbnailWidth and thumbnailHeight have no effect

Share Improve this question asked May 6, 2015 at 15:38 ChlebtaChlebta 3,11015 gold badges52 silver badges99 bronze badges 1
  • Possible duplicate of Dropzone.js + Client Side Image Resizing – Chris Moschini Commented Oct 20, 2017 at 23:22
Add a ment  | 

4 Answers 4

Reset to default 7

I had the same problem, but if you call manually the resize function of the dropzone, the thumnails will be in the right dimensions:

var file = new File([xhr.response], '', {'type': xhr.response.type});
dropzone.createThumbnailFromUrl(file,path);
dropzone.emit("addedfile", file);
dropzone.emit("thumbnail", file, path);
dropzone.emit("plete", file);

You can size a new image explicitly in javascript.

var img = new Image();
img.src =  'http://files.parsetfss./12917a88-ac80-4e5e-a009-fc634161b79c/tfss-6c59b59f-8f57-4610-966e-31bbc203707b-samsung-galaxy-note-4-7290-002.jpg';
img.height = 300;
img.width = 300;

img is now resized with proper dimensions.

Also, I just looked at the dropzone.js documentation and this method is probably of use. http://www.dropzonejs./#config-resize

I had a similar problem and was able to fix it by updating the CSS for the thumbnail that was generated. You will need to put this in your CSS

.dz-image img{
    width: 130px;
    height:130px;
}

Explanation: the problem is that the image is larger the the div and hiding the rest of the picture thus you end up with just a corner of it.

After many tries, I found this and it worked fine for me.

.dz-image img{
   width: 100%;
   height: 100%;
}
发布评论

评论列表(0)

  1. 暂无评论