i just came across the bug, that evry image i saves was hieroglyphic.
I fixed this bug debugging my code this whole morning.
So, i open locally stored images using lwip and calculating the scaling - so that every image gets scaled to a maximum 300x300 square thumbnail. After that part, i create a blank canvas with white background and paste my scaled image on top of that, to prevent black background on transparent images and save it locally.
lwip.open(imagePath, function(err, image) {
var ratio = 300 / Math.max(image.width(), image.height()),
scaledHeight = image.height() * ratio,
scaledWidth = image.width() * ratio;
image.scale(ratio, function(err, image) {
// create a blank canvas with the same dimensions as our image
lwip.create(scaledWidth, scaledHeight, 'white', function(err, canvas) {
// paste original image on top of the canvas
canvas.paste(0, 0, image, function(err, image) {
// save it locally
});
});
});
});
but i discovered, that lwip.create does not support float numbers (decimal numbers), it only works with Integers...
so a workaroud for me was to use Math.floor before creating the white canvas.
I know it's specific, but i just want it to be documented... if someone else stumbles upon the same bug.
Thanks @ChiefORZ
Note that the docs state that the dimensions must be integers. But nevertheless it should probably throw an exception when non integers are passed.
Hey,
i just came across the bug, that evry image i saves was hieroglyphic.
I fixed this bug debugging my code this whole morning. So, i open locally stored images using lwip and calculating the scaling - so that every image gets scaled to a maximum 300x300 square thumbnail. After that part, i create a blank canvas with white background and paste my scaled image on top of that, to prevent black background on transparent images and save it locally.
but i discovered, that
lwip.create
does not support float numbers (decimal numbers), it only works with Integers... so a workaroud for me was to use Math.floor before creating the white canvas.I know it's specific, but i just want it to be documented... if someone else stumbles upon the same bug.