【问题标题】:Dropzone.js resize image to fit the thumbnail sizeDropzone.js 调整图像大小以适应缩略图大小
【发布时间】:2015-07-16 20:47:09
【问题描述】:

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

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

这就是它的显示方式:

我也试过了:

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

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

【问题讨论】:

标签: javascript jquery html css dropzone.js


【解决方案1】:

我遇到了类似的问题,并且能够通过更新生成的缩略图的CSS 来解决它。你需要把它放在你的 CSS 中

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

说明: 问题是图像比 div 更大,并且隐藏了图片的 rest,因此你最终只剩下一个角落。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,但是如果你手动调用 dropzone 的 resize 函数,缩略图的尺寸会正确:

    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);
    

    【讨论】:

    • 谢谢,添加方法调用“createThumbnailFromUrl”对我有用。
    【解决方案3】:

    您可以在 javascript 中明确调整新图像的大小。

    var img = new Image();
    img.src =  'http://files.parsetfss.com/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 现在已调整为适当的尺寸。

    另外,我刚刚查看了 dropzone.js 文档,这种方法可能很有用。 http://www.dropzonejs.com/#config-resize

    【讨论】:

    • 感谢这个解决方案,但我想使用图书馆的thumbnailWith and thumbnailHeight...
    猜你喜欢
    • 2012-05-02
    • 2012-01-06
    • 2011-09-03
    • 2014-05-05
    • 2012-09-15
    • 1970-01-01
    • 2013-12-30
    • 2020-08-26
    • 2013-06-22
    相关资源
    最近更新 更多