• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

automate impossible to achieve task. A challenge for photoshop actions/script Gurus

Explorer ,
May 17, 2023 May 17, 2023

Copy link to clipboard

Copied

I have a large collection of inconsistent JPG images with high resolution that I need to resize, crop, and compress for web use. The main challenge is automating multiple actions. Here is what I would like to achieve:

1. Convert the images into smart objects.

2. Slice the images into parts, (required for horizontal images).

3. Remove watermark/numbers (if present in the image)

4. Blur background (to increase focus on the subject)

5. After that, detect the main subject and crop them with a 150px top and 100px bottom margin around the subject.

6. Next, resize the images to specific dimensions, such as 800px wide and 1000px tall, while maintaining a 4:5 aspect ratio.(if image dimensions are bigger than that)

7. Convert the images to the WebP format, aiming for a file size between 100-200kb.

8. Export the images while preserving the sub-folder structure of the original source folder.

Is it possible to automate this process, either fully or partially? Please guide me, I will highly appreciate your kind help

TOPICS
Actions and scripting

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
May 17, 2023 May 17, 2023

Copy link to clipboard

Copied

quote

Is it possible to automate this process, either fully or partially? Please guide me, I will highly appreciate your kind help


By @raeen

 

This is hard to answer without a broad sample of images and more specific info on the requirements.

 

#1 - Creating a SO should be no problem, but should this happen as the first step or after you "slice"?

 

#2 - Examples would help, I'm not sure if you mean slice as in slicing for save for web or simply cropping?

 

#3 - Samples are needed, however, this may be a barrier for automation. Why can't you get clean originals, why are there numbers/watermarks and is it ethical to remove them?

 

Etc.

 

Tackle each step one at a time, then see if you can make a combined, cohesive workflow from each separate step.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

Think there is a source folder and it has 200 sub-folder.
Each sub-folder has product pictures of one product/style.
Some sub-folder have only portrait images, some have only horizontal images and some have mix of both.
Most horizontal images are composite of two portrait images. When we select the slice tool, the tool automatically snaps into 2 parts(when we divide slice vertically in 2 parts)
I want all images in portrait form to use on the website
To my understanding, it would be better to first convert all images into smart object
Then slice/split horizontal images into 2 parts and save each individually.
Up to this point, all images would be in portrait hence cropping/resizing images in batch would be possible.

 

There is no issue of copyright to remove name/numbers as we have permission from the owner

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

That explanation helps a bit.

 

I doubt that the slice tool is going to help with automation. Easier to just adjust canvas size to 50% width for left and right sides.

 

A script can differentiate between landscape and portrait and process accordingly, but how to auto process landscape if they are not all actually a 2up combined image??? Filename? Metadata?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

If I save slice images into png then convert those(PNGs) into smart object that would be ok too.

Does Photoshop have something known as logic/conditions?
Like, run this action to all these folders, slice, and export images into PNG only if the images are in JPG and are horizontal

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied


Does Photoshop have something known as logic/conditions?


 

Photoshop actions have a limited range of "conditional" options:

 

conditional-action.png

 

https://helpx.adobe.com/au/photoshop/using/conditional-actions-creative-cloud.html

 

conditional-atn.png

 

Scripting offers more possibilities, an example here:

 

http://actionlogic.blogspot.com/2006/03/sivas-photoshop-conditional-action.html

 

There are many more conditions that scripting can check, above and beyond what is mentioned above.

 

Edit - Some other simple scripting conditional examples:

 

https://prepression.blogspot.com/2022/11/photoshop-action-helper-scripts.html

 

https://snipit.io/public/collections/22660/22660

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

quote3. Remove watermark/numbers (if present in the image)

 

By @raeen


sounds like smth illegal...hm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

Don't worry, I have permission

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

This would likely be a major roadblock to automation, but without seeing samples it is hard to know. Much better to get versions without numbers or watermarks if you have permission to remove them.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

There are 2 options that could be done to overcome this

  1. Remove background completely
  2. Blur background

Here background removal won't be precise on all images and it will take more computing power and time and manual adjustment to some images will be required.

Hence I have decided to go with the 2nd option which is to blur the background, it solves all problems at once and it can be automated completely to my knowledge.

 

I know to know your opinion on this.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

We cannot give any help or advice in these forums with removing watermarks, it would break forum guidelines. Doing so will get the thread locked. That includes editing them out by blurring. 

 

