brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.14k stars 255 forks source link

"flutter web" crashes the browser #620

Open andre-ab opened 4 months ago

andre-ab commented 4 months ago

The code snippet crashes the browser, how to solve this? because on the Web I can't get the path but rather the "Uint8List" bytes

Future<Uint8List> converNowImgUint8List(Uint8List image) async {
    var newImg = img.decodeJpg(image);
    var x = img.copyResize(newImg!, width: 240);
    return img.encodePng(x);
}
brendan-duncan commented 4 months ago

Can you reduce the problem? Is it the decode? The resize? The encode? Comment out the copyResize and encode, does it crash with just the decode? Then add the encode back, try that; then add the resize. Does the decode actually return an Image, or null? How large is the jpeg?

andre-ab commented 4 months ago

in this part of the code: img.decodeJpg(image); image size: 2.7MB lock time: Start = 09:56.835, end = 10:25.325 Image type: tested with JPG and PNG

// open with: 
FilePickerResult? result = await FilePicker.platform.pickFiles( );
if (kIsWeb) {
  final extension = result.files.first.extension;
  final fileImg = result.files.single.bytes;
   return await crop.converNowImgUint8List(fileImg!, extension!)
 }

file: img_crop.dart

     Future<Uint8List> converNowImgUint8List(
      Uint8List image, String extension) async {
    var newImg;
    switch (extension) {
      case 'png':
        // the code crashes on this line
        newImg = img.decodePng(image);
        break;
      case 'jpg':
        // the code crashes on this line
        newImg = img.decodeJpg(image);
        break;
    }
    final x = img.copyResize(newImg!, width: 240);
    return img.encodePng(x);
  }
andre-ab commented 4 months ago

Can you reduce the problem? Is it the decode? The resize? The encode? Comment out the copyResize and encode, does it crash with just the decode? Then add the encode back, try that; then add the resize. Does the decode actually return an Image, or null? How large is the jpeg?

Any news about these crashes on flutter web?

brendan-duncan commented 4 months ago

Sorry for the delay. I'm afraid there just isn't enough info here to be able to diagnose the problem. I don't know what would be crashing Flutter in this case. 2.7MB file size is not large. I don't know what the contents of the file are. If it were an invalid jpeg, it shouldn't crash. I have no idea. If you can send me the file I could take a look, but otherwise I don't know.