我有3张图片想在网页上水平放置,它们的比例各不相同,我希望它们共享一个特定的高度(待计算)。所以,假设我的页面宽度为't',图像的当前尺寸为h1 x w1,h2 x w2,h3 x w3如何缩放n张图片以适合某个宽度?
我制定了2张图片的公式,但无法获取我的图片头部周围3个或更多:
(h1*h2*t)/(w1*h2 + h1*w2)
我有3张图片想在网页上水平放置,它们的比例各不相同,我希望它们共享一个特定的高度(待计算)。所以,假设我的页面宽度为't',图像的当前尺寸为h1 x w1,h2 x w2,h3 x w3如何缩放n张图片以适合某个宽度?
我制定了2张图片的公式,但无法获取我的图片头部周围3个或更多:
(h1*h2*t)/(w1*h2 + h1*w2)
您必须遵守的条件是:
k1*w1 + k2*w2 + ... + kn*wn = t
其中kn
是适用于宽度,保持图像的原始比例,其新的高度比例常数。
我们可以说,
kn = h_new/hn
其中h_new
是所有图像的新的高度。从那里它的全部替代和隔离
h_new*w1/h1 + h_new*w2/h2 + ... + h_new*wn/hn = t
h_new * (w1/h1 + w2/h2 + ... + wn/hn) = t
h_new = t/(w1/h1 + w2/h2 + ... + wn/hn)
我认为应该是这样,如果我完全错了,回复! :)
谢谢,就是这样! –
这对我来说很合适。 – Chris
我在javascript中编写了一个photoshop CS5脚本来调整和存储基于@ vache的公式的打开图像。希望有人认为它有用:
var outputFolder = Folder.selectDialog("Select a folder for the output files")
if(outputFolder != null) {
var startRulerUnits = app.preferences.rulerUnits
var startDisplayDialogs = app.displayDialogs
// Set Adobe Photoshop CS5 to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS
app.displayDialogs = DialogModes.NO
do {
var totalWidth = parseInt(prompt("How wide do they need to fit into?", 844));
}
while(totalWidth <= 0 || isNaN(totalWidth));
var DL = documents.length;
var totalArea = 0;
for(a=0;a<DL;a++){
var cur = documents[a];
totalArea += cur.width/cur.height;
}
var newHeight = totalWidth/totalArea;
for(a=1;a<=DL;a++){
activeDocument = documents[a-1];
var AD=activeDocument;
// bring to front
app.activeDocument = AD;
AD.changeMode(ChangeMode.RGB);
var imgName= AD.name.toLowerCase();
imgName = imgName.substr(0, imgName.length -4);
AD.flatten();
AD.resizeImage(null,UnitValue(newHeight,"px"),null,ResampleMethod.BICUBIC);
//AD.resizeImage(UnitValue(newWidth,"px"),null,null,ResampleMethod.BICUBIC);
saveForWeb(outputFolder, imgName, AD);
}
// Close all the open documents
while (app.documents.length) {
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES)
}
// Reset the application preferences
app.preferences.rulerUnits = startRulerUnits;
app.displayDialogs = startDisplayDialogs;
}
function saveForWeb(outputFolderStr, filename, AD)
{
var opts, file;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.JPEG;
opts.quality = 80;
if (filename.length > 27) {
file = new File(outputFolderStr + "/temp.jpg");
AD.exportDocument(file, ExportType.SAVEFORWEB, opts);
file.rename(filename + ".jpg");
}
else {
file = new File(outputFolderStr + "/" + filename + ".jpg");
AD.exportDocument(file, ExportType.SAVEFORWEB, opts);
}
}
那是什么'特定高度?我知道这是你想要计算的东西,但我不明白它应该代表什么。尽可能最大的高度,同时仍然符合't'? – Vache
@Vache是的,这是最大的高度仍然适合t –