Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Outline

Jimp ... in a browser

Browser support for Jimp was added by Phil Seaton. This enabled Jimp to be used in Electron applications as well as web browsers.

Example usage:

<script src="jimp.min.js"></script>
<script>
Jimp.read("lenna.png").then(function (lenna) {
    lenna.resize(256, 256)            // resize
         .quality(60)                 // set JPEG quality
         .greyscale()                 // set greyscale
         .getBase64(Jimp.MIME_JPEG, function (err, src) {
              var img = document.createElement("img");
              img.setAttribute("src", src);
              document.body.appendChild(img);
         });
}).catch(function (err) {
    console.error(err);
});
</script>

See the main documentation for the full API documenatinon.

WebWorkers

For better performance, it recommended that Jimp methods are run on a separate thread using WebWorkers. The following shows how using two files (index.html and jimp-worker.js):

// index.html

var worker = new Worker('jimp-worker.js');
worker.onmessage = function(e) {
    // append a new img element using the base 64 image
    var img = document.createElement('img');
    img.setAttribute('src', e.data);
    document.body.appendChild(img);
};
worker.postMessage('lenna.png'); // message the worker thread
// jimp-worker.js

importScripts('jimp.min.js');

self.addEventListener('message', function(e) {
    Jimp.read(e.data).then(function(lenna) {
        lenna
            .resize(256, 256) // resize
            .quality(60) // set JPEG quality
            .greyscale() // set greyscale
            .getBase64(Jimp.MIME_JPEG, function(err, src) {
                self.postMessage(src); // message the main thread
            });
    });
});

License

Jimp is licensed under the MIT license.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.