Crop to Ratio & Resize To Fill

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: Tom, Kukurykus

whome

Crop to Ratio & Resize To Fill

Post by whome »

I have written a PS script to crop an image to a desired ratio like 2/3 and then optionally resize it to fill (not fit like the Image Processor) to a desired size . The source image is the currently active file opened is PS. The script takes into consideration the orientation of your source image so you don't have to worry if it is portrait or landscape. If the source image is square you will end up with the same aspect ratio as the destination. I added a UI which stores your last used settings in a file called CropRatioResizeFill.dat stored in your home directory. When running the script during an action your settings are saved to the action and used the next time the action is run (thanks to X for the code to do that).

If you aren't resizing the images then the destination width and height don't have to be actual pixel dimensions; they can be a ratio like 2/3.

Enjoy

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

whome

Crop to Ratio & Resize To Fill

Post by whome »

Here's the file.
xbytor

Crop to Ratio & Resize To Fill

Post by xbytor »

I noticed a slight problem in your script.

Code: Select allfunction isInteger(a) {
    return typeof a == 'number' && isFinite(a);
}

function isDouble(a) {
    return typeof a == 'number' && !isFinite(a);
}

isInteger(2); // true
isInteger(2.0) // true?
isDouble(2); // false
isDouble(2.0) // true?


isInfinite does not do what you think it does.

One implementation would be:
Code: Select allfunction isInteger(a) {
    return typeof a == 'number' && Math.floor(a) == Math.ceil(a);
}

function isDouble(a) {
    return typeof a == 'number' && Math.floor(a) != Math.ceil(a);
}

Another would be:
Code: Select allfunction isInteger(a) {
    return typeof a == 'number' && a.toString().indexOf('.') == -1;
}

function isDouble(a) {
    return typeof a == 'number' && a.toString().indexOf('.') != -1;
}

Of course, I may be completely off base here.

-X