Copy link to clipboard
Copied
I have an animated sequence of about 300 images which I'm applying to a single base image via the "Glass" filter (creating another animated sequence with the filter). To do this manually, every time the Glass filter is applied I have to load a new source image in the sequence but I can't find a way to do this through automation (I would need the automation to pick the next file in the folder as a reference for each application of the filter).
Is this possible to do in Photoshop? I'm using CS4 Extended. Any help would be greatly appreciated.
That was my fault it should have been uppercase "p" in zeropad
THis has now got resize canvas with anchor middle center.
function revert(doc){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID( "SnpS" ), doc.name );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
save
Copy link to clipboard
Copied
Can't this be done by recording an Action to handle one image in the sequence then Batch the Action over the entire folder of images?
Copy link to clipboard
Copied
The problem is that I'm only working on one image, but adjusting it, saving it then resetting it to adjust and save it again sequentially 300 times. Let me try to explain my situation again:
I have a single image I'm working on. I go to Filter > Distort > Glass. Within the glass filter, there is the option to use a Photoshop document as the source for the distortion. That is where I need to sequentially use a different set of prerendered images from a sequence. After I'm done, I save and start over again with the original file.
I can't seem to get any action to use sequential images within the filter settings. If I'm doing something wrong and this can be done, please tell me as doing this manually is taking hours.
Copy link to clipboard
Copied
This should get you started.
function applyGlassFilter( distort, smooth, scale, invert, file ) {
var desc = new ActionDescriptor();
desc.putEnumerated( charIDToTypeID( "GEfk" ), charIDToTypeID( "GEft" ), charIDToTypeID( "Gls " ) );
desc.putInteger( charIDToTypeID( "Dstr" ), distort );
desc.putInteger( charIDToTypeID( "Smth" ), smooth );
desc.putPath( charIDToTypeID( "TxtT" ), file );
desc.putInteger( charIDToTypeID( "Scln" ), scale );
desc.putBoolean( charIDToTypeID( "InvT" ), invert );
executeAction( charIDToTypeID( "Gls " ), desc, DialogModes.NO );
}
function revert(doc){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID( "SnpS" ), doc.name );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 8;
var files = new Folder( '/c/temp3' ).getFiles('*.psd');
var saveFolder = new Folder( '/c/temp4');
var saveName = activeDocument.name;
for( var i = 0; i < files.length; i++ ){
applyGlassFilter( 7, 3, 10, false, files[ i ] );
activeDocument.saveAs( new File( saveFolder + '/' + saveName + '_' + i +'.jpg' ), saveOptions, true,Extension.LOWERCASE);
revert( activeDocument );
}
Copy link to clipboard
Copied
I'm going to go on a limb here without knowing much about the filter and say yes it can be done with a script or a combination script/action.
I can give it a try for you if you'd like and see what I can come up with. It may not be tonight, but maybe tomorrow. I just need to know a bit more about the images you are processing. Bit depth, color space, etc.
Copy link to clipboard
Copied
If you can do that, I would be incredibly greatful as it would not only save me hours of painfully boring work but it would also open me up to making changes down the road (as there is always something that needs to be tweaked).
The current process is this:
(Starting point- I have the original document open "basebackground.psd")
1) Filter > Distort > Glass
2) Within the Glass filter, there are 2 pulldowns next to "Texture:". The first allows me to select a number of default images or the last used custom image (which has to be a .psd). The second is the single option to "Load Texture..." which is what I use to get the next custom image in my already rendered blackwhite001-300.psd sequence.
3) After applying whatever number I happen to be on, I cut the canvas size down to 256x256 (as this was a 3x3 grid of 768x768- this allows me to get rid of tile seams that would have been caused by the edges in a 1x1 grid).
4) With my 256x256 tile ready, I then do a Save As... sequentially from 001-300
5) After the tile is saved, I undo the document history back to my starting point so I can repeat the steps but this time, using blackwhite002.psd instead of blackwhite001.psd when I get to step 2.
The details from my best attempt at a Glass filter action are as follows:
Effect: Glass
Distortion: 15
Smoothness: 4
Tescture Type: (file path to my my blackwhite001-300.psd)
Scaling: 100
Without Invert Texture
In addition, the original document is RGB with 8bits/channel. If there is any other bit of information you need, please let me know.
Copy link to clipboard
Copied
I'm jumping in and trying to understand this as best I can. For me, the most critical bit is the Glass filter:
function applyGlassFilter( distort, smooth, scale, invert, file ) {
var desc = new ActionDescriptor();
desc.putEnumerated( charIDToTypeID( "GEfk" ), charIDToTypeID( "GEft" ), charIDToTypeID( "Gls " ) );
desc.putInteger( charIDToTypeID( "Dstr" ), distort );
desc.putInteger( charIDToTypeID( "Smth" ), smooth );
desc.putPath( charIDToTypeID( "TxtT" ), file );
desc.putInteger( charIDToTypeID( "Scln" ), scale );
desc.putBoolean( charIDToTypeID( "InvT" ), invert );
executeAction( charIDToTypeID( "Gls " ), desc, DialogModes.NO );
}
And within that function it seems that the putEnumerated and putPath are going to be the core of what I'm after but admittedly this is all still quite new to me and I have a bit of a learning curve ahead. I'm off to find some scripting tutorials.
Copy link to clipboard
Copied
You don't really need to understand the function to use it, but the putEnumerated is for the glass filter and putPath is for the file object that you want to use as a texture. The putInteger lines and the putBoolean line is for the other options from the dialog, all of which are arguments of the function.
Copy link to clipboard
Copied
Does this look like it is going to work for you? From what I can see, it looks like it should.
Copy link to clipboard
Copied
At this point I'm trying to get the Glass Filter script to run on its own (so I can use it as part of an action, which I'm more familiar with) but what I've taken from the above keeps on applying the Glass Filter over and over again before I'm able to continue the rest of the action. I'm looking through some tutorials to make more sense of what has been posted.
Copy link to clipboard
Copied
The script I posted process a folder of psd textures. I posted it before you stated that you needed to adjust the canvas size. The resize can be added to the script but as I understand what you are trying to do it would be better to avoid actions.
Perhaps if you outlined all the steps I can adust the script to meet your needs.
Mike
Copy link to clipboard
Copied
At this point I have actions in place to handle everthing but the Glass filter so I am just trying to get a script for step 2:
2) Within the Glass filter, there are 2 pulldowns next to "Texture:". The first allows me to select a number of default images or the last used custom image (which has to be a .psd). The second is the single option to "Load Texture..." which is what I use to get the next custom image in my already rendered blackwhite001-300.psd sequence.
Copy link to clipboard
Copied
This will give the glass effect on the selected layer..
activeDocument.activeLayer.applyGlassEffect(15,4,100,false,TextureType.FROSTED,undefined);
The options are Distortion 0-20, Smoothness 1 - 15, Scaling 50 - 200, invert true/false, texture TextureType, File - texture file
Copy link to clipboard
Copied
activeDocument.activeLayer.applyGlassEffect(15,4,100,false,TextureType.FROSTED,undefined);
That gets me close, but it uses the Frosted preset insead of my sequential .psd's. So what I need from the line above is a way to use my psd file instead of FROSTED and then use the next one in the series upon each subsequent run of the script.
Copy link to clipboard
Copied
activeDocument.activeLayer.applyGlassEffect(15,4,100,false,undefined,File("fullPathAndFileName"));
You will have to amend to suit.
Copy link to clipboard
Copied
That last one gave me identical results to the Frosted preset which doesn't make any sense to me. After triple checking that I'm using the right script and the file path/name is in there, I'm at a loss. I most certainly appreciate all of the help thus far but I'm afraid my weekend has been burned through trying to get this to work out and as I'm behind schedule at this point, I'll just have to bite the bullet and do the last 150 images manually with partial automation through actions.
Thank you again to everyone for their help.
Copy link to clipboard
Copied
Mike has done all the work and his code should work.
Here's Mike's code without the scriptlistner glass and using the one liner.
function revert(doc){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID( "SnpS" ), doc.name );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 8;
var files = new Folder( '/c/temp3' ).getFiles('*.psd');
var saveFolder = new Folder( '/c/temp4');
var saveName = activeDocument.name;
for( var i = 0; i < files.length; i++ ){
activeDocument.activeLayer.applyGlassEffect(15,4,100,false,undefined,files[ i ]);
activeDocument.saveAs( new File( saveFolder + '/' + saveName + '_' + i +'.jpg' ), saveOptions, true,Extension.LOWERCASE);
revert( activeDocument );
};
Copy link to clipboard
Copied
Thanks Paul,
I did miss the part about cropping but he never posted the details. Thanks also for pointing out that the scripting API has a glass filter method.
Copy link to clipboard
Copied
That works brilliantly. I'm not sure why I had so many problems with the earlier version of the script. I'm going to change the save options to a lossless format but I believe I can handle that. I really only have two minor questions left at this point.
1) How do I get the file name to be in the format "SavedFile_001.ext" through "SavedFile_300.ext" instead of "SavedFile_1.ext" through "SavedFile_300.ext"?
2) How would I go about reducing the canvas size from 768x768 to 256x256 (going from a 3x3 grid to a 1x1) after applying the filter? (This I can currently do with actions but if I can do everything at once, that's even better.)
Thank you very much again.
Copy link to clipboard
Copied
This should add the padding and do the resize...
function revert(doc){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID( "SnpS" ), doc.name );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 8;
var files = new Folder( '/c/temp3' ).getFiles('*.psd');
var saveFolder = new Folder( '/c/temp4');
var saveName = activeDocument.name;
for( var i = 0; i < files.length; i++ ){
activeDocument.activeLayer.applyGlassEffect(15,4,100,false,undefined,files[ i ]);
activeDocument.resizeImage( UnitValue(256,"px"), undefined, undefined, ResampleMethod.BICUBICSHARPER);
activeDocument.saveAs( new File( saveFolder + '/' + saveName + '_' + zeropad(i,3) +'.jpg' ), saveOptions, true,Extension.LOWERCASE);
revert( activeDocument );
};
Copy link to clipboard
Copied
I'm looking for a resizeCanvas instead of a resizeImage- do you happen to have the format for that?
Edit: The last zeropad just needed to be changed to zeroPad.
Copy link to clipboard
Copied
That was my fault it should have been uppercase "p" in zeropad
THis has now got resize canvas with anchor middle center.
function revert(doc){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID( "SnpS" ), doc.name );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 8;
var files = new Folder( '/c/temp3' ).getFiles('*.psd');
var saveFolder = new Folder( '/c/temp4');
var saveName = activeDocument.name;
for( var i = 0; i < files.length; i++ ){
activeDocument.activeLayer.applyGlassEffect(15,4,100,false,undefined,files[ i ]);
activeDocument.resizeCanvas(new UnitValue(256, "px"),new UnitValue(256, "px"),AnchorPosition.MIDDLECENTER);
activeDocument.saveAs( new File( saveFolder + '/' + saveName + '_' + zeroPad(i,3) +'.jpg' ), saveOptions, true,Extension.LOWERCASE);
revert( activeDocument );
};
Copy link to clipboard
Copied
That works perfectly. I really cannot stress enough how much I appreciate your patience through all of this, as well as everyone else who has taken the time to help. This not only saves me quite a bit of a headache, but will also allow me to make future modifications to the environment as necessary.
Again, thank you very much.