如何缩放n张图像以适应一定的宽度?
我有 3 个图像,我想在网页上水平并排放置,它们的比例不同,我希望它们最终共享特定的高度(待计算)。假设我的页面宽度是“t”,图像的当前尺寸是 h1 x w1、h2 x w2、h3 x w3
我计算出了 2 个图像的公式,但我无法理解 3 或更多的:
(h1*h2*t) / (w1*h2 + h1*w2)
I've got 3 images I want to fit on a web page horizontally side by side, they are of various proportions and I want them to end up sharing a particular height (to be calculated). So let's say the width of my page is 't' and the current dimensions of the images are h1 x w1, h2 x w2, h3 x w3
I worked out a formula for 2 images but I can't get my head around 3 or more:
(h1*h2*t) / (w1*h2 + h1*w2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须遵守的条件是:
其中
kn
是应用于宽度的缩放常数,以保持图像的原始比例及其新高度。我们可以说,
其中
h_new
是所有图像的新高度。从那里开始,一切都是替代和隔离,我认为应该是这样,如果我完全错了,请回复! :)
The condition you must respect is:
where
kn
is the scaling constant applied to the width to keep the original proportion of the image with its new height.We can say that
where
h_new
is the new height for all images. From there it's all substitution and isolationI think that should be it, reply if I'm completely wrong! :)
我用 javascript 编写了一个 Photoshop CS5 脚本,用于根据 @vache 的公式调整大小并保存打开的图像。希望有人觉得它有用:
I wrote a photoshop CS5 script in javascript to resize and save out the open images based on @vache's formula. Hope someone finds it useful: