有没有办法动态定义图像在页面或特定布局中的显示方式?
长期以来,我在管理高度或宽度异常长的图像时遇到了问题。
如果我固定它们的高度和宽度,它们会显得拉长吗?
如果我固定它们的宽度,并且图像的高度很长,那么它也会弄乱整个网站。
如果我固定它们的高度,并且图像的宽度很长,那么它也会弄乱整个网站。
我保存在本地驱动器中的图像是否保持比例保存? 假设用户决定上传图像 1(高度)* 32(宽度)。 当他上传这张图片时,脚本将用户上传的图片大小调整为高度:1000px(只是一个例子),
所以生成的图片为1000px(高度)* 32000(宽度),你看到现在图像异常大。
现在,当在 1000px * 1000px 的框中显示此图像时,显示此图像的最佳方式是什么?
For so many time, I have encountered problems with managing image having abnormally long height or width.
If I fixed their height and widht, they will appear streched?
If I fixed their width, and if the height of the image is very long then also it will mess up the overall website.
If I fixed their height, and if the width of the image is very long then also it will mess up the overall website.
The images I save in the local drive are saved maintaining the ratio?
Let say user decides to upload image 1(height)*32(width).
When he uploads this image, the script is made to resize the user uploaded image to height:1000px(just an example)
So the resulting image in 1000px(height)*32000(widht), you see now the image is abnormally large.
Now while displaying this image in a box of 1000px * 1000px, what is the best way to display this image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您尝试调整 32x1 图像的大小以使其适合 1000x1000 的框,则不应将高度调整为 1000。相反,您应该将宽度调整为 1000,将高度调整为 1000/32。
一些示例代码可以是:
这检查哪个尺寸相对于盒子的尺寸“更大”,并适当地设置 $new_width 和 $new_height 。确保处理其中一个维度四舍五入为 0 的奇怪情况(即 10000x1 图像可能最终为 1000x0)。
If you're trying to resize the 32x1 image so it fits within a 1000x1000 box, you shouldn't be resizing the height to be 1000. Instead, you should resize the width to 1000 and the height to 1000/32.
Some example code could be:
This checks which of the dimensions is "bigger" relative to the dimensions of the box and sets $new_width and $new_height appropriately. Make sure to handle weird cases where one of the dimensions gets rounded down to 0 (ie. a 10000x1 image would probably end up as 1000x0).
如果我理解正确的话你想保持这个比例。那么为什么不使用一些图像库来缩放图像的高度或宽度并保持比例。
If I understand correctly you want to keep the ratio. So why don't you use some image library to scale the image on either height or width and keep ratio.
如果改变比例,它们就会扭曲;如果改变大小,它们就会拉伸。
图像将缩放,保持其原始 xy 比例。这是否“搞乱网站”取决于上下文。
同上
这取决于许多因素,其中最重要的是图像的目的是什么。是的,我们又回到了上下文。
如果我对您想要实现的目标做出一些假设,您基本上有两个选择:
They'll be distorted if you change the ratio, and stretched if you change the size.
The image will scale, keeping its original x-y ratio. Whether or not this "messes up the website" depends on the context.
Ditto
That depends on a number of factors, not least of which is what the purpose of the images is. Yes, we're back to context again.
If I make some assumptions about what you are trying to achieve, you essentially have two options:
尝试将输出图像适合(保持纵横比)在特定的矩形中怎么样?
What about trying to fit (keeping the aspect ratio) the output image in a specific rectangle?
您可以将
div
与overflow:hidden;
一起使用。You can use a
div
withoverflow: hidden;
.