Dropzone.js 调整图像大小以适合缩略图大小
Dropzone.js resize image to fit the thumbnail size
我正在尝试调整缩略图中图像的大小以修复方框大小。我已经试过了:
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;
}
};
它是这样显示的:
我也试过了:
thumbnailWidth:"300",
thumbnailHeight:"300",
===
thumbnailWidth:"400",
thumbnailHeight:"400",
但是什么都没变,thumbnailWidth and thumbnailHeight
没有效果
您可以在 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
我遇到了同样的问题,但如果您手动调用拖放区的调整大小功能,缩略图将处于正确的尺寸:
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);
我有一个类似的问题,并且能够通过更新生成的缩略图的 CSS
来解决它。您需要将其放入 CSS
.dz-image img{
width: 130px;
height:130px;
}
说明:
问题是图像比 div 大并且隐藏了图像的 rest 因此你最终只得到它的一角。
我正在尝试调整缩略图中图像的大小以修复方框大小。我已经试过了:
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;
}
};
它是这样显示的:
我也试过了:
thumbnailWidth:"300",
thumbnailHeight:"300",
===
thumbnailWidth:"400",
thumbnailHeight:"400",
但是什么都没变,thumbnailWidth and thumbnailHeight
没有效果
您可以在 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
我遇到了同样的问题,但如果您手动调用拖放区的调整大小功能,缩略图将处于正确的尺寸:
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);
我有一个类似的问题,并且能够通过更新生成的缩略图的 CSS
来解决它。您需要将其放入 CSS
.dz-image img{
width: 130px;
height:130px;
}
说明: 问题是图像比 div 大并且隐藏了图像的 rest 因此你最终只得到它的一角。