diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index 5fe5c93f4199b..6804eab212c92 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -484,14 +484,18 @@ export default function Image( { // for values that are removed since setAttributes // doesn't do anything with keys that aren't set. setAttributes( { + // width: attribute & style. width: newValue.width && parseInt( newValue.width, 10 ), + // height: attribute only, style is 'auto'. height: newValue.height && parseInt( newValue.height, 10 ), scale: newValue.scale, - aspectRatio: newValue.aspectRatio, + aspectRatio: + newValue.aspectRatio || + newValue.width / newValue.height, } ); } } defaultScale="cover" @@ -688,9 +692,9 @@ export default function Image( { onResizeStop={ ( event, direction, elt ) => { onResizeStop(); setAttributes( { - width: elt.offsetWidth, - height: elt.offsetHeight, - aspectRatio: undefined, + width: elt.offsetWidth, // attribute & style. + height: elt.offsetHeight, // attribute only, style is 'auto'. + aspectRatio: elt.offsetWidth / elt.offsetHeight, } ); } } resizeRatio={ align === 'center' ? 2 : 1 } diff --git a/packages/block-library/src/image/save.js b/packages/block-library/src/image/save.js index 6fa8c6b2342f3..9bc4aacbbc41d 100644 --- a/packages/block-library/src/image/save.js +++ b/packages/block-library/src/image/save.js @@ -59,7 +59,7 @@ export default function save( { attributes } ) { aspectRatio, objectFit: scale, width, - height, + height: !! height && 'auto', // Also defined in style.scss. } } width={ width } height={ height }