2

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)

The steps to achieve desired result

image credits: https://itunes.apple.com/us/app/id603106194

2
  • Should be doable with Action.
    – Joonas
    Dec 1, 2015 at 23:44
  • Are they all the same orientation, say, portrait? If some have the short side longer than "3" are you willing to crop it evenly from both sides?
    – user45605
    Dec 2, 2015 at 0:21

2 Answers 2

1

Maybe this isn't the most bulletproof method, but you could do something like this.

Record an Action like this:

  1. Layer > New > Layer from background...
    • ( Hold down alt when clicking so it doesn't ask you anything. Not that it matters, really. )
  2. File > Automate > Fit image.... Give it your desired document width and height ( I used 500x375px ).
  3. Layer > Duplicate layer... - Duplicate: New ( no need to give it a name )
  4. Image > Image size... - Click the chain to unlock aspect ratio. Insert the desired width document width ( I used 500px ).
  5. Select > All
  6. Edit > Copy
  7. File > Close - Close without saving.
  8. 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. )
  9. Edit > Paste
  10. Layer > New > Background from layer
  11. 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 ):

  1. Layer > New > Layer from background...
    • ( Hold down alt when clicking so it doesn't ask you anything. Not that it matters, really. )
  2. File > Automate > Fit image.... Give it your desired document width and height.
  3. 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. )
  4. Layer > New > Layer via copy - This is for the middle (why not..)
  5. Layer > New > Layer via copy - This is for the left side
  6. Select > All
  7. Layer > Align layers to selection > Left edges
  8. Layer > New > Layer via copy - This is for the right side
  9. Select > All
  10. Layer > Align layers to selection > Right edges
  11. Select > Deselect
  12. Layer > Merge down
  13. Layer > Merge down
  14. Layer > New > Background from layer
  15. Filter > Blur > Gaussian blur...

Both actions can be downloaded here

2
  • This is a great answer! I'll make your answer the right one even though I was on a tight schedule last night and went about with scripts instead of Actions as I wasn't sure how to achieve all this while maintaining usability on different resolutions (This does however need to be used only on portrait photos, not landscape/ or wider than 4:3). Thanks again! Dec 2, 2015 at 10:15
  • Edited the answer to include the stretch method and a link to both actions.
    – Joonas
    Dec 2, 2015 at 11:16
1

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.

  1. To use the script copy the code into notepad (or another plain text editor) and save as a *.jsx file.
  2. In Photoshop create a action where you go to File -> Scripts -> Browse... and locate the *.jsx file you created earlier.
  3. 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 );  
}
1
  • 1
    I find it interesting that tackled this with a script. Nothing wrong with that. More flexible in the long run. By the way, you can get document dimensions as a number value like this: app.activeDocument.width.value
    – Joonas
    Dec 2, 2015 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.