imageSize property

String get imageSize

Implementation

String get imageSize {
  if (width != null && height != null) {
    return " width=$width height=$height";
  }
  if (width != null) {
    return " width=$width";
  }
  if (height != null) {
    return " height=$height";
  }
  if (autoSize) {
    final String? imageRoot = Platform.environment["TECHS_IMAGE_ROOT"];
    final file = imageRoot == null ? File(src) : File(p.join(imageRoot, src));
    if (file.existsSync()) {
      final img.Image? imageData = img.decodeImage(file.readAsBytesSync());
      if (imageData == null) return "";
      inlineStyles = [
        "max-width: 100%",
        "height: auto",
        "max-height: ${imageData.height}px",
        ...inlineStyles ?? [],
      ];
      return " width=${imageData.width} height=${imageData.height}";
    }
  }
  return "";
}