Watermarks are there for a reason. If you have permission from the owner(s) to use their images, then go to those owner(s) and get unwatermarked copies.

 

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

okay, I got images without a watermark, can you help now?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

quote

okay, I got images without a watermark, can you help now?

The please post one of those images. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2023 Jun 01, 2023

Copy link to clipboard

Copied

quotesounds like smth illegal...hm

By @Ivan Zajats

 

Actually, it would be either legal or illegal irrespective of the watermark. The importance of a watermark (or copyright symbol) is overrated. All copyright always applies regardless. You don't need to specifically mark the image to retain all rights. Copyright legally belongs to the creator of the work, full stop.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

Please provide at least one original image and the resulting file/s you want to create to clarify your point. 

 

Do you understand what (the advantages of) Smart Objects are? 

 

»Hence I have decided to go with the 2nd option which is to blur the background, it solves all problems at once and it can be automated completely to my knowledge.«

How would this solve the problem of creating a decent selection of the subject of the image?

Are you referring to the »Depth Blur«-Neural Filter? 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

So here is the original image I received from the owner without a watermark or number. Below are the steps I took to obtain the desired image (referred to as processed image 1 & 2):

  1. Automatically slice the vertical image into two parts and save each part as a PNG file.
  2. Open one of the slices and crop the image to conform to a 4:5 ratio. If there are white vertical bars on the left and right sides of the image, select them and fill them with the content-aware tool.
  3. After that, use the "Select Subject" tool to select the subject and then inverse the selection to select the background.
  4. Apply a Tilt-Blur effect to the background, directing it towards the bottom.
  5. Next, resize the image to be 800 pixels wide and 1000 pixels tall.
  6. Save a copy of the processed image in the webp format.

Currently, it is not possible to automate all of these steps together, especially step 2. Therefore, I suggest saving the sliced images as smart objects or PSD files to avoid losing quality. Then, perform each processing step one by one and finally export all the images in webp format.

 

I have attached original image and desired image(after processing) with the hope to get a reply 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 21, 2023 May 21, 2023

Copy link to clipboard

Copied

Convert an image into a smart object doesn't magically avoid quality loss. Just take that step out of the process.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 21, 2023 May 21, 2023

Copy link to clipboard

Copied

Okay, except smart object step, can you guide how to automate rest of the steps? or any of the the steps?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2023 Jun 01, 2023

Copy link to clipboard

Copied

• Does the left/smaller image always have the identical position and dimensions or does it vary? 

• »Processed-Photo-1.jpg« has had a piece cropped at the top – deliberate, random, …? 

 

It also demonstates shortcomings of »Select Subject« – one of the lamps right of the head seems to have been included. 

And on »Processed-Photo-2.jpg« the results of Content-Aware Fill seem suboptimal. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2023 Jun 01, 2023

Copy link to clipboard

Copied

LATEST

The following code would create two images from the active document (see screenshot), you can amend the Tilt-Shift settings. 

If the smaller image is not actually always at that same position you could try using work-arounds utilizing the Magic Wand Tool (for example) to locate it. 

 

I trust you can find plenty of code-examples for scaling images on this Forum.

I have no interest in or need of using webp so far, but it seems @Stephen_A_Marsh already posted code on that, too. 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/saving-webp-image-by-script/m-p/13642...

 

Screenshot 2023-06-01 at 15.16.48.png

