Copy link to clipboard
Copied
I have a client who wants a minimum size for all images of 4500 x 2800 pixels at 300dpi. This applies wether they are vertical or horizontal.
I've tried everything- Fit to Image, Image Processor (& Pro) Lightroom & Bridge. I think it can only be done in a script, which would be something like:
Find longest edge
If < 4500 pxl then make = 4500
Scale Proportionally
Find shortest edge
If <2800 pxl then make = 2800
Scale proportionally
I'm still trying to learn scripting, but would this work & does know the correct terminology?
Matt
Copy link to clipboard
Copied
Unclear.
What should be the final file if the original file has a size, for example, 8000x2000?
Copy link to clipboard
Copied
So if it was 8000 x 2000, then I figured this would deal with it:
Find shortest edge
If <2800 pxl then make = 2800
Scale proportionally
and make the 2000 to 2600 & scale proportionally so final image would be 10400 x 2600?
Matt
Copy link to clipboard
Copied
Why you changed 2000 to 2600 if minimum length of shorter edge had to be 2800? Is it some additional calculation you didn't mention in your original post? Otherwise 2000 * 8000 should result as 2800 * 11200, shouldn't it?
Copy link to clipboard
Copied
My mistake- meant to write 2800 not 2600.
I think the script from piotrf87808300 will do it.
Matt
Copy link to clipboard
Copied
You can create an action with conditional method.
The reflection of r-bin is consistent
so with files of variable sizes you can not get the result
4500 x 2800
Copy link to clipboard
Copied
Apologies, but what does "The reflection of r-bin is consistent" mean?
Matt
Copy link to clipboard
Copied
He wants to say that r-bin has made a right observation.
Copy link to clipboard
Copied
var maxWidth = 4500
var maxHeight = 2000
var Resolution = 300
var doc = app.activeDocument
if( doc.width/doc.height >= maxWidth/maxHeight ){
$.writeln("a")
var proportion = doc.height/doc.width
var newWidth = maxWidth
var newHeight = maxWidth * proportion
}
else{
var proportion = doc.width/doc.height
var newWidth = maxHeight * proportion
var newHeight = maxHeight
}
$.writeln([proportion,doc.width, doc.height])
ResizeImage(newWidth, newHeight, Resolution)
function ResizeImage(x, y , res){ //[width , height, resolution]
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc3167 = new ActionDescriptor();
desc3167.putUnitDouble( cTID('Wdth'), cTID('#Pxl'), x );
desc3167.putUnitDouble( cTID('Hght'), cTID('#Pxl'), y );
desc3167.putUnitDouble( cTID('Rslt'), cTID('#Rsl'), res );
desc3167.putEnumerated( cTID('Intr'), cTID('Intp'), sTID('bicubicAutomatic') );
executeAction( cTID('ImgS'), desc3167, DialogModes.NO );
};
Copy link to clipboard
Copied
Your script doesn't work a way matthew_shaw wanted. It resizes image proportionally indeed, but only once. There's also mistake - should be 2800, not 2000. He also did not want larger lengths to be resized down, but only smaller legths up...
Copy link to clipboard
Copied
Try a code I created changing other my code from this theard: Get pixel layer properties?
(function IC(v) {
r = !~~((wh = [(aD = activeDocument).width, aD.height])[+!!v] / wh[+!v])
if (wh
< (_ = v || 4500)) eval("aD.resizeImage(" + (r ? 'null, ' : '') + "_)"); if (!v) IC(2800)
})()
EDIT: I forgot earlier about case when PIXELS ruleUnits are not chosen, as well as resolution:
preferences.rulerUnits = Units.PIXELS; (function IC(v) {
r = !~~((wh = [(aD = activeDocument).width, aD.height])[+!!v] / wh[+!v]); if (wh
< (_ = v || 4500)) { eval('aD.resizeImage(' + (r ? 'null, ' : '') + '_' + (r ? '' : ', null') + ', 300)'); if (!v) IC(2800)
}
})()
Copy link to clipboard
Copied
In terms of the algorithm you never need to scale twice.
How about: work out XScale: target X size / actual X size and YScale: target Y size / actual Y size.
If both are greater than or equal to 1.0, nothing need be done, the file is smaller than the limit.
Otherwise, find the lower of XScale and YScale, then scale by that one amount, proportionally.
This is very similar to what you propose, except it doesn't do the work until it's finished calculating.