Giter VIP home page Giter VIP logo

quill-image-compress's Introduction

quill-image-compress

NPM Version License Downloads/week Github Issues Build and Publish

Quill.js Module which compresses images that are uploaded to the editor

Install

yarn add quill-image-compress

Features

  • Will compress image when:
    • Drag/Dropped into quill
    • Pasted into quill
    • Clicked image load button
  • Handles most image formats a browser can read:
    • gif|jpeg|png|svg|webp|bmp|vnd
  • Compression options more info
  • Add multiple images in one drag/paste

NOTE: ❗you don't need quill-image-drop-module, it's included in this package:exclamation:

Quickstart

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
      suppressErrorLogging: false, // default
      insertIntoEditor: undefined, // default
    }
  }
});

Quickstart (script tag)

    <script src="https://unpkg.com/[email protected]/dist/quill.imageCompressor.min.js"></script>
    <script>
      Quill.register("modules/imageCompressor", imageCompressor);
      
      var quill = new Quill("#editor", {
        modules: {
          imageCompressor: {
            quality: 0.9,
            maxWidth: 1000, // default
            maxHeight: 1000, // default
            imageType: 'image/jpeg'
          }
        }
      });
    </script>

Options

  • [Integer] maxWidth, maxHeight

    • Maximum width of images (in pixels)
  • [Float] quality

    • Image quality range: 0.0 - 1.0
  • [String] imageType

    • Values: 'image/jpeg' , 'image/png' ... etc
  • [Array] keepImageTypes
    Preserve image type and apply quality, maxWidth, maxHeight options

    • Values: ['image/jpeg', 'image/png']
  • [Array] ignoreImageTypes
    Image types contained in this array retain their original images, do not compress them.

    • Values: ['image'/jpeg', 'image/webp']
  • [Function] insertIntoEditor Custom function to handle inserting the image. If you wanted to upload the image to a webserver rather than embedding with Base64, you could use this function.

    • Example function, uploading to a webserver:
      insertIntoEditor: (imageBase64URL, imageBlob, editor) => {    
        const formData = new FormData();
        formData.append("file", imageBlob);
      
        fetch("/upload", {method: "POST", body: formData})
          .then(response => response.text())
          .then(result => {
            const range = editor.getSelection();
            editor.insertEmbed(range.index, "image", `${result}`, "user");
          })
          .catch(error => {
            console.error(error);
          });
      }
  • [Boolean] debug

    • Displays console logs: true/false

Thanks

This project is based on quill-image-uploader, thanks mate!

quill-image-compress's People

Contributors

benwinding avatar zeevl avatar leehanyeong avatar koenvg avatar ckpuna4 avatar sercangurbuz avatar yenda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.