簡體   English   中英

Filepicker IO 如何在上傳時指定最小寬度和高度

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

我希望能夠為通過 FilePicker 上傳對話框上傳的圖像設置最小寬度和高度(最小尺寸:1200 x 960 像素)。

理想情況下會有一個選項,但我似乎找不到它。

雖然我們沒有一種方法可以根據圖片尺寸限制上傳,但是我們確實添加了在2015年5月上傳圖片時調整圖片大小的功能。

以下參數控制此行為:

這些功能適用於從計算機中拾取的本地文件以及使用網絡攝像頭服務捕獲的圖像。

圖片尺寸

{imageDim:[寬度,高度]}

指定圖像尺寸。 例如:{imageDim:[800,600]}。 上傳之前,本地圖像將被調整大小(放大或縮小)為指定的尺寸。 保持原始的高寬比。 要基於寬度調整所有圖像的大小,請設置[width,null],例如。 [800,空]。 對於高度設置為[null,height],例如[null,600]。

最大圖像尺寸

{imageMax:[寬度,高度]}

指定最大圖像尺寸。 例如:{imageMax:[800,600]}。 大於指定尺寸的圖像將被調整為最大尺寸。

最小影像尺寸

{imageMin:[寬度,高度]}

指定最小圖像尺寸。 例如:{imageMin:[800,600]}。 小於指定尺寸的圖像將放大到最小尺寸。

注意:客戶端調整大小取決於打開的對話框才能正常工作。 如果用戶使用下拉窗格功能(意味着沒有模式對話框窗口打開)上載其圖像,則其圖像將不會被修改。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM