Photoshop: Action to transform placed image to specific pixel dimensions?

  • 1
  • Question
  • Updated 1 week ago
  • (Edited)
I would be grateful to learn from users here how to solve this problem.

I need an Action which will scale a placed image *proportionally* to a specific pixel dimension along one side *regardless of the original size*.

Recording the Transform  to an Action always results in percentages for height and width instead of pixels, which will only work if the originals are the same size, which mine aren’t.

Does anyone here know a way around this?
Photo of Philip King

Philip King

  • 35 Posts
  • 3 Reply Likes

Posted 2 weeks ago

  • 1
Photo of Gary Cawood

Gary Cawood

  • 15 Posts
  • 5 Reply Likes
I do what I think you are talking about by saving jpg or tiff files in Camera Raw.

Photo of Philip King

Philip King

  • 35 Posts
  • 3 Reply Likes
Thanks Jeff, I’ve just had a look at frames at your suggestion and it actually gets most of the way to what I need. There doesn’t seem to be any fitting rules (such as in InDesign), and the fitting doesn't scale up, only down, but the vast majority of my source images would scale down anyway. I do hundreds of these, so this workflow could save a lot of tedious resizing.
Photo of JEFF LAMBERT

JEFF LAMBERT

  • 37 Posts
  • 15 Reply Likes
hey Philip, I'm glad it's working. I too was looking for fitting options like InDesign, but there is nothing. I was wondering why you need to do this in the first place though. I've used Lightroom Classic when I have a lot of images that I want to crop and have at the same pixel width. Maybe another workflow for you to checkout.
Photo of Philip King

Philip King

  • 35 Posts
  • 3 Reply Likes
Hi Jeff, the images I work with arrive in various sizes and aspect ratios and my task is to output each image in a set of different specific sizes and aspect ratios. So for each image I have one master where I do all the edits and adjustments, and then import-linked into template files where I crop to the various ratios. So I edit the master PSDs and can update the cropped versions in batches. Adding frames to my templates is going to save a step, which will make a difference over hundreds of images.
Photo of JEFF LAMBERT

JEFF LAMBERT

  • 37 Posts
  • 15 Reply Likes
ok, I do something like that but use Lightroom Classic. I do virtual copies for the different crops/ratio but use a PSD so if I update the PSD, all photos update but keep the crop. Then I can decide the output size in pixels. It can even scale them up if needed. If you have the same ratio, but different size, you can just have one virtual copy with the right ratio, but output to many sizes. And it's really easy to just export again if you have any last-minute changes.
Photo of Anthony Edge

Anthony Edge

  • 100 Posts
  • 11 Reply Likes
Sounds like IrfanView might be an option... https://www.irfanview.com/
Photo of David Converse

David Converse

  • 888 Posts
  • 258 Reply Likes
Scaling requires a percentage. You could use a small script which calculated percentage from the image dimensions.
Photo of Philip King

Philip King

  • 35 Posts
  • 3 Reply Likes
Hi David, thanks for the reply. The transform settings in the options ribbon certainly takes a figure in pixels, I use it every day. The problem is that the pixel figure isn't recorded in the action but converted to a percentage. My hope was that there was a way to insert pixels into the action, but I’ll look at your suggestion of a script (although I have no idea where to start with creating one).
Photo of Gary Cawood

Gary Cawood

  • 14 Posts
  • 3 Reply Likes
I center images on a white background for printing via image and canvas size tools under Image in Photoshop.  The align tool might be of use to you also.
Photo of David Converse

David Converse

  • 888 Posts
  • 258 Reply Likes
You'll need to do some work on this to pick the right layer and determine long side but this is functional.

layerUpdate();

function layerUpdate(){
    if(documents.length > 0){
        var originalDialogMode = app.displayDialogs;
        app.displayDialogs = DialogModes.ERROR;
        var originalRulerUnits = preferences.rulerUnits;
        var scale = 0;
        var finished = 1500; //desired size in pixels
        var placed = [];
        try{
            var docRef = activeDocument;
            preferences.rulerUnits = Units.PIXELS;
            var LayerRef = docRef.artLayers[0]; //this gets the top layer
            placed = LayerRef.bounds; //array of four corner coordinates
            scale = (placed[2] - placed[0]); //horizontal size
            scale = finished / scale; //resize factor
            scale = scale * 100;
            LayerRef.resize(scale, scale); //horizontal, vertical percentage
            }
        catch(e){
            alert(e + '  ' + e.line);
            preferences.rulerUnits = originalRulerUnits;
            app.displayDialogs = originalDialogMode;
            return;
            }
        preferences.rulerUnits = originalRulerUnits;
        app.displayDialogs = originalDialogMode;
        }
    else{
        alert('You must have a document open to run this script.');
        return;
        }
    }

Photo of Philip King

Philip King

  • 35 Posts
  • 3 Reply Likes
Thanks David, that’s very helpful. I have a week or so before the next batch arrives so I have a bit of time to experiment. I’ll let you know how I get on.
Photo of Anthony Edge

Anthony Edge

  • 100 Posts
  • 11 Reply Likes
Could your action open the original image, make the background layer (or all layers if a PSD) a smart object, resize the entire image to meet your pixel scale needs, then copy and paste the smart layer to your working document? (Close the original without saving.)
Some other combination of copying the entire linked layer and pasting into a new document and resizing, before copying back, might prove helpful.
Photo of Philip King

Philip King

  • 35 Posts
  • 3 Reply Likes
Hi Anthony, thanks for responding. I see what you're getting at but I reckon Jeff’s and David’s suggestions are closer to the sort of workflow I'm looking for.
Photo of Max Johnson

Max Johnson, Champion

  • 620 Posts
  • 332 Reply Likes
If you have a template that has your output sizes updating with linked files, you should definitely have a look at the Asset Generator. Naming your layers with .png or .jpg will let you turn on the generator and have it spit them all out into a sidecar folder automatically rather than needing to export-as. You can even specify scaling, multiple output filetypes, and compression quality in the layer name.
https://helpx.adobe.com/photoshop/using/generate-assets-layers.html

Combined with the script to 'find-replace' text in layers (see below), you can set your templates up with the frame layer named something like 'CLIENTNAME_PRODNAME_1200x600.jpg6' and replace CLIENTNAME and PRODNAME in a few seconds.
https://github.com/Paul-Riggott/PS-Scripts/blob/master/Layer%20Name%20Edit.jsx