PainKKKiller Posted December 19, 2016 Share Posted December 19, 2016 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! Quote Link to comment Share on other sites More sharing options...
PainKKKiller Posted December 19, 2016 Author Share Posted December 19, 2016 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"); }); Quote Link to comment Share on other sites More sharing options...
xerver Posted December 20, 2016 Share Posted December 20, 2016 You should be able to skip the drawing to canvas step and just use the img as the texture source: var img = document.createElement("img"); img.setAttribute("src", src); var spr = new PIXI.Sprite(new PIXI.Texture(new PIXI.BaseTexture(img))); stage.addChild(spr); PainKKKiller 1 Quote Link to comment Share on other sites More sharing options...
PainKKKiller Posted December 22, 2016 Author Share Posted December 22, 2016 xerver, thanks for advice I'll check it out Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.