question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to draw jimp image onto canvas

See original GitHub issue

Just wonderting is it possible to draw image modified by jimp on to canvas. When I am trying something like this:

` 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!”); /image.write(“table-test.png”, function(error, result){ console.log(error); console.log(result); });/ console.log(image); var canvas = document.createElement(‘canvas’); canvas.width = 150; canvas.height = 180; var ctx = canvas.getContext(‘2d’); ctx.drawImage(image.bitmap,0,0,150,180); // or ctx.drawImage(image,0,0,150,180); });

}).catch(function (err) {
    // handle an exception
    console.log("can't read image");
});`

I am getting error TypeError: Failed to execute ‘drawImage’ on ‘CanvasRenderingContext2D’: The provided value is not of type ‘(HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap)’

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
painkkillercommented, Dec 19, 2016

Sorry already figured it out

1reaction
danielholmescommented, Oct 2, 2020

I found the following to be the quickest for me:

const image: Jimp ...
const imageData = new ImageData(
      Uint8ClampedArray.from(image.bitmap.data),
      image.bitmap.width,
      image.bitmap.height
);
ctx.putImageData(imageData, 0, 0);
Read more comments on GitHub >

github_iconTop Results From Across the Web

how draw image in canvas-html5 and replace with exiting ...
You can fill the canvas fully with a background image using the scaling version of context.drawImage . The version of clear below will...
Read more >
How to Draw Using Gimp - Small Business - Chron.com
1. Select the “Paintbrush Tool" from the Toolbox. · 2. Drag the brush on the canvas in a short stroke. · 3. Draw...
Read more >
Drawing rectangles with Jimp - RunKit
1. const Jimp = require('jimp'); ; 2. const canvas = new Jimp(512, 256, 0xFFFFFFFF); ; 3. ​ ; 4. // Promise-based wrapper for...
Read more >
How to Draw Images on JavaScript's Canvas for HTML5 and ...
Draw the image on the canvas. The drawImage() function takes five parameters. The first is the name of an image object (It must...
Read more >
gimp - Draw on layer larger than canvas?
Yes, you can draw on a layer which is bigger than the canvas. There is one restriction: the selection is clipped to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found