createThumbnailsWithOverlay_img method

Uint8List createThumbnailsWithOverlay_img(
  1. Uint8List overlay_payload,
  2. Uint8List image_Thumbnails, {
  3. Size? size,
})

Implementation

Uint8List createThumbnailsWithOverlay_img(Uint8List overlay_payload, Uint8List image_Thumbnails, {Size? size}) {
  print("createThumbnailsWithOverlay START");
  var s = Stopwatch();
  s.start();
  int w = 0;
  int h = 0;
  final overLayImg = img.decodePng(overlay_payload, frame: 1)!;
  s.stop();
  print("createThumbnailsWithOverlay: img.decodePng(overlay_payload)${s.elapsedMilliseconds}ms for ${overLayImg..lengthInBytes}");
  s.start();

  if (size != null) // allineo vert/hor all'overlay
  {
    w = size.width.toInt();
    h = size.height.toInt();

    if (overLayImg.width > overLayImg.height) {
      w = size.height.toInt();
      ;
      h = size.width.toInt();
    }
  } else {
    w = overLayImg.width ~/ 10;
    h = overLayImg.height ~/ 10;
  }
  var resizedOverlayImg = img.copyResize(overLayImg, width: w, height: h);
  s.stop();
  print("createThumbnailsWithOverlay:  img.copyResize()${s.elapsedMilliseconds}ms for ${overLayImg..lengthInBytes}");
  s.start();
  var imgThumb = img.decodePng(image_Thumbnails)!;
  s.stop();
  print("createThumbnailsWithOverlay:  img.decodePng(image_Thumbnails)${s.elapsedMilliseconds}ms for ${overLayImg..lengthInBytes}");
  s.start();

  var newMiniature = img.compositeImage(imgThumb, resizedOverlayImg, blend: img.BlendMode.alpha);
  s.stop();
  print("createThumbnailsWithOverlay:  img.compositeImage()${s.elapsedMilliseconds}ms for ${overLayImg..lengthInBytes}");
  s.start();

  final pngBytes = img.encodePng(newMiniature);
  s.stop();
  print("createThumbnailsWithOverlay:  img.copyResize()${s.elapsedMilliseconds}ms for ${overLayImg..lengthInBytes}");
  // s.stop();
  // print("createThumbnailsWithOverlay:${s.elapsedMicroseconds} for ${overLayImg..lengthInBytes}");
  return pngBytes;
}