Copy link to clipboard
Copied
I’d like to create a Photoshop action to automatically fill a selection with another image and scale the image to fit to cover the selection.
For example, I’d like the action to fill a circle with the image below.
I tried defining a pattern, but I wasn’t able to find a script that would either create a single instance of the pattern or scale the pattern down to cover the selection.
Is there a pattern script that will scale a pattern to fit to cover a selection?
Or will another Photoshop tool do this?
Copy link to clipboard
Copied
You may need to write a custom script. You can get the size by selection.bounds and then get the fill bounds (say, another layer) using layer.bounds then scale with layer.resize().
Copy link to clipboard
Copied
One thing you could do is clip the circle layer to the image layer and then resize the image layer to cover (in either order). Scaling to cover means you calculate the scale factor to match both height and width and then take the maximum. When doing this, I typically scale it an extra pixel on each side to prevent anti-aliased edges from showing up in the clipped area. Below is the scriptListener function that clips the active layer to the one below.
function ClipActiveLayer() {
var d = new ActionDescriptor()
var r = new ActionReference()
r.putEnumerated( chID( "Lyr " ), chID( "Ordn" ), chID( "Trgt" ) )
d.putReference( chID( "null" ), r)
executeAction( chID( "GrpL" ), d, DialogModes.NO )
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Or will another Photoshop tool do this?
Data-driven graphics can automatically scale to layer bounds, but I am not aware if scripts can utilize this feature. This functionality can certainly be applied manually or by using a pre-existing data list, especially when aiming to populate a defined area with multiple pre-prepared images.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now