我希望能够为通过FilePicker上传对话框上传的图像设置最小宽度和高度(最小大小:1200x960像素)。
理想情况下,这是有选择的,但我似乎找不到。
发布于 2016-01-12 15:47:39
虽然我们没有基于图像尺寸限制上传的方法,但我们在2015年5月上传时增加了调整图像大小的功能。
以下参数控制此行为:
这些功能适用于从您的计算机中提取的本地文件和使用网络摄像头服务捕获的图像。
图像维数
{imageDim:宽度,高度}
指定图像尺寸。例:{imageDim: 800,600}在上传之前,本地图像将被调整大小(向上缩放或缩小)到指定的维度。保持原有的高度与宽度之比。若要根据宽度调整所有图像的大小,请设置宽度、空值等。800,空。对于设置为空的高度,如空,600。
最大图像维数
{imageMax:宽度,高度}
指定最大图像尺寸。例:{imageMax: 800,600}大于指定尺寸的图像将被调整为最大大小。
最小图像维数
{imageMin:宽度,高度}
指定最小图像尺寸。例:{imageMin: 800,600}小于指定尺寸的图像将被向上缩放到最小大小。
注意:客户端调整大小依赖于打开的对话框才能工作。如果用户使用drop窗格功能(意味着没有打开模态对话框窗口)来上传他们的图像,他们的图像将不会被修改。
发布于 2021-11-15 23:12:20
Filestack确实提供了一个选择器选项来设置回调onFileSelected。这是他们网站上的一个教程的例子:
function checkImgSize (file) {
return new Promise(function (resolve, reject) {
const maxWidth = 1300;
const maxHeight = 1300;
const blob = file.originalFile;
// Get an object URL for the local file
const url = URL.createObjectURL(blob);
// Create an image and load the object URL
const img = new Image();
img.src = url;
img.onload = function () {
URL.revokeObjectURL(url);
if (this.naturalWidth > maxWidth) {
reject('File is too wide');
}
if (this.naturalHeight > maxHeight) {
reject('File is too tall');
}
// If we made it here then the file was approved
resolve();
}
});
}
const picker = client.picker({
exposeOriginalFile: true,
onFileSelected: checkImgSize,
});https://stackoverflow.com/questions/29639609
复制相似问题