Here's the way I did it with scripts, not many people may be fans of them, but they worked for me. Check the comments in code for details.
- To use the script copy the code into notepad (or another plain text editor) and save as a *.jsx file.
- In Photoshop create a action where you go to File -> Scripts -> Browse... and locate the *.jsx file you created earlier.
- Next record saving the file and closing the document.
Then File -> Automate -> Batch... to loop through a folder with the action you created.
var doc = app.activeDocument;
var layer = doc.activeLayer;
var group = layer.parent.layers;
// get document width and height
var w = doc.width.toString().replace(' px', '')
var h = doc.height.toString().replace(' px', '')
if ( w/h == 4/3 ) { //if the image ratio is exactly 4:3
//just resize to 1280x960
doc.resizeImage(1280,960,null,ResampleMethod.BICUBIC);
} else if ( w/h > 4/3 ){ //if the image ratio is wider than 4:3
//create two layers, one for the blurry background and the other one on top of it
layer.duplicate()
layer.duplicate()
group[1].name = 'bkg';
group[0].name = 'top';
//crop to a 4:3 ratio
var bounds = [ 0, -(w/4*3-h)/2, w, w/4*3-(w/4*3-h)/2];
doc.crop(bounds);
//clear the background with the image fitting the canvas
var black = new SolidColor();
black.rgb.red = black.rgb.green = black.rgb.blue = 0;
doc.selection.selectAll();
doc.selection.fill( black );
doc.selection.clear();
//scale the background image to fill the canvas
doc.activeLayer = doc.artLayers.getByName("bkg");
var scaleFactor = doc.height.toString().replace(' px', '')/h*100
var userResampleMethod = app.preferences.interpolation;
app.preferences.interpolation = ResampleMethod.BILINEAR;
activeDocument.activeLayer.resize(scaleFactor, scaleFactor, AnchorPosition.MIDDLECENTER);
app.preferences.interpolation = userResampleMethod;
//resize the document to 1280x960
doc.resizeImage(1280,960,null,ResampleMethod.BICUBIC);
//gaussian blur the background by 20px
gaussianBlur(20);
} else if ( w/h < 4/3 ){ //if the image ratio is taller than 4:3
//create two layers, one for the blurry background and the other one on top of it
layer.duplicate()
layer.duplicate()
group[1].name = 'bkg';
group[0].name = 'top';
//crop to a 4:3 ratio with the image fitting the canvas
var bounds = [-(h/3*4-w)/2, 0, h/3*4-(h/3*4-w)/2, h];
doc.crop(bounds);
//clear the background
var black = new SolidColor();
black.rgb.red = black.rgb.green = black.rgb.blue = 0;
doc.selection.selectAll();
doc.selection.fill( black );
doc.selection.clear();
//scale the background image to fill the canvas
doc.activeLayer = doc.artLayers.getByName("bkg");
var scaleFactor = doc.width.toString().replace(' px', '')/w*100
var userResampleMethod = app.preferences.interpolation;
app.preferences.interpolation = ResampleMethod.BILINEAR;
activeDocument.activeLayer.resize(scaleFactor, scaleFactor, AnchorPosition.MIDDLECENTER);
app.preferences.interpolation = userResampleMethod;
//resize the document to 1280x960
doc.resizeImage(1280,960,null,ResampleMethod.BICUBIC);
//gaussian blur the background by 20px
gaussianBlur(20);
}
function gaussianBlur(amount){
var idGsnB = charIDToTypeID( "GsnB" );
var desc2 = new ActionDescriptor();
var idRds = charIDToTypeID( "Rds " );
var idPxl = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( idRds, idPxl, amount );
executeAction( idGsnB, desc2, DialogModes.NO );
}