r-bin escreveu Resize is done in any cases, for large and small values. And what do you want? You can do a check for the fact that the size is already fitted and do nothing. #target photoshop var d = new Window("dialog", "Fit Image CM", {x:0, y:0, width:260, height:105} ,{closeButton: true}); ctd_gp = d.add("group", {x:5, y:-10, width:260, height:105}); edt_w = ctd_gp.add("edittext", {x:53, y:25, width:50, height:10}, " 25,5"); // Set a size W txt_w = ctd_gp.add("statictext", {x:10, y:30, width:120, height:10}, " Width: cm"); edt_h = ctd_gp.add("edittext", {x:53, y:55, width:50, height:10}, " 15"); // Set a size H txt_h = ctd_gp.add("statictext", {x:10, y:60, width:120, height:10}, " Height: cm"); fit_bt = ctd_gp.add("button", {x:150, y:25, width:93,height:25}, "Fit", { name: "ok"}); // your new code ////////// var doc = activeDocument; app.preferences.rulerUnits = Units.CM; edt_w.text =(doc.width.value.toFixed(2)); edt_h.text =(doc.height.value.toFixed(2)); ////////////////////////// fit_bt.onClick = function() { try { if (!app.documents.length) return; var fit_w = Number(edt_w.text.replace(/,/g, ".")); if (fit_w <= 0 || isNaN(fit_w)) { alert("wrong W"); return; } var fit_h = Number(edt_h.text.replace(/,/g, ".")); if (fit_h <= 0 || isNaN(fit_h)) { alert("wrong H"); return; } var old_units = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.CM; var w = Number(activeDocument.width.value); var h = Number(activeDocument.height.value); var w1; var h1; if (w/h > fit_w/fit_h) w1 = fit_w; else h1 = fit_h; d.close(); if ((w1 && Math.round(w*100)/100 != Math.round(fit_w*100)/100) || (h1 && Math.round(h*100)/100 != Math.round(fit_h*100)/100)) activeDocument.resizeImage(w1, h1); else alert("Already fitted!", "Warning") w = Number(activeDocument.width.value); h = Number(activeDocument.height.value); w = Math.round(w*100)/100; h = Math.round(h*100)/100; app.preferences.rulerUnits = old_units; if (w > fit_w || h > fit_h) { alert("Fit to:\t" + fit_w + " x " + fit_h + "\n\nResult:\t" + w + " x " + h, "Fit problem"); } } catch (e) { alert(e); } } d.center(); d.show(); What did not work for you I did not understand. That's right, I would like to scale for small and large values, nothing more! Thank you
... View more