// crop two segments of image, save as new files, change to 4:5 and 
// apply tilt-shift blur to background based on select > subject;
// 2023, use at your own risk;
if (app.documents.length > 0) {
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
// get properties, thanks to xbytor;
    var myDocument = app.activeDocument;
    var docName = myDocument.name;
    try {
        var basename = docName.match(/(.*)\.[^\.]+$/)[1];
        var docPath = myDocument.path
    }
    catch (e) {var docPath = "~/Desktop"};
// duplicate, crop, canvas size, … for right;
    var theCopy = myDocument.duplicate("thecopy", true);
    cropImageTo (myDocument.width/2, 0, myDocument.width, myDocument.height);
    theCopy.flatten();
    var theWidth = theCopy.width;
    var theHeight = theCopy.height;
    theCopy.resizeCanvas(theHeight/5*4, theHeight);
    var theDifference = (theCopy.width-theWidth)/2;
    rectangularSelection (0, 0, theDifference+2, theHeight, false);
    rectangularSelection (theCopy.width-theDifference-2, 0, theCopy.width, theHeight, true);
    contentAwareFill();
    tiltShiftBlurBackground (30);
    saveAsTif (theCopy, docPath+"/"+basename+"_right"+".tif");
// duplicate, crop, canvas size, … for left;
    app.activeDocument = myDocument;
    var theCopy2 = myDocument.duplicate("thecopy2", true);
    cropImageTo (417, 572, 2426, 3484);
    theCopy2.flatten();
    var theWidth = theCopy2.width;
    var theHeight = theCopy2.height;
    theCopy2.resizeCanvas(theHeight/5*4, theHeight);
    var theDifference = (theCopy2.width-theWidth)/2;
    rectangularSelection (0, 0, theDifference+2, theHeight, false);
    rectangularSelection (theCopy2.width-theDifference-2, 0, theCopy2.width, theHeight, true);
    contentAwareFill();
    tiltShiftBlurBackground (30);
    saveAsTif (theCopy2, docPath+"/"+basename+"_left"+".tif");
// reset;
    app.preferences.rulerUnits = originalRulerUnits;
    };
////// save tif //////
function saveAsTif (myDocument, thePath) {
// tif options;
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
tifOpts.alphaChannels = false;
tifOpts.byteOrder = ByteOrder.MACOS;
tifOpts.layers = false;
// save as tif;
myDocument.saveAs((new File(thePath)), tifOpts, false);
};
////// save pdf //////
function saveCopyAsTif (myDocument, thePath) {
// tif options;
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
tifOpts.alphaChannels = false;
tifOpts.byteOrder = ByteOrder.MACOS;
tifOpts.layers = false;
// save copy;
myDocument.saveAs((new File(thePath)), tifOpts, true);
};
////// crop //////
function cropImageTo (x1, y1, x2, y2) {
// =======================================================
    var desc7 = new ActionDescriptor();
        var desc8 = new ActionDescriptor();
        var idPxl = charIDToTypeID( "#Pxl" );
        desc8.putUnitDouble( charIDToTypeID( "Top " ), idPxl, y1 );
        desc8.putUnitDouble( charIDToTypeID( "Left" ), idPxl, x1);
        desc8.putUnitDouble( charIDToTypeID( "Btom" ), idPxl, y2 );
        desc8.putUnitDouble( charIDToTypeID( "Rght" ), idPxl, x2 );
    var idRctn = charIDToTypeID( "Rctn" );
    desc7.putObject( charIDToTypeID( "T   " ), idRctn, desc8 );
    desc7.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), 0.000000 );
    desc7.putBoolean( charIDToTypeID( "Dlt " ), false );
    desc7.putEnumerated( stringIDToTypeID( "cropAspectRatioModeKey" ), stringIDToTypeID( "cropAspectRatioModeClass" ), stringIDToTypeID( "pureAspectRatio" ) );
    desc7.putBoolean( charIDToTypeID( "CnsP" ), false );
executeAction( charIDToTypeID( "Crop" ), desc7, DialogModes.NO );
};
////// make a rectangular selection //////
function rectangularSelection (x1, y1, x2, y2, theAdd) {
    if (theAdd == false || theAdd == undefined) {var idset = stringIDToTypeID( "set" )}
    else {var idset = stringIDToTypeID( "addTo" )};
//
    var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
    var desc16 = new ActionDescriptor();
            var ref2 = new ActionReference();
            ref2.putProperty( stringIDToTypeID( "channel" ), stringIDToTypeID( "selection" ) );
        desc16.putReference( stringIDToTypeID( "null" ), ref2 );
            var desc17 = new ActionDescriptor();
            desc17.putUnitDouble( stringIDToTypeID( "top" ), idpixelsUnit, y1 );
            desc17.putUnitDouble( stringIDToTypeID( "left" ), idpixelsUnit, x1 );
            desc17.putUnitDouble( stringIDToTypeID( "bottom" ), idpixelsUnit, y2 );
            desc17.putUnitDouble( stringIDToTypeID( "right" ), idpixelsUnit, x2 );
        desc16.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "rectangle" ), desc17 );
        if(theAdd == true) desc16.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
    executeAction( idset, desc16, DialogModes.NO );
    };
