kyranet / canvas-constructor

An ES6 utility for canvas with built-in functions and chained methods.
https://canvasconstructor.js.org
MIT License
116 stars 23 forks source link

bug: Image render are broken #375

Closed troke12 closed 3 years ago

troke12 commented 3 years ago

Describe the bug

The image when we get using resolveImage sometimes broken and sometimes normal

The first one (https://a.troke.id/2) broken

first

The second one (https://a.troke.id/1) normal

second

Code :

async function createBanner() {
    const img = await resolveImage('./images/banner.png');
    const logo = await resolveImage('https://a.troke.id/1');
    return new Canvas(1920, 436)
        .printImage(img, 0, 0, 1920, 436)
        .setColor('#FFFFFF')
        .setTextFont('72px sans-serif')
        .printText('TROKE', 589, 169)
        .printImage(logo, 296, 101, 128, 128)
        .toBufferAsync();
}
kyranet commented 3 years ago

The problem here is that https://a.troke.id/2 is a PNG file with bit depth 16, which Cairo seems to not support according to your try.

You can try https://cdn.skyra.pw/skyra-assets/coins_heads.png (which has a bit depth of 8) and you'll see it works.

The only thing I can think of to fix this, is that you can use GIMP or any other image editing tool to export it as a PNG with bit depth 8, then it'll work.


Starting with canvas-constructor v5 - which I hope to get ready for next week - you'll be able to use an alternative render engine which does support bit depth 16 (and presumably 24 as well).

troke12 commented 3 years ago

image

ah i see, i try it and it's worked, seems like i need to refactor again my avatar server, thank you very much!

kyranet commented 3 years ago

Glad I could help!

For future reference, I used https://www.metadata2go.com to read the PNG's metadata, since I don't have my local tool around :)