photopea / UPNG.js

Fast and advanced PNG (APNG) decoder and encoder (lossy / lossless)
MIT License
2.1k stars 259 forks source link

" Cannot read properties of undefined (reading 'deflate') " #76

Closed jetrotal closed 2 years ago

jetrotal commented 2 years ago

Hey guys, I'm trying to use upng to generate a indexed-color image, but I can't figure out how to run upng function.

The issue I'm having happens in this page: https://codepen.io/jetrotau/pen/wvmMBeG

if I go on the pen's Iframe and type:

var ctx = stage.canvas.getContext('2d');

var dta = ctx.getImageData(0,0,200,300).data;  // ctx is Context2D of a Canvas
//  dta = new Uint8Array(200 * 300 * 4);       // or generate pixels manually
var png = UPNG.encode([dta.buffer], 200, 300, 0);   console.log(new Uint8Array(png));

I get the error: Cannot read properties of undefined (reading 'deflate')

any Idea on what am I doing wrong?

Thanks in advance!

jetrotal commented 2 years ago

I see what I got wrong.

I imported on my html as

<script src='https://cdnjs.cloudflare.com/ajax/libs/upng-js/2.1.0/UPNG.min.js'> </script>

instead of:

  <script type="module">
  import upngJs from "https://cdn.skypack.dev/upng-js@2.1.0";
  window.UPNG = upngJs;
</script>