1

我有 3 张图像我想并排放置在网页上,它们具有不同的比例,我希望它们最终共享一个特定的高度(待计算)。所以假设我的页面宽度是 't' 并且图像的当前尺寸是 h1 x w1, h2 x w2, h3 x w3

我为 2 个图像制定了一个公式,但我无法理解 3 个或更多图像:

(h1*h2*t) / (w1*h2 + h1*w2)
4

2 回答 2

4

您必须遵守的条件是:

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)

我认为应该是这样,如果我完全错了,请回复!:)

于 2011-09-12T16:21:28.293 回答
1

我在 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);
    }
}
于 2011-09-19T15:25:20.473 回答