: Batch fit images into ratio with blurred background I need to resize a lot of images into a 4:3 ratio with the desired effect. Is there a way to do this using photoshop actions? (the background
I need to resize a lot of images into a 4:3 ratio with the desired effect.
Is there a way to do this using photoshop actions? (the background can be scaled or two copies moved to the sides, either way works)
image credits: itunes.apple.com/us/app/id603106194
More posts by @Yeniel278
2 Comments
Sorted by latest first Latest Oldest Best
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 );
}
Maybe this isn't the most bulletproof method, but you could do something like this.
Record an Action like this:
Layer > New > Layer from background...
( Hold down alt when clicking so it doesn't ask you anything. Not that it matters, really. )
File > Automate > Fit image.... Give it your desired document width and height ( I used 500x375px ).
Layer > Duplicate layer... - Duplicate: New ( no need to give it a name )
Image > Image size... - Click the chain to unlock aspect ratio. Insert the desired width document width ( I used 500px ).
Select > All
Edit > Copy
File > Close - Close without saving.
Image > Canvas size.... Give it the desired width ( I used 500px )
If you want Canvas size to set both width and height: Stop recording the action, undo the last resize, start recording again and apply the canvas size. ( Because fit image sets either the width or height to what ever size you give it, the Action will only record one of those values when you try to resize the canvas, which might not be desirable. )
Edit > Paste
Layer > New > Background from layer
Filter > Blur > Gaussian blur...
Then to run it on bunch of images: File > Scripts > Image processor... and give it your action to run.
...or File > Automate > Batch...
Alternative action that uses copies of the original image, aligns them to fill the document sided and then blurs that ( Slightly different end result and a bit less bulletproof ):
Layer > New > Layer from background...
( Hold down alt when clicking so it doesn't ask you anything. Not that it matters, really. )
File > Automate > Fit image.... Give it your desired document width and height.
Image > Canvas size.... Give it the width, just like before.
If you want Canvas size to set both width and height: Stop recording the action, undo the last resize, start recording again and apply the canvas size. ( Because fit image sets either the width or height to what ever size you give it, the Action will only record one of those values when you try to resize the canvas, which might not be desirable. )
Layer > New > Layer via copy - This is for the middle (why not..)
Layer > New > Layer via copy - This is for the left side
Select > All
Layer > Align layers to selection > Left edges
Layer > New > Layer via copy - This is for the right side
Select > All
Layer > Align layers to selection > Right edges
Select > Deselect
Layer > Merge down
Layer > Merge down
Layer > New > Background from layer
Filter > Blur > Gaussian blur...
Both actions can be downloaded here
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.