10

As the image is large, the response is slow, so must limit! How to do it? thanks!

var editor = new Quill('#postContent', {
  modules: {
    toolbar: '#toolbar-container'
  },
  theme: 'snow',
  //placeholder: '不超过3000字...',
});
willchow
  • 111
  • 1
  • 1
  • 6
  • may my answer on this question help you [link](http://stackoverflow.com/a/41888453/4683616) – hardik Jan 27 '17 at 07:04

4 Answers4

6

Sure can, I made a Quill module to compress images once they are added to the Quill editor (Pasted, Uploaded, Dragged). You can adjust the compression and quality of the compression too.

https://github.com/benwinding/quill-image-compress

import ImageCompress from 'quill-image-compress';

Quill.register('modules/imageCompress', ImageCompress);

const quill = new Quill(editor, {
  // ...
  modules: {
    // ...
    imageCompress: {
      quality: 0.7, // default
      maxWidth: 1000, // default
      maxHeight: 1000, // default
      imageType: 'image/jpeg', // default
      debug: true, // default
    }
  }
});
Ben Winding
  • 10,208
  • 4
  • 80
  • 67
  • Thanks for this. I've only one problem: when I paste an image, the original one stays in the editor and the resized one appears below it. Also, the toolbar button to add an image no longer works (nothing happens and there are no errors). I'm using version 2.0.0-dev.3 of Quill.js. – nonzaprej Feb 09 '21 at 18:18
2

Yes he can. When you add your image, use :

quill.insertEmbed(0, 'image', value, 'user'); // to insert the image

quill.formatText(0, 1, 'width', '300px'); //to limit the width
Salem017
  • 21
  • 3
1

This is not possible at the moment, you would have to create a custom image handler. Feel free to open a feature request.

jhchen
  • 14,355
  • 14
  • 63
  • 91
-1

I gave him this solution, it is not the right one, but it works temporarily:

I modified quill.js and add this validation:

var maxSize = 2097152; // Maximum limit of 2mb (2,097,152 kb)
var fileSize = fileInput.files[0].size;
if (fileSize <= maxSize) { .... }

Image example of quill.js:

enter image description here

Tomislav Stankovic
  • 3,080
  • 17
  • 35
  • 42