Skip to main content
abhis53409866
Participant
August 4, 2021
Question

AppleScript using pixels for scaling layer

  • August 4, 2021
  • 2 replies
  • 471 views

Ive been using AppleScript to automate a template file but I need to resize a pasted image layer. I went through the guid and couldnt find anything. Is there any way to resize/scale a layer with pixels rather than percentages? Pasted current code snippets below

 

tell application "Adobe Photoshop 2021"
	set ruler units of settings to pixel units
	set type units of settings to pixel units 
	set AlbumArt to layer "Layer 5" of layer set "Title" of current document
	set name of AlbumArt to "Album Artwork"
	move AlbumArt to layer set "Album Art" of current document
	set AlbumArt to layer "Album Artwork" of layer set "Album Art" of current document
	set AlbumArt to current layer of current document
	set scaleSet to {horizontal scale: 500 , vertical scale: 500}
	scale of current layer of current document with scaleSet

end tell

 

 

This topic has been closed for replies.

2 replies

Stephen Marsh
Community Expert
Community Expert
August 9, 2021

You can turn the layer into a smart object.

 

Edit the smart object layer.

 

Resize using fit image or image size, with resampling using px.

 

Close and save the smart object layer.

 

Adjust position of the smart object layer (you can load a selection before converting to smart object, then align back to the original selection as required).

 

Rasterize or convert to layers on the smart object layer.

 

All of this can be scripted or recorded into an action in px.

Legend
August 4, 2021

I do not use AppleScript, but problem is easy to solve - get the bounds of the layer, calculate its width or height, and then just find out how many percent you need to change this value to get the size you want. In JS, it would look like this:

 

var scaleInPercent = 500/(activeDocument.activeLayer.bounds[2].value-activeDocument.activeLayer.bounds[0].value)*100

 

 * units are set to pixels
** layer bounds are usually encoded as an array of 4 points: [left, top, right, bottom] 

abhis53409866
Participant
August 4, 2021

Thanks for the reply, this is basically what I ended up doing. Just got the bounds of the pasted layer and scaled it by a factor that I got by dividing the size I needed.