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
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
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
hey chuck i need your help, i try ue your script and this eror popout. I dont know how to fix it. already try any method but stil no work
Copy link to clipboard
Copied
DOD you try my suggestions on you other post regarding the names of the files? That first file in you screen shot has all that garbage lettering after it.
Copy link to clipboard
Copied
already change the name to 1 letter but still not work
Copy link to clipboard
Copied
sardonicHumour();
function sardonicHumour() {
alert("Thx for giving away free iPhone cases. Not every people want to share they product for free");
}