medium-editor-insert-plugin icon indicating copy to clipboard operation
medium-editor-insert-plugin copied to clipboard

image resize before upload does not work

Open quape opened this issue 8 years ago • 4 comments

Hi there,

as this plugin uses blueimp fileupload for uplading images I though I could just add this to fileUploadOptions:

disableImageResize: false,
imageMaxWidth: 400,
imageMaxHeight: 400

(Of course I added the depending js libs to my app) Unfortunately that does not work at all. The file is uploaded but not resized before. Are there maybe some interfering things with the preview function of this plugin and the blueimp process() ?

Thanks

quape avatar Mar 19 '16 11:03 quape

No, client size resizing is not supported right now. The only option is to resize on server and return to the plugin resized imaged.

linkesch avatar Mar 23 '16 09:03 linkesch

Well, you use blueimp fileupload which supports resizing. So it should only be some little piece of code to make it work. If you give me a hint why it doesn't work out of the box I can do it.

quape avatar Mar 23 '16 10:03 quape

I don't know how blueimp's resizing works. In our plugin we use Images.showImage(img, data) function to add an image to content.

This function is called twice:

  1. If you have preview enabled, it is called from Images.uploadAdd() function with img parameter set to preview image data BLOB.
  2. When upload is done, the function is called one more time from Images.uploadDone() function where it is called with img parameter set to URL to uploaded image and if the preview was enabled, the preview image is just replaced with the real image URL.

So my guess would be to take a look at Images.uploadDone() and change data.result.files[0].url to resized image provided by jQuery File Upload plugin.

linkesch avatar Mar 23 '16 10:03 linkesch

I have found a solution as below with changing "medium-editor-insert-plugin.js"


fileUploadOptions = {
                dataType: 'json',
                add: function (e, data) {
                    $.proxy(that, 'uploadAdd', e, data)();
                    $.blueimp.fileupload.prototype.options.add.call(this, e, data); // Add this line
                },
                done: function (e, data) {
                    $.proxy(that, 'uploadDone', e, data)();
                },
                disableImageResize: false,  // Add this line
                imageMaxWidth: 960,  // Add this line
            };

amboleos avatar Jan 10 '19 13:01 amboleos