foliojs / png.js

A (animated) PNG decoder in JavaScript for the HTML5 canvas element and Node.js
http://devongovett.github.com/png.js
MIT License
489 stars 92 forks source link

Having data passed from PHP, how can we handle the file? #65

Open realtebo opened 2 years ago

realtebo commented 2 years ago

I've this snippet reading a png

   <?php
        $file_name = './ReactNative-snapshot-image6513693026486043647.png';
        $image_file_content = base64_encode(file_get_contents( $file_name ));

        $image_size = getimagesize( $file_name );
    ?>

I need to convert the png to a Uint8ClampedArray (to decode a QRCode client-side, long story)

Is there a way using your lib to get file content from a base64 string?

For instance, I am doing a similar thing using jpeg-js

    const jpegData = Buffer.from("<?php echo $image_file_content ?>", 'base64');
    const rawImageData = jpeg.decode(jpegData);
    const clamped_array = Uint8ClampedArray.from(rawImageData.data);
    const decodedGreenpass = window.jsQR(
          clamped_array,
         <?php echo $image_size[0]; ?>,
         <?php echo $image_size[1]; ?>
    );

I need to obtain in some way pngData or a Uint8ClampedArray