Skip to main content
Marinapomorac
Inspiring
January 18, 2022
해결됨

Batch clipping between two folders, one with mask, one with photos

  • January 18, 2022
  • 2 답변들
  • 1800 조회

Hello:

I have folder "A" full of PNG images (200) that are actually clipping masks and folder "B" is a set of photos (200). Both sets are in identical dimensions US letter 8.5 × 11".

Is it possible to make action/script for batch processing that will take photo #1 from folder "A" and photo #1 from folder B"" and clip it, photo #2 from folder "A" and photo #2 from folder "B" and clip it, and so on?

 

I will always have new set of clipping masks and new set of photos that need to be clipped in specific way. 
Is there any way to automate this work?

Thanks in advance.

이 주제는 답변이 닫혔습니다.
최고의 답변: Kukurykus

Depending on one of described scenarios replace:

while(A.length) parng(shft = A.shift(), 'dLayerRelinkToFile'), parng(B.shift(), 'Event'),

to:

while(A.length) parng(shft = A.shift(), 'dLayerRelinkToFile'), parng(B[0], 'Event'),

or:

while(B.length) parng(A[0], 'dLayerRelinkToFile'), parng(shft = B.shift(), 'Event'),

2 답변

Kukurykus
Legend
January 18, 2022

Create on your desktop 2 folders like in your example with appropriate content: A, B

If their resolution is other than 300, then change that for example to 72 in the script.

Change in the code '*.png' chunk (for folder B) to other extension if they're not png.

Run script, wait some time and find resultant files in self created C desktop folder:

 

function crt() {
	aD.activeLayer.name = 'Bottom'; (ref = new ActionReference()).putEnumerated
	(sTT('menuItemClass'), sTT('menuItemType'), sTT('screenModeFullScreen'));
	(dsc = new ActionDescriptor()).putReference(sTT('null'), ref),
	executeAction(sTT('select'), dsc, DialogModes.NO);

	(ref = new ActionReference()).putProperty(sTT('property'), gP = sTT('generalPreferences'))
	ref.putClass(sTT('application')); (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref);
	(dsc2 = new ActionDescriptor()).putBoolean(sTT('placeRasterSmartObject'), false)
	dsc1.putObject(sTT('to'), gP, dsc2), executeAction(sTT('set'), dsc1)
	executeAction(sTT('newPlacedLayer'))
}

sTT = stringIDToTypeID; Folder(C = (pth = '~/desktop/') + 'C/').create()
A = File(pth + 'A').getFiles('*.png'), B = File(pth + 'B').getFiles('*.png');
(aD = documents.add(UnitValue(2550,'px'), UnitValue(3300, 'px'), 300, '', null,
DocumentFill.TRANSPARENT, null, null, 'none')).suspendHistory('crt', 'crt()')

function loop() {
	function parng(v1, v2) {
		(dsc = new ActionDescriptor()).putPath(sTT('null'), v1)
		executeAction(sTT('place' + v2), dsc)
	}

	while(A.length) parng(shft = A.shift(), 'dLayerRelinkToFile'), parng(B.shift(), 'Event'),
	(ref = new ActionReference()).putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum')),
	(dsc = new ActionDescriptor()).putReference(sTT('null'), ref), executeAction(sTT('groupEvent'), dsc),
	aD.saveAs(File(C + shft.name), png, true), aD.activeHistoryState = aD.historyStates[2]
}

png = new PNGSaveOptions
aD.suspendHistory('loop', 'loop()')
aD.close(SaveOptions.DONOTSAVECHANGES)

 

Marinapomorac
Marinapomorac작성자
Inspiring
January 18, 2022

IT WORKED!!!

For people not that familiarized with scripting and what to do when someone gives you block of text as script these are the steps:
Open Notepad and copy paste the text that was given to you as script.
Save the file with unique name and add extension .jsx at the end. It will ask you are you sure, just accept.
Look for C:\Program Files\Adobe\Adobe Photoshop 2021\Presets\Scripts and paste the file you just created there.
Obviously create folders named A and B on your desktop if you want to use this one, and place same size and 300DPI images in those folders. Folder A is for clipping masks files, and B for photos to be clipped.
Open Photoshop and under File menu look for Scripts. You should have your script name listed there. Click on it and let it run.

In my case it generated folder C with my photos clipped by my frames.

PERFECT! Going to test it now on more photos.

 

 

Stephen Marsh
Community Expert
Community Expert
January 18, 2022

This will need a script, it is beyond an action.

 

The following scripts can be modifed as needed.

 

I don't have time now to customise if you can't script, but I will have time in 24 hours or so.

 

EDIT:

 

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-open-files-and-layer-them/m-p/12532657

 

 

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/auto-merge-files/m-p/10753387

 

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

Marinapomorac
Marinapomorac작성자
Inspiring
January 18, 2022

Thank you.
The best answer fro me is to know it is possible, now it is only matter of finding person that knows how to write scripts.
I do not have knowledge to write scripts or modify them so I will copy paste this and share it on FB hopefully someone will respond with the functional script for what I am trying to achieve. 

THANK YOU!!


Stephen Marsh
Community Expert
Community Expert
January 18, 2022

I'm sure that somebody here can help, I'll check back tomorrow when I have time. If I have time before then I'll update the code.