forked from drone/command-center-dashboard

罗广辉
2025-04-02 e1699c4851f6ca397cd0ad1ff63f32c737654836
src/utils/cesium/compressImage2.js
@@ -12,35 +12,35 @@
    maxWidth,
    maxHeight,
    outputFormat = 'image/jpeg',
    quality = 0.7,
   quality = 0.7
) {
    return new Promise((resolve, reject) => {
        const image = new Image();
        image.setAttribute('crossOrigin', 'Anonymous');
        image.src = src;
      const image = new Image()
      image.setAttribute('crossOrigin', 'Anonymous')
      image.src = src
        image.onload = () => {
            let width = image.width;
            let height = image.height;
         let width = image.width
         let height = image.height
            if (width > maxWidth) {
                height *= maxWidth / width;
                width = maxWidth;
            height *= maxWidth / width
            width = maxWidth
            }
            if (height > maxHeight) {
                width *= maxHeight / height;
                height = maxHeight;
            width *= maxHeight / height
            height = maxHeight
            }
            const canvas = document.createElement('canvas');
            canvas.width = width;
            canvas.height = height;
            const ctx = canvas.getContext('2d');
            ctx.drawImage(image, 0, 0, width, height);
         const canvas = document.createElement('canvas')
         canvas.width = width
         canvas.height = height
         const ctx = canvas.getContext('2d')
         ctx.drawImage(image, 0, 0, width, height)
            const newDataUrl = canvas.toDataURL(outputFormat, quality);
            resolve(newDataUrl);
        };
        image.onerror = reject;
    });
         const newDataUrl = canvas.toDataURL(outputFormat, quality)
         resolve(newDataUrl)
      }
      image.onerror = reject
   })
}