2011-09-12 1 views
1

웹 페이지에 가로로 나란히 놓고 싶은 3 개의 이미지가 있습니다. 다양한 비율로 구성되어 있으며 특정 높이 (계산할 값)를 공유하게됩니다. 그래서 내 페이지의 너비가 't'이고 이미지의 현재 크기가 h1 x w1, h2 x w2, h3 x w3이라고 가정 해 봅시다. 두 이미지에 대한 수식을 계산했는데 내 이미지를 가져올 수 없습니다. 약 3 이상 머리 :가 존중해야특정 너비에 맞게 n 개의 이미지를 어떻게 확장합니까?

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

'특정 높이'란 무엇입니까? 나는 그것이 당신이 계산하려고하는 것이지만 그것이 무엇을 나타내는 지 이해하지 못한다는 것을 알고 있습니다. 여전히't'에서 피팅하면서 가능한 가장 큰 높이? – Vache

+0

@Vache 예, 여전히 가장 큰 높이입니다. –

답변

4

조건이다 kn는 새로운 높이 이미지의 원래의 비율을 유지하기 위해 폭에인가되는 스케일링 상수이다

k1*w1 + k2*w2 + ... + kn*wn = t 

.

우리는

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) 

내가 완전히 틀렸다면 답장해야한다고 생각합니다! :)

+0

감사합니다. –

+0

그건 내게 맞는 것 같아. – Chris

1

@ vache의 수식을 기반으로 열린 이미지의 크기를 조정하고 저장하기 위해 javascript에 Photoshop 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); 
    } 
}