简体   繁体   English

Filepicker IO 如何在上传时指定最小宽度和高度

[英]Filepicker IO how to specify a minimum width and hight in upload

I want to be able to set a minimum width and height for images uploaded via the FilePicker Upload dialog box (Minimum size: 1200 x 960 pixels).我希望能够为通过 FilePicker 上传对话框上传的图像设置最小宽度和高度(最小尺寸:1200 x 960 像素)。

Ideally there would be an option for this but I cannot seem to find it.理想情况下会有一个选项,但我似乎找不到它。

While we don't have a method to limit uploads based on image dimensions, we did add the ability to resize images upon upload in May of 2015. 虽然我们没有一种方法可以根据图片尺寸限制上传,但是我们确实添加了在2015年5月上传图片时调整图片大小的功能。

The follow parameters govern this behavior: 以下参数控制此行为:

These functions work for local files picked from your computer and images captured using the webcam service. 这些功能适用于从计算机中拾取的本地文件以及使用网络摄像头服务捕获的图像。

Image dimensions 图片尺寸

{imageDim: [width, height]} {imageDim:[宽度,高度]}

Specify image dimenions. 指定图像尺寸。 eg : {imageDim: [800, 600]}. 例如:{imageDim:[800,600]}。 Local images will be resized (upscaled or downscaled) to the specified dimensions before uploading. 上传之前,本地图像将被调整大小(放大或缩小)为指定的尺寸。 The original height to width ratio is maintained. 保持原始的高宽比。 To resize all images based on the width, set [width, null], eg. 要基于宽度调整所有图像的大小,请设置[width,null],例如。 [800, null]. [800,空]。 For the height set [null, height], eg [null, 600]. 对于高度设置为[null,height],例如[null,600]。

Max image dimensions 最大图像尺寸

{imageMax: [width, height]} {imageMax:[宽度,高度]}

Specify maximum image dimenions. 指定最大图像尺寸。 eg : {imageMax: [800, 600]}. 例如:{imageMax:[800,600]}。 Images bigger than the specified dimensions will be resized to the max size. 大于指定尺寸的图像将被调整为最大尺寸。

Min image dimensions 最小影像尺寸

{imageMin: [width, height]} {imageMin:[宽度,高度]}

Specify minimum image dimenions. 指定最小图像尺寸。 eg : {imageMin: [800, 600]}. 例如:{imageMin:[800,600]}。 Images smaller than the specified dimensions will be upscaled to the minimum size. 小于指定尺寸的图像将放大到最小尺寸。

Note: client side resizing relies on the dialog being opened to work. 注意:客户端调整大小取决于打开的对话框才能正常工作。 If a user utilizes the drop-pane functionality (meaning no modal dialog window opens) to upload their images, their images will not be modified. 如果用户使用下拉窗格功能(意味着没有模式对话框窗口打开)上载其图像,则其图像将不会被修改。

Filestack does provide a picker option to set a callback onFileSelected . Filestack 确实提供了一个选择器选项来设置回调onFileSelected This is an example from a tutorial on their web site:这是他们网站上教程的示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM