I imported multiple images to make a GIF. The problem is, that the images have multiple resolutions. How can I automatically scale all images to fit the canvas?Screenshot of my layers and the different images, I hope you see them


This is a case where you want to use a script to read the size & position of each layer's bounds so that it can dynamically transform them.

To use this script, copy the code into a plain text document, save, then rename the extension .txt -> .jsx

You can then drag the jsx into Photoshop to run it.


  • What you're asking for may noticeably stretch some layers if they differ a lot from the canvas size.
  • This script is untested. Backup your files before trying it on them just in case.
var doc = activeDocument

preferences.rulerUnits = Units.PIXELS

var layers = doc.artLayers
var lenLayers = layers.length

for( var i=0; i<lenLayers; i++ ) {  // Loop thru each layer

  var layer = layers[i]

  var bounds = layer.bounds // Bounds is a rectangle [x1,y1,x2,y2]

  // Move to top-left corner
  layer.translate( -bounds[0], -bounds[1] ) 

  // Calculate percent scaling from layer bounds to document (canvas)
  var resizePercentWidth = doc.width / ( bounds[2] - bounds[0] ) * 100
  var resizePercentHeight = doc.height / ( bounds[3] - bounds[1] ) * 100

  layer.resize( resizePercentWidth, resizePercentHeight, AnchorPosition.TOPLEFT )

If you're interested in learning scripts like this, here are resources to start with:

  • 1
    don't forget to multiply resizePercentWidth and resizePercentHeight by 100 (you're getting ratio, not percents) and restore user's rulerUnits – Sergey Kritskiy Mar 22 '20 at 23:34
  • Thanks Sergey, I've edited the post. – Nick Combs Mar 22 '20 at 23:38
  • I also found a script. I used the script Fit Layer To Canvas from jawinn. Since the script is only for the active layer I tried to change it to apply to all layers. The script from jawinn: gist.github.com/jawinn/ab4df1c33d0743e41fd3 yours seems to do the trick on all layers. Thanks a lot! Best regards – Luis Mar 24 '20 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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