Skip to content

Commit

Permalink
Image editing: fix image size on crop
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 16, 2020
1 parent 140a5e9 commit 1a314dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/block-library/src/image/image-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ export default function ImageEditor( {
url,
setAttributes,
isSelected,
naturalWidth,
naturalHeight,
width,
height,
children,
} ) {
const { createErrorNotice } = useDispatch( 'core/notices' );
const [ isCropping, setIsCropping ] = useState( false );
const [ inProgress, setIsProgress ] = useState( null );
const [ imageSize, setImageSize ] = useState( {
naturalHeight: 0,
naturalWidth: 0,
} );
const [ crop, setCrop ] = useState( null );
const [ position, setPosition ] = useState( { x: 0, y: 0 } );
const [ zoom, setZoom ] = useState( 1 );
Expand Down Expand Up @@ -235,14 +235,15 @@ export default function ImageEditor( {
</div>
) }
{ isCropping ? (
<div className="richimage__crop-controls">
<>
<div
className="richimage__crop-area"
style={ {
paddingBottom: `${
( 100 * imageSize.naturalHeight ) /
imageSize.naturalWidth
( 100 * naturalHeight ) / naturalWidth
}%`,
width,
height,
} }
>
<Cropper
Expand All @@ -256,7 +257,6 @@ export default function ImageEditor( {
onCropChange={ setPosition }
onCropComplete={ setCrop }
onZoomChange={ setZoom }
onMediaLoaded={ setImageSize }
/>
</div>
<RangeControl
Expand All @@ -268,7 +268,7 @@ export default function ImageEditor( {
value={ zoom }
onChange={ setZoom }
/>
</div>
</>
) : (
children
) }
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ export default function Image( {
url={ url }
setAttributes={ setAttributes }
isSelected={ isSelected }
naturalWidth={ naturalWidth }
naturalHeight={ naturalHeight }
width={ width }
height={ height }
>
{ img }
</ImageEditor>
Expand Down

0 comments on commit 1a314dc

Please sign in to comment.