I'm trying to create a mural designer where the user can choose or upload an image. The user can set the dimension of a virtual wall and zoom or move the image over this wall. My problem is I want that when the image width is smaller than the height, the width of the image fits exactly the width of the wall (at least when the user chooses or uploads the image). The other case is when the height of the image is smaller than the width I want that the height of the image fits exactly the height of the wall. I can achieve that for the first case but not for the second case. The problem is not to know if the height or width is smaller but my problem is to fit the height of the image to the height of the wall when this height is smaller than the width. I'm using react, antd and MapInteractionCSS (for zoom and move) libraries. Here is my App.js code:
<SquareDraw height={dim.height} width={dim.width} rate={dim.rate}>
<MapInteractionCSS
value={zoom.value}
onChange={(value) => setZoom({ value })}
>
<img alt="" style={{width: '100%', height: 'auto'}} src={files.previewImage} />
</MapInteractionCSS>
</SquareDraw>
I'm just showing the code of the virtual wall. And the SquareDraw component:
import React from 'react'
export const SquareDraw = (props) => {
return (
<div
style={{
border: '1px solid grey',
width: `${props.height > props.width ? (('350').toString() / 15) * props.rate + 'em' : '23.333em'}`,
height: `${props.width > props.height ? (('350').toString() / 15) * props.rate + 'em' : '23.333em'}`}}
>
{props.children}
</div>
)
}
The problem is the image does not fit the heigth to the virtual wall. This is the image:
And this is the result of choosing the image:
I just want the height of the image to be equal to the height of the virtual wall.
If I set the object-fit attribute to contain I see it like this:
Does anyone know how can I do that? If something is not explained correctly please tell me. Thanks!!