Copy link to clipboard
Copied
I have a box mockup, and a folder of 300 images. Manually, I follow the following steps:
1. Edit the smart object (the image that goes into the box)
2. Drag and drop the next image onto the existing one
3. CTRL+F (expands the size of the image to fit the canvas size)
4. Save smart object
5. Close smart object
6. Export image (box with embedded image) to PNG
I then repeat the above for the next image. I'm looking for some advice on how to automate this, using actions, automate batch or any other method! Thanks!
Copy link to clipboard
Copied
Is Ctrl & F your personal shortcut? If so, which menu item it refers?
Copy link to clipboard
Copied
CTRL+F runs the script "fit layer to canvas".
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks; I did come across that in my search, but I'm not familiar with scripts - do I have to copy and paste that code somewhere in Photoshop? How do I automate it?
Copy link to clipboard
Copied
Hi @extracampine, basically, write or copy your script to Notepad or Textpad and save the file with the .js extension. Upload that file to Photoshop with the Script Events Manager found under the File menu. Then run that script as needed. I hope that's helpful!
Copy link to clipboard
Copied
.jsx is more exact format, while Script Events Manager should be used only for listening.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@extracampine wrote:
I'm not familiar with scripts - do I have to copy and paste that code somewhere in Photoshop? How do I automate it?
Quickstart:
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
Thanks - but "copy the code text to the clipboard" - that link pasted above has lots of different code text, from different people. Which one should I use?
Copy link to clipboard
Copied
Whichever one works best for you. You are likely going to have to try many different scripts, there must be at least a dozen out there. Here's another! As my earlier links show, this question comes up continuously.
Copy link to clipboard
Copied
Thanks again. Been messing around with this for a while, but can't seem to get it to work. One script I found saves the images as PSD - but I want it to save as PNG. The script also doesn't resize the images to fit the smart object after they are placed. This is the script:
// Replace SmartObject’s Content and Save as PSD
// 2017, use it at your own risk
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theLayer = myDocument.activeLayer;
// PSD Options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
psdOpts.spotColors = true;
// Check if layer is SmartObject;
if (theLayer.kind != "LayerKind.SMARTOBJECT") {
alert("selected layer is not a smart object")
} else {
// Select Files;
if ($.os.search(/windows/i) != -1) {
var theFiles = File.openDialog("please select files", "*.psd;*.tif;*.jpg", true)
} else {
var theFiles = File.openDialog("please select files", getFiles, true)
};
if (theFiles) {
for (var m = 0; m < theFiles.length; m++) {
// Replace SmartObject
theLayer = replaceContents(theFiles[m], theLayer);
var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];
// Save JPG
myDocument.saveAs((new File(thePath + "/" + theName + "_" + theNewName + ".png")), psdOpts, true);
}
}
}
};
// Get PSDs, TIFs and JPGs from files
function getFiles(theFile) {
if (theFile.name.match(/\.(psd|tif|jpg)$/i) != null || theFile.constructor.name == "Folder") {
return true
};
};
// Replace SmartObject Contents
function replaceContents(newFile, theSO) {
app.activeDocument.activeLayer = theSO;
// =======================================================
var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
desc3.putPath(idnull, new File(newFile));
var idPgNm = charIDToTypeID("PgNm");
desc3.putInteger(idPgNm, 1);
executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
return app.activeDocument.activeLayer
};
Copy link to clipboard
Copied
An all too common question... Some more topics, which may include other scripts:
Phone cases are another common topic, scripts should be applicable to both:
Smart object replacement:
Another option here:
https://github.com/joonaspaakko/Batch-Mockup-Smart-Object-Replacement-photoshop-script
Good luck!