Jump to content

How to show images made with jimp library in pixi.js


PainKKKiller
 Share

Recommended Posts

I want to process images on client side with JIMP (awesome library for image processing). I read png file with jimp, modify it with jimp, and then I've get stucked, because I don't know how to display it in pixi.js. The image read by jimp has bitmap property, and when I trying to create texture from it (with  PIXI.Texture.from for example I gets errors). Thanks in advance!

Link to comment
Share on other sites

Already figured it out on my own. for those who interested:

 Jimp.read("res/table.png").then(function (image) {
        // do stuff with the image
        //image.contrast( val ); // adjust the contrast by a value -1 to +1
        console.log(":read table");
        Jimp.loadFont('res/fonts/open-sans/open-sans-8-white/open-sans-8-white.fnt').then(function (font) {
            console.log('font loaded!' + image);
            image.print(font, 10, 10, "Hello world!")
                 .getBase64(Jimp.AUTO, function (err, src) {
                     var img = document.createElement("img");
                     img.setAttribute("src", src);
                     //document.body.appendChild(img);
                      var canvas = document.createElement('canvas');
                      canvas.width  = 150;
                      canvas.height = 180;
                      var ctx = canvas.getContext('2d');
                      ctx.drawImage(img,0,0,150,180);
                    var spr = new PIXI.Sprite(PIXI.Texture.fromCanvas(canvas));
                        stage.addChild(spr);
                             });
                        console.log(image);
        });
        
    }).catch(function (err) {
        // handle an exception
        console.log("can't read image");
    });

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...