javascript - Dropzone.js 调整图像大小以适合缩略图大小

标签 javascript jquery html css dropzone.js

我正在尝试调整缩略图中图像的大小以固定框大小。我试过这个:

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("complete", file);
                    };
                    xhrs.push(xhr);
                    xhr.send();
                });
                this.options.maxFiles = this.options.maxFiles - uploadedImages.count;
            }
        };

这是原始图像的外观: http://files.parsetfss.com/12917a88-ac80-4e5e-a009-fc634161b79c/tfss-6c59b59f-8f57-4610-966e-31bbc203707b-samsung-galaxy-note-4-7290-002.jpg

这是它的显示方式: enter image description here

我也试过了:

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

但是什么都没变,thumbnailWidth 和 thumbnailHeight 没有效果

最佳答案

我遇到了同样的问题,但如果您手动调用拖放区的调整大小功能,缩略图将处于正确的尺寸:

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("complete", file);

关于javascript - Dropzone.js 调整图像大小以适合缩略图大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30081416/

相关文章:

javascript - 将 RegExp 转换回字符串

javascript - 在 Leaflet 中按经纬度过滤 GeoJSON

javascript - 如何根据特定值显示 Angular Controller 数据

javascript - 使用Jquery获取文件名

javascript - 如何将 Bootstrap Burger 菜单功能添加到常规 Bootstrap 菜单?

javascript - CSS:绝对位置改变div宽度

javascript - 如何使 div 可编辑到 textarea 并上传/删除现有图像

javascript - 侧边栏导航不显示

javascript - 连接 JSON 中的两个对象键

javascript - @Html.DropDownListFor() 即使选择了列表项也始终显示空白