0
// Replace SmartObject’s Content and Save as JPG
// 2017, use it at your own risk
// Via @Circle B: https://graphicdesign.stackexchange.com/questions/92796/replacing-a-smart-object-in-bulk-with-photoshops-variable-data-or-scripts/93359
// JPG code from here: https://forums.adobe.com/thread/737789

#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;
    // JPG Options;
    jpgSaveOptions = new JPEGSaveOptions();  
    jpgSaveOptions.embedColorProfile = true;  
    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;  
    jpgSaveOptions.matte = MatteType.NONE;  
    jpgSaveOptions.quality = 11;   
    // 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", "*.png;*.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 + "/"  + theNewName + ".jpg")), jpgSaveOptions, true,Extension.LOWERCASE);
            }
        }
    }
};
// Get PSDs, TIFs and JPGs from files
function getFiles(theFile) {
    if (theFile.name.match(/\.(png|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
};

//Alert Letting the User Know the Script Has Finished
alert("Finished!\nThe script has finished saving the jpeg thumbnails in the folder with the original mockup");

I want it to place the design normally in the right place, but instead, it turns the mockup in the first image to the weird, zoomed input image in the second image: mockup misplaced image

but it was supposed to look like that: enter image description here

Here is my mockup file

6
  • ermmm.... "it turns this mockup to this image" --- How is anyone here to know how things are supposed to look? Did you review the question the script was taken from graphicdesign.stackexchange.com/questions/92796/… -- it's listed right there at the top of the script.
    – Scott
    Jun 11, 2022 at 18:58
  • @Scott sorry if it's not clear, it was supposed to look as a picture in the frame. Yes, I exactly did the said thing, I selected the image and pressed OK, then the whole mockup just turned into a hugified version of the input image.
    – pofdzm
    Jun 11, 2022 at 19:21
  • I guess I need to somehow make the script fit every input image as the same resolution with the default picture in the mockup.
    – pofdzm
    Jun 11, 2022 at 19:35
  • To be honest, I have no clue what the result is supposed to look like. Your description of "in a frame" isn't very helpful. In addition, I have no idea where you got the "mock up" you are using or how it may be constructed. There's really just very minimal information in the question and subsequent comments. I'd suggest you EDIT the question and provide more detail. Remember no one here knows what you are working with or what you are trying to accomplish, or what the end result is supposed to look like.
    – Scott
    Jun 11, 2022 at 19:46
  • @Scott here, I hope I entered enought information now.
    – pofdzm
    Jun 11, 2022 at 20:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.