【问题标题】:dropzone - change the thumbnail sizedropzone - 更改缩略图大小
【发布时间】:2014-09-17 01:27:16
【问题描述】:

我想上传一个文件并设置宽度和高度以适应给定的div,具体取决于文件大小。例如:

div size: width: 600px, height: 300px

img size: width: 1200px, height: 400px

使用width 600 和height 300 创建拇指(通过使用thumbnailWidththumbnailHeight 选项)

success 我收到文件大小。在示例情况下,我让图像和 div 的宽度为 600px,但我想将高度更改为 200(这样图像不会变形)

我现在的问题是图片src(数据)的宽度还是300px

任何想法如何解决这个问题?谢谢!

【问题讨论】:

    标签: dropzone.js


    【解决方案1】:

    像这样改变调整大小的功能:

    https://github.com/enyo/dropzone/issues/236

    ,
        resize: function(file) {
            var info;
    
            // drawImage(image, srcX, srcY, srcWidth, srcHeight, trgX, trgY, trgWidth, trgHeight) takes an image, clips it to
            // the rectangle (srcX, srcY, srcWidth, srcHeight), scales it to dimensions (trgWidth, trgHeight), and draws it
            // on the canvas at coordinates (trgX, trgY).
            info = {
                srcX:0,
                srcY:0,
                srcWidth: file.width,
                srcHeight: file.height,
                trgX:0,
                trgY:0,
                trgWidth: this.options.thumbnailWidth,
                trgHeight: parseInt(this.options.thumbnailWidth * file.height / file.width)
            }
    
            return info;
        },
    

    【讨论】:

      猜你喜欢
      • 2015-03-17
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-21
      • 2018-02-23
      相关资源
      最近更新 更多