<img> 根据原始图像大小调整图片大小



在使用引导程序的react应用程序中获取要在标记中使用的图像文件时,有时我会在大图像容器中看到一个小图像,这看起来很糟糕。因此,我想得到原始图像的大小,如果太小,请根据其原始高度和宽度进行缩放。图像保存在react应用程序的服务器中;上传/图像";。例";上传/images/John_Doe.png";,并且图像源包含在变量"0"中;user.pfp";

<img className="mx-auto d-block" src={user.pfp} style={{maxWidth:'400px', maxHeight:'325px', scale: {*user.pfp height < 100 pixels and user.pfp width < 100 pixels* ? "200%" : "100%"}} />

我不知道如何根据图像源找到原始图像的高度和宽度,以确定是否需要缩放。

当我们讨论这个主题时,我对react和html图像容器是个新手。"的正确语法是什么;小于";以及";以及";在这种情况下?

<p><img src="image/example.jpg" alt="Example1" width="193" height="130"> (width:193px, height:130px)</p>
<p><img src="image/example.jpg" alt="Example2" width="96" height="65"> (width:96px, height:65px)</p>
<p><img src="image/example.jpg" alt="Example3" width="100%" height="130"> (width:100%, height:130px)</p>

来源:www.tagindex.net

最新更新