Copy link to clipboard
Copied
can someone help me how to replace image on mockup with auto action or script and save it as jpeg ?
i try action but keep fail and dont know wahts wrong with my action script
i still new on photoshop and sry for my bad english
this is my mockup and photo example
Here is a script that will replace the selected Smart Object layer with a file from a source folder, then save the file as a jpg to an output folder. It will loop through the source folder and replace the original smart object with each file in the source folder, All the source files have to be the same size! In the script, I have the source folder being on the desktop and called "source files." The output folder is a subfolder, in source files, called "done." You can change the code to reflect
...Copy link to clipboard
Copied
Here is a script that will replace the selected Smart Object layer with a file from a source folder, then save the file as a jpg to an output folder. It will loop through the source folder and replace the original smart object with each file in the source folder, All the source files have to be the same size! In the script, I have the source folder being on the desktop and called "source files." The output folder is a subfolder, in source files, called "done." You can change the code to reflect whatever folders you want to use. I also added a "-Flat" suffix to the saved jpg files to avoid overwriting anything.
var srcFolder = new Folder('~/desktop/source files/');
var outputFolder = new Folder('~/desktop/source files/done/');
var searchMask = '*.???'
var fileList = srcFolder.getFiles(searchMask);
var doc = activeDocument;
var curLayer = doc.activeLayer;
var soName
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;
for (var i=0;i<fileList.length;i++){
replaceSO (fileList[i]);
var fName = fileList[i].name.split('.')[0];
dupeFile ();
var doc2 = activeDocument;
doc2.saveAs(new File(outputFolder +'/'+fName + '-flat.jpg'),jpgOptions);
doc2.close(SaveOptions.DONOTSAVECHANGES);
}
function replaceSO(file){
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
var desc5 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc5.putPath( idnull, new File( file ) );
executeAction( idplacedLayerReplaceContents, desc5, DialogModes.NO );
}
function dupeFile(){
var idDplc = charIDToTypeID( "Dplc" );
var desc11 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idDcmn = charIDToTypeID( "Dcmn" );
var idOrdn = charIDToTypeID( "Ordn" );
var idFrst = charIDToTypeID( "Frst" );
ref1.putEnumerated( idDcmn, idOrdn, idFrst );
desc11.putReference( idnull, ref1 );
var idMrgd = charIDToTypeID( "Mrgd" );
desc11.putBoolean( idMrgd, true );
executeAction( idDplc, desc11, DialogModes.NO );
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hello Chuck, i wanna ask that I used your script on Photoshop CS6 but it shows error 8800; General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- The command "Replace Contents" is not currently available.
Line: 27
-> executeAction( idplacedLayerReplaceContents, desc5, DialogModes.NO );
Do you know how to fix it?
Copy link to clipboard
Copied
Oops, nevermind I solved it.
I forgot to resize the images to be the same size.
Thanks for the script tho, it helps many people!
Copy link to clipboard
Copied
Hi Chuck,
Thank you its working fine with source folder but jpeg is not getting saved automatically in done folder even though i created the folder in same loaction as you mentioned.
Secondly everytime its asking to save manually and names of JPEGs are also not chaging so its asking to replace or rename.
Please confirm what should I do in that case
Copy link to clipboard
Copied
Hi Ankit,
I have the same issue with automatic saving of jpegs, did you find a solution ?
Thanks
Copy link to clipboard
Copied
Hello Chuck,
First of all, thank you very much for sharing the solution here. I have also applied the above code and it works. I need support in one matter. It runs the Save As method each time while saving the processed images. Instead, what kind of editing should be done in the code to give it the name of the rendered image directly and save it in 12 quality?
Copy link to clipboard
Copied
This is a great script and very similar to the answer I am looking for, in my case, is not just one mockup in the PSD file, is do all this but multiple times, I mean the same file from the folder will replace the content in the smart object (and in around 9 more smart object copies over a different "background no background" layer that is under the every smart object copy, ) then what I need to do is to save those 10 mockups for each image (because the different background), so If I explain my self well, I need 10 different JPGS for each file in the folder, Did I was able to explain myself?
thank you for any light you can bring to this , blessings.
Copy link to clipboard
Copied
@AlexPrint So you just have one common smart object with several other smartobjects that are "linked" to that one smart object? An you want several files saved with each of those smart objects and a different background or multiple backgrounds? Is your working file always the same structure: same number of layers, in the same order, with the same names? Are there more layers than just the smart object and the background layer that you want saved to each file? Can you post an example of your layer structure?
Copy link to clipboard
Copied
Hi Chuck,
This solution worked beautifully for me this morning, and is the BEST version of this script I've found on these forums, Thank you SO much!! But for some reason - a few hours later - it's stopped working 😢
Photoshop seems to be saving the files as PSDs rather than JPGs and stopping on a "save as" screen, where I have to hit "save" for it to continue.
Not sure why this has happened when I didn't change anything about the files / scripts / process.
Wondering if it has to do with the latest version of Photoshop, and the 'save to cloud' screen that sometimes comes up, even tho i've turned it off 🤔
Any ideas?
Copy link to clipboard
Copied
Did you update PS? My guess is that the preferences got changed to the now default of not allowing layered files to be saved as jpgs. Check the preferences and make sure the file saving is set to Legacy.
Copy link to clipboard
Copied
thanks chuck! I figured out what it was.
I had to have a locked background layer in the file, otherwise it doesn't work
Multiple layers is fine, as long as there is a locked BG layer
Copy link to clipboard
Copied
Very good. Glad you got it figured out.
Copy link to clipboard
Copied
Yes, save as plain text with an extension of .jsx.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
To run the script, put in Photoshop's subfolder: Presets/Scripts, then restart Photoshop. Go to File>Scripts in the main menu, and you should see your script listed. If not, use the browse butto . To navigate to it to run it. Just make sure you have your source and output folders setup as I mentioned in my previous post, or change the paths in the code to where you have those folders.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied