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.

Throws "Invalid filter algorithm" error on some PNG images

See original GitHub issue

When attempting to generate a pdf with this image jsPDF throws an error:

Uncaught Error: Invalid filter algorithm: 100
    at e.decodePixels (jspdf.min.js:286)
    at Object.t.processPNG (jspdf.min.js:282)
    at Object.t.addImage (jspdf.min.js:281)

I’ve created an example bin to illustrate the issue: http://jsbin.com/nujiyebamu/edit?html,js,output

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
denis-lukincommented, Apr 16, 2021

If someone still doesn’t know what to do, you can try this:

const convertImgToBase64URL = (url, outputFormat) =>
    new Promise((resolve, reject) => {
        const img = new Image();
        img.crossOrigin = 'Anonymous';
        img.onerror = (e) => {
            reject(e);
        };
        img.onload = function () {
            let canvas = document.createElement('CANVAS');
            const ctx = canvas.getContext('2d');
            let dataURL;
            canvas.height = img.height;
            canvas.width = img.width;
            ctx.drawImage(img, 0, 0, img.width, img.height);
            dataURL = canvas.toDataURL(outputFormat);
            canvas = null;
            resolve({ dataURL });
        };
        img.src = url;
    });

const imageBase64 = convertImgToBase64URL('/assets/images/your_image.png');

after that just use this for image rendering:

<Image src={imageBase64.dataURL} />

1reaction
Uzlopakcommented, Sep 22, 2017

PullRequest #1455

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Throws "Invalid filter algorithm" error on some PNG images
When attempting to generate a pdf with this image jsPDF throws an error: Uncaught Error: Invalid filter algorithm: 100 at e.
Read more >
Top 10 Most Common C++ Mistakes That Developers Make
This article explains how ten of the most common C++ developer mistakes can be avoided ... Some STL algorithms can also lead to...
Read more >
References - JuliaImages
Throw an error if the image has a time dimension that is not the last dimension. ... Filter a one, two or multidimensional...
Read more >
Wireshark User's Guide
Display packets with very detailed protocol information. Save packet data captured. Export some or all packets in a number of capture file formats....
Read more >
Magick++ API: Working with Images - ImageMagick
Depending on the constructor arguments, the Blob size , depth , magick (format) may also be specified. Some image formats require that size...
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