Tom Gera
Tools for creators

Fit Layer to Canvas

A free one-click Photoshop script for scaling a layer to fit the canvas or artboard, and centring it.

PhotoshopScript

Here's a thing I do about forty times a day. I drop an image into a Photoshop comp, and it comes in the wrong size. Too big, too small, never quite right. So I want it to fit the canvas. That's it. Make this layer as big as the canvas, keep its proportions, put it in the middle.

And Photoshop, the programme that can rebuild a sky, remove a tourist and generate a whole extra metre of beach, can't do that. As far as I know there is no button for it. No menu item hidden three levels deep. You Free Transform, you drag a corner while holding your breath, you squint at the edges, you nudge it, and you align it to the centre afterwards. Every single time.

InDesign has had "Fit content proportionally" for about twenty years. After Effects has Fit to Comp under a shortcut. Photoshop, the one where you place more images than anywhere else, makes you eyeball it. It's a bit like a car with heated seats and no indicator.

So I made a script.

AAAWgmp1bWIAAAAeanVtZGMycGEAEQAQgAAAqgA4m3EDYzJwYQAAABZcanVtYgAAAEdqdW1kYzJtYQARABCAAACqADibcQN1cm46YzJwYTpmZDQyYzJmNy1lN2VlLTQwYTEtOTFmMi04ZGQ3YjY4OTcxYjEAAAADl2p1bWIAAAApanVtZGMyYXMAEQAQgAAAqgA4m3EDYzJwYS5hc3NlcnRpb25zAAAAALxqdW1iAAAARGp1bWRjYm9yABEAEIAAAKoAOJtxE2MycGEuaW5ncmVkaWVudC52MwAAAAAYYzJzaHe5mL9F6U09ZFOVVYl1gpcAAABwY2JvcqNpZGM6Zm9ybWF0bWltYWdlL3N2Zyt4bWxqaW5zdGFuY2VJRHgseG1wOmlpZDo0YjRiNGEyMy01M2E4LTQ4YWMtYTU3MS1iNmUxNzNhMjBjNjhscmVsYXRpb25zaGlwaHBhcmVudE9mAAAB4mp1bWIAAABBanVtZGNib3IAEQAQgAAAqgA4m3ETYzJwYS5hY3Rpb25zLnYyAAAAABhjMnNo/7KdG4gCRDhsE/fGTwEGmgAAAZljYm9yomdhY3Rpb25zgqJmYWN0aW9ua2MycGEub3BlbmVkanBhcmFtZXRlcnOha2luZ3JlZGllbnRzgaJjdXJseC1zZWxmI2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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQFAAHg0FbRtnwnyR8xy/onqt7qU5q3KsEHGeDluiIL4AWFcpV9Y9TB3KYn4qofowDG8alyCFLhznRNxD4N5/T9Y= Placed the wrong size Fit default Fill FILL = true or Too big, off-centre Fits inside, centred Covers it, crops sides Works on the artboard the layer sits on, too.
One click from wrong size to fitted. Flip one setting in the script for fill instead.

What it does

  • Scales the active layer proportionally until it fits the canvas, and centres it.
  • If the layer sits on an artboard, it fits that artboard instead of the whole canvas.
  • Works on pixel layers, smart objects, shapes, type: anything you can resize.
  • Want it to fill the canvas instead (cover, cropping whatever sticks out)? Open the file in a text editor and change var FILL = false; to var FILL = true;. You could also keep two copies, one of each.

Use it once

Select the layer, then File › Scripts › Browse… and pick Fit_Layer_to_Canvas.jsx.

Install it properly

  1. Put the .jsx in Photoshop's own scripts folder. On Windows that's C:\Program Files\Adobe\Adobe Photoshop (version)\Presets\Scripts, on a Mac Applications/Adobe Photoshop (version)/Presets/Scripts.
  2. Restart Photoshop. It's now under File › Scripts › Fit Layer to Canvas.
  3. Give it a shortcut: Edit › Keyboard Shortcuts, set the dropdown to Application Menus, open File › Scripts, click Fit Layer to Canvas and press the keys you want. That's where it really starts to pay off.

I have mine on a button on my Stream Deck, labelled "Scale to Fit". How to set that up is in the Instant PNG to Desktop post.

If you'd rather not touch the Program Files folder, you can also record it into an Action (File › Scripts › Browse while recording) and put a function key on the Action.

Questions

How do I fit a layer to the canvas in Photoshop?

Without a script: press Ctrl+T (Cmd+T on Mac), drag a corner until it fits, then centre it with the Align buttons. With this script: select the layer and run it, and it scales and centres it in one go.

Can it fill the canvas instead of fit?

Yes. Open the script in a text editor and change var FILL = false; to var FILL = true;. It then covers the whole canvas and crops what sticks out.

Does it work with artboards?

Yes. If the layer sits on an artboard, it fits that artboard instead of the whole document.

Can I give it a keyboard shortcut?

Yes. Put the script in Photoshop's Presets/Scripts folder, restart, and assign a shortcut under Edit › Keyboard Shortcuts › Application Menus › File › Scripts.

Free to use and share. And Adobe, if you're reading: it's eighty lines. Please just steal it.