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?
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.
Notes:
- 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:
-
1don't forget to multiply
resizePercentWidth
andresizePercentHeight
by 100 (you're getting ratio, not percents) and restore user'srulerUnits
– Sergey Kritskiy Mar 22 '20 at 23:34 -
-
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