1

Webページに水平に並べて配置したい3つの画像があります。それらはさまざまな比率であり、最終的に特定の高さ(計算対象)を共有するようにします。たとえば、ページの幅が「t」で、画像の現在のサイズがh1 x w1、h2 x w2、h3xw3であるとします。

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

@vacheの式に基づいて、開いている画像のサイズを変更して保存するために、JavaScriptでフォトショップCS5スクリプトを作成しました。誰かがそれが役に立つと思うことを願っています:

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 に答える