Closed Hopding closed 4 years ago
Hi, I just tried to open your PNG image in Photopea and it seems to work well. Photopea uses UPNG.toRGBA8(). Try to use UPNG.js library from this repository, as I dont know who is the author and maintainer of your "npm" version.
@photopea The NPM version I am using is advertised in the README file, so I assumed it was an officially supported distribution. The NPM package also lists users photopea and scimonster as contributors (the same contributors as this repo lists). However, I just noticed that the last NPM release was 2 years ago, whereas the last commit to this repo was just 3-4 months ago.
I tried copying the latest version of the UPNG.js
file in this repo directly into a script tag and it works as expected: upng.html.txt (note the .txt
extension is just to get around GitHub's file extension whitelist).
Would you please confirm whether or not the upng-js
NPM package is officially supported or not?
I should also mention that unpkg is just a CDN for NPM packages. All NPM packages are available on it without any additional configuration by the author. But regardless, the problem is not an unpkg issue. I ran into it when just installing the package via npm
.
@Scimonster Could you please update the NPM version of UPNG.js?
I am not a user of NPM (but I made an account there through a browser some time ago). I publish my work only here on this GitHub account, and other users put it on NPM.
If nobody updates it on NPM, I will remove the NPM-related instructions from README.
That makes sense. Thanks for the clarification!
I forked this repo (https://github.com/Hopding/upng) and published my own version to NPM: @pdf-lib/upng
. I'll be using my fork as a dependency in pdf-lib
.
@photopea Thanks for the work you've done on this project! I really appreciate that you've open sourced this code. It's the best PNG decoding library I've been able to find for JavaScript. All the other libraries I've come across either don't support certain types of PNGs or rely on NodeJS APIs and are a hassle to use in the browser.
I only found this lib because of npm. Maybe @Hopding can share the steps to publish it to NPM? Otherwise, maybe you can give me rights to the project and I can figure it out and publish it to NPM. Thanks for a great project!
@Hopding thanks! The most complex part of UPNG.js is the lossy PNG encoder, which can minify PNG files, similar to tinypng.com https://blog.photopea.com/png-minifier-inside-photopea.html
@friksa You can take a look at my fork to see how I went about publishing the code to NPM. Here's a diff of the changes I made: https://github.com/photopea/UPNG.js/compare/master...Hopding:master. Let me know if you have any questions.
And, of course, feel free to just use the @pdf-lib/upng
module I published, if you like.
Hello @photopea and friends!
I'm looking to use
upng-js
as the PNG decoding library forpdf-lib
. However, I ran into an issue when testing the output ofUPNG.toRGBA8()
on thebasi0g01
image from the interlaced PNG test suite linked to in the README.When I run
basi0g01
throughUPNG.toRGBA8()
and draw the output to an HTML canvas, I see the following:The correct rendering is shown below:
I've attached the
basi0g01
image for your convenience:basi0g01.png
Here's a simple self-contained HTML file you can view in your browser to reproduce the issue:
Note that I obtained the inline image by running the following NodeJS script:
Lest you suspect that the issue is simply due to a bug in my script code, I should mention that I first encountered the issue when reading the image data directly from the PNG file. I just thought it would be helpful to create a self-contained HTML file to make reproducing the issue as easy as possible.
Finally, I found that by exporting the PNG image in Mac's Preview app (essentially rewriting it as a different PNG type) I was able to successfully decode and draw it on the canvas. Here's the rewritten image I created:
basi0g01_rewritten.png
. And here's an alternative version of thegetImageData
function you can swap out in the example I shared to use the rewritten version:Any idea what's going on here? Am I doing something incorrectly? Or is this a bug in the
UPNG.toRGBA8()
method?