////// content aware fill //////
function contentAwareFill () {
    var desc12 = new ActionDescriptor();
    desc12.putEnumerated( stringIDToTypeID( "using" ), stringIDToTypeID( "fillContents" ), stringIDToTypeID( "contentAware" ) );
    desc12.putBoolean( stringIDToTypeID( "contentAwareColorAdaptationFill" ), true );
    desc12.putBoolean( stringIDToTypeID( "contentAwareRotateFill" ), false );
    desc12.putBoolean( stringIDToTypeID( "contentAwareScaleFill" ), false );
    desc12.putBoolean( stringIDToTypeID( "contentAwareMirrorFill" ), false );
    desc12.putUnitDouble( stringIDToTypeID( "opacity" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
    desc12.putEnumerated( stringIDToTypeID( "mode" ), stringIDToTypeID( "blendMode" ), stringIDToTypeID( "normal" ) );
executeAction( stringIDToTypeID( "fill" ), desc12, DialogModes.NO );
};
////// select subject and apply tilt-shift blur on background //////
function tiltShiftBlurBackground (theValue) {
    var theX = activeDocument.width/2;
    var theHeight = activeDocument.height;
    // =======================================================
        var desc5 = new ActionDescriptor();
        desc5.putBoolean( stringIDToTypeID( "sampleAllLayers" ), false );
    executeAction( stringIDToTypeID( "autoCutout" ), desc5, DialogModes.NO );
    // =======================================================
    executeAction( stringIDToTypeID( "inverse" ), undefined, DialogModes.NO );
    // =======================================================
        var desc395 = new ActionDescriptor();
        desc395.putBoolean( stringIDToTypeID( "blurbType" ), true );
        desc395.putInteger( stringIDToTypeID( "versionMajor" ), 1 );
        desc395.putInteger( stringIDToTypeID( "versionMinor" ), 0 );
            var desc396 = new ActionDescriptor();
            desc396.putInteger( stringIDToTypeID( "top" ), 0 );
            desc396.putInteger( stringIDToTypeID( "left" ), 0 );
            desc396.putInteger( stringIDToTypeID( "bottom" ), 4050 );
            desc396.putInteger( stringIDToTypeID( "right" ), 3240 );
        desc395.putObject( stringIDToTypeID( "referenceRect" ), stringIDToTypeID( "rectangle" ), desc396 );
        desc395.putInteger( stringIDToTypeID( "blurbOpenPanel" ), 3 );
        desc395.putBoolean( stringIDToTypeID( "blurbLensTiltEffectApplied" ), true );
        desc395.putBoolean( stringIDToTypeID( "blurbSaveMaskChannel" ), false );
        desc395.putBoolean( stringIDToTypeID( "blurbHighQuality" ), false );
        var idblurbWidgetList = stringIDToTypeID( "blurbWidgetList" );
            var list4 = new ActionList();
                var desc397 = new ActionDescriptor();
                desc397.putInteger( stringIDToTypeID( "blurbWidgetType" ), 3 );
                desc397.putDouble( stringIDToTypeID( "blurbWidgetLocationX" ), theX );
                desc397.putDouble( stringIDToTypeID( "blurbWidgetLocationY" ), theHeight*0.8 );
                desc397.putBoolean( stringIDToTypeID( "blurbWidgetSelected" ), true );
                desc397.putBoolean( stringIDToTypeID( "blurbWidgetEffectEnabled" ), true );
                desc397.putDouble( stringIDToTypeID( "blurbWidgetFade" ), 100.000000 );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftInnerPoint1X" ), theX );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftInnerPoint1Y" ), theHeight*0.9 );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftInnerPoint2X" ), theX );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftInnerPoint2Y" ), theHeight*1.2 );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftOuterPoint1X" ), theX );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftOuterPoint1Y" ), theHeight*0.5 );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftOuterPoint2X" ), theX );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftOuterPoint2Y" ), theHeight*1.5 );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftBlurAmount" ), theValue );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftDistortion" ), 0.000000 );
                desc397.putBoolean( stringIDToTypeID( "blurbTiltShiftSymmetricDistortion" ), false );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftCenterX" ), theX );
                desc397.putDouble( stringIDToTypeID( "blurbTiltShiftCenterY" ), theHeight*0.9 );
            list4.putObject( stringIDToTypeID( "blurbWidget" ), desc397 );
        desc395.putList( idblurbWidgetList, list4 );
    executeAction( stringIDToTypeID( "blurbTransform" ), desc395, DialogModes.NO );
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines