File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,24 @@ class ImageTransformer implements DomTransformer {
2828 final data =
2929 toImageData (part, contentType.mediaType, configuration);
3030 imageElement.attributes['src' ] = data;
31+ final maxImageWidth = configuration.maxImageWidth;
32+ if (maxImageWidth != null &&
33+ imageElement.attributes['width' ] != null &&
34+ imageElement.attributes['height' ] != null ) {
35+ final width = int .tryParse (imageElement.attributes['width' ]! );
36+ final height = int .tryParse (imageElement.attributes['height' ]! );
37+ if (width != null && width > maxImageWidth && height != null ) {
38+ final factor = maxImageWidth / width;
39+ imageElement.attributes['width' ] = maxImageWidth.toString ();
40+ imageElement.attributes['height' ] =
41+ (height * factor).floor ().toString ();
42+ final styleAttribute = imageElement.attributes['style' ];
43+ if (styleAttribute != null &&
44+ styleAttribute.contains ('width' )) {
45+ imageElement.attributes.remove ('style' );
46+ }
47+ }
48+ }
3149 if (imageElement.parent? .localName != 'a' ) {
3250 final linkCid =
3351 Uri .encodeComponent (cid.substring (1 , cid.length - 1 ));
You can’t perform that action at this time.
0 commit comments