yacon
yacon

Reputation: 1122

dropzone - change the thumbnail size

I want to upload one file and set the width and height to fit in a given div, depending on the file size. e.g.:

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

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

the thumb gets created with width 600 and height 300 (by using thumbnailWidth and thumbnailHeight options)

on success I receive the filesize. In the example case I let the width of the image and div at 600px, but I want to change the height to 200 (So that the image doesn't get deformed)

My problem now is that the image src (data) still has a width of 300px

Any ideas how to fix that? THANKS!

Upvotes: 3

Views: 4250

Answers (1)

Tyjeans
Tyjeans

Reputation: 101

Change the resize fonction like this:

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

Upvotes: 1

Related Questions