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

How to align values of chart images by flip horizontal?

Engaged ,
May 23, 2023 May 23, 2023

Copy link to clipboard

Copied

I receive about 1000 chart images daily that following images are two sample of my images: 

001.jpgUntitled002.jpg 

Now i want to align values of charts using flip horizontal and use photoshop action or script to apply on 1000 daily images like following: 

Video-2023-05-23-195416.gif 

The left side of the chart bars does not need any changes and photoshop action can divide the images into two parts (left side of chart bars - other sides of chart bars) 

next step of action after dividing images, the values on the right side of the chart bars should be selected with Color Range (dark color) 

 

Now i have problem after above step. I must expand selection of values (that i selected by color range) to only left side and selections must extend to the edge of the left border of the layer. 

After extending the selections to the leftmost point of the layer, i can convert each selection to specific layer and every layer can filp horizontal. 

Finally with above steps photoshop action can align all of my images values. 

 

Does anyone have any ideas to solve my problem? 

Please help me in any way you can. If I don't find a solution to this problem, I will lose my job. My only hope is God and this forum and I hope to find a solution for this problem.

TOPICS
Actions and scripting , Windows

Views

4.4K

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

correct answers 2 Correct answers

Community Expert , Jun 11, 2023 Jun 11, 2023

edited 2023-06-12 

 

 

// moveNumbersLeftOfBarGraphs
// separate elements in specific graphics, put the bars right and align the numbers on the left;
// 2023, use it at your own risk;
var time1 = Number(timeString());
moveNumbersLeftOfBarGraphs ();
var time2 = Number(timeString());
alert("\nthe script took: "+((time2-time1)/1000)+" seconds\nstart "+time1+"\nend "+time2+"\n\n");
////// move numbers to left of bar graphs //////
function moveNumbersLeftOfBarGraphs () {
if (app.documents.length > 0)
...

Votes

Translate

Translate
Community Expert , Jun 16, 2023 Jun 16, 2023

This should perform at least somewhat faster if you want to give it a try: 

// moveNumbersLeftOfBarGraphs
// separate elements in specific graphics, put the bars right and align the numbers on the left;
// ideally bars and logos should be colorful to make numbers better identifyable;
// 2023, use it at your own risk;
executeAction( stringIDToTypeID( "revert" ), undefined, DialogModes.NO );
var time1 = Number(timeString());
moveNumbersLeftOfBarGraphs ();
var time2 = Number(timeString());
alert("\
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 05, 2023 Jul 05, 2023

Copy link to clipboard

Copied

»Flip_only_selected_layers_verticaly.jsx« also used DOM-code for the flipping and should benefit from using AM-code. 

But I strongly discourage using ChatGPT for this. 

 

The Scripts 

Flip_only_selected_layers_verticaly.jsx

Flip_only_selected_layers_horizontal.jsx

seem identical except for the direction of the flipping, so if the horizontal AM-heavier version is faster just adapt the line

 

desc6.putUnitDouble( stringIDToTypeID( "width" ), stringIDToTypeID( "percentUnit" ), -100.000000 );

 

for the flipping in the other direction. 

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
Engaged ,
Jul 08, 2023 Jul 08, 2023

Copy link to clipboard

Copied

quote

»


By @c.pfaffenbichler

sir in chart images i want to select values like following: 

sshottt.jpg 

and then convert that selection to following: 

sshooot2.jpg 

i can do this by photoshop action but the steps are complicated (i attach sample PNG and script here, you can check my method steps). do you have faster and simpler idea for steps after values selection? 

note that i can do this by photoshop action but i don't want waste time for complicated steps after values selection. It is not wise to go through those complicated steps every time for every type of chart images. 

my method for this: https://drive.google.com/file/d/1f9zwP3M39qB-W7LilapqvcCO5zKJmLvS/view?usp=sharing

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 ,
Jul 08, 2023 Jul 08, 2023

Copy link to clipboard

Copied

If you can achieve the result you need for all the different graphics you have to process with an Action then that’s fine. 

I am not interested in this anymore. 

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
Engaged ,
Jul 09, 2023 Jul 09, 2023

Copy link to clipboard

Copied

quote

I

By @c.pfaffenbichler

sir can you tell me what is the name of following feature? i mean open 9 number of images in a photoshop and run a script on them at same time. I remember you sent me this gif on this forum a few months ago. 

removeEverythingExceptNumbers_mov01.gif

 

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 ,
Jul 09, 2023 Jul 09, 2023

Copy link to clipboard

Copied

I suspect it must have been a for-clause (referring to app.documents.length). 

And the Script does not run its operations on them at the same time exactly, it selects each image in turn and runs on that, then the next etc.

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
Engaged ,
Jul 19, 2023 Jul 19, 2023

Copy link to clipboard

Copied

quote

If you can achieve the result you need for all the different graphics you have to process with an Action then that’s fine. 

I am not interested in this anymore. 


By @c.pfaffenbichler

Finally I found a method that works on almost all chart images. 

The method I found is not complicated, but it takes nearly 2.5 hours to excute on 1000 images. 

If I share the method with you here, can you help speed it up? Or you are still not interested in continuing this topic. 

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 ,
Jul 19, 2023 Jul 19, 2023

Copy link to clipboard

Copied

Thank you but if you have a functioning method then by all means use it. 

When you have familiarized yourself with Photoshop Scripting further you may be able to improve the perfomance but as it is 9 seconds per image does not seem that bad. 

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 ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Another thing: 

If you have succeeded in automating the processing of images of so many different properties/appearances you should take some pride in that. 

Maybe you will be able to improve the performance in the future, give it time. 

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
Engaged ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

quote

Another thing: 

If you have succeeded in automating the processing of images of so many different properties/appearances you should take some pride in that. 

Maybe you will be able to improve the performance in the future, give it time. 


By @c.pfaffenbichler

Can you tell me how can i use your script on chart images that have not white background? 

I mean following script that you provided me before: 

// selectTextsLeftOfBarGraphs
// create rectangular selection for texts left of bars;
// 2023, use it at your own risk;
var time1 = Number(timeString());
moveNumbersLeftOfBarGraphs ();
var time2 = Number(timeString());

////// move numbers to left of bar graphs //////
function moveNumbersLeftOfBarGraphs () {
if (app.documents.length > 0) {
// the number of pixels;
var theScale = 2;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.togglePalettes();
var myDocument = app.activeDocument;
if (myDocument.mode != "DocumentMode.RGB") {myDocument.convertProfile ("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true)};
var theLayer = myDocument.activeLayer;
// resize image;
myDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE);
myDocument.resizeImage (new UnitValue (theScale*100, "%"), new UnitValue (theScale*100, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
// create path;
createSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer();
loadChannelAsSelection("red", true, false);
var lineStartLeft = myDocument.selection.bounds[0];
deselect();
////////////////////////////////////
myDocument.layers[0].remove();
myDocument.layers[0].remove();
deselect ();
////////////////////////////////////
loadChannelAsSelection("red", true, false);
rectangularSelection (0, 0, lineStartLeft-4, myDocument.height, false, true);
myDocument.quickMaskMode = true;
useMagicWand2022 ([1,1]);
expandSelection(12);
invertSelection ();
fillWithBlack ("white");
deselect ();
applyThreshold(90);
myDocument.quickMaskMode = false;
var thePathIndex = makeWorkPath2 (0.5);
var thePath = collectPathInfoFromDesc2023 (myDocument, thePathIndex[0]);
deletePath (thePathIndex[0]);
////////////////////////////////////
var lineStartExtremes = getSubPathItemExtremes(thePath[0]);
var theNamesPath = [lineStartExtremes];
// process subpathitems;
for (var m = 1; m < thePath.length; m++) {
var theExtremes = getSubPathItemExtremes(thePath[m]);
// add subpathitem if within the vertical dimensions;
if (theExtremes[1] >= lineStartExtremes[1] && theExtremes[1] <= lineStartExtremes[3]) {
//    if (theExtremes[1] >= lineStartExtremes[1] && theExtremes[3] <= lineStartExtremes[3]) {
        theNamesPath[theNamesPath.length - 1][0] = Math.min(theNamesPath[theNamesPath.length - 1][0], theExtremes[0]);
    theNamesPath[theNamesPath.length - 1][1] = Math.min(theNamesPath[theNamesPath.length - 1][1], theExtremes[1]);
    theNamesPath[theNamesPath.length - 1][2] = Math.max(theNamesPath[theNamesPath.length - 1][2], theExtremes[2]);
    theNamesPath[theNamesPath.length - 1][3] = Math.max(theNamesPath[theNamesPath.length - 1][3], theExtremes[3]);
} else {
// new rectangle;
if (theExtremes[1] > lineStartExtremes[3] && theExtremes[3] > lineStartExtremes[3]) {
    lineStartExtremes = theExtremes;
    theNamesPath.push(theExtremes)
}
};
};
////////////////////////////////////
myDocument.resizeImage (new UnitValue (100/theScale, "%"), new UnitValue (100/theScale, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
//alert (theNamesPath.join("\n\n"));
rectangularSelection (theNamesPath[0][0]/theScale, theNamesPath[0][1]/theScale, theNamesPath[0][2]/theScale, theNamesPath[0][3]/theScale, false, false);
for (var n = 0; n < theNamesPath.length; n++) {
    rectangularSelection (theNamesPath[n][0]/theScale, theNamesPath[n][1]/theScale, theNamesPath[n][2]/theScale, theNamesPath[n][3]/theScale, true, false)
};
////////////////////////////////////
// reset;
app.preferences.rulerUnits = originalRulerUnits;
app.togglePalettes();
}
};
////// collect path info from actiondescriptor, indices start at 1, not 0 //////
function collectPathInfoFromDesc2023 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// based of functions from xbytor’s stdlib;
var idPath = charIDToTypeID( "Path" );
var ref = new ActionReference();
// check if thePath is an index or a dom-path;
if (thePath.constructor == Number) {
ref.putIndex(idPath, thePath)
}
else {
thePath.select();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Path" ), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
};
// get stuff;
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
    var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
    var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
    switch (operation1) {
        case 1097098272:
        var operation = 1097098272 //cTID('Add ');
        break;
        case 1398961266:
        var operation = 1398961266 //cTID('Sbtr');
        break;
        case 1231975538:
        var operation = 1231975538 //cTID('Intr');
        break;
        default:
//		case 1102:
        var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
        break;
        };
// for subpathitem’s count;
    for (var n = 0; n < listKey.count; n++) {
        theArray.push(new Array);
        var points = listKey.getObjectValue(n).getList(sTID('points'));
        try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
        catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
        for (var o = 0; o < points.count; o++) {
            var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
            var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
            var thisPoint = [anchor];
            try {
                var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
                var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
                thisPoint.push(leftDirection)
                }
            catch (e) {
                thisPoint.push(anchor)
                };
            try {
                var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
                var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
                thisPoint.push(rightDirection)
                }
            catch (e) {
                thisPoint.push(anchor)
                };
            try {
                var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
                thisPoint.push(smoothOr)
                }
            catch (e) {thisPoint.push(false)};
            theArray[theArray.length - 1].push(thisPoint);
            };
        theArray[theArray.length - 1].push(closed);
        theArray[theArray.length - 1].push(operation);
        };
    };
// by xbytor, thanks to him;
function cTID (s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };
function sTID (s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// delete path by id //////
function deletePath (theID) {
var desc32 = new ActionDescriptor();
    var ref9 = new ActionReference();
    ref9.putIndex ( stringIDToTypeID( "path" ), theID );
    desc32.putReference( stringIDToTypeID( "null" ), ref9 );
executeAction( stringIDToTypeID( "delete" ), desc32, DialogModes.NO );
};
////// load path as selection //////
function loadPathAsSelection (theIndex) {
    var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc1.putReference( charIDToTypeID( "null" ), ref1 );
        var ref2 = new ActionReference();
        ref2.putIndex( charIDToTypeID( "Path" ), theIndex );
    desc1.putReference( charIDToTypeID( "T   " ), ref2 );
    desc1.putInteger( charIDToTypeID( "Vrsn" ), 1 );
    desc1.putBoolean( stringIDToTypeID( "vectorMaskParams" ), true );
executeAction( charIDToTypeID( "setd" ), desc1, DialogModes.NO );
};
////// determine selected path //////
function selectedPath2020 () {
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref);
var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
//
var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Path"), theIndex); 
var pathDesc = executeActionGet(ref);
var theKind = pathDesc.getEnumerationValue(stringIDToTypeID("kind"));
var theName = pathDesc.getString(stringIDToTypeID("pathName"));
//
return [theIndex, theKind, theName];
}
catch (e) {return undefined}
};
////// make work path from selection //////
function makeWorkPath2 (theTolerance) {
var idPath = charIDToTypeID( "Path" );
var idmake = stringIDToTypeID( "make" );
var idFrom = charIDToTypeID( "From" );
var idnull = stringIDToTypeID( "null" );
// =======================================================
var desc5 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putClass( idPath );
desc5.putReference( idnull, ref3 );
var ref4 = new ActionReference();
ref4.putProperty( charIDToTypeID( "csel" ), charIDToTypeID( "fsel" ) );
desc5.putReference( idFrom, ref4 );
desc5.putUnitDouble( charIDToTypeID( "Tlrn" ), charIDToTypeID( "#Pxl" ), theTolerance );
executeAction( idmake, desc5, DialogModes.NO );
// =======================================================
var desc7 = new ActionDescriptor();
    var ref3 = new ActionReference();
    ref3.putClass( idPath );
desc7.putReference( idnull, ref3 );
var idfrom = stringIDToTypeID( "from" );
    var ref4 = new ActionReference();
    ref4.putProperty( idPath, stringIDToTypeID( "workPath" ) );
desc7.putReference( idFrom, ref4 );
desc7.putString( stringIDToTypeID( "name" ), Math.random() );
executeAction( idmake, desc7, DialogModes.NO );
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref);
var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
return [theIndex/*, theKind, theName*/];
}
catch (e) {return undefined}
};
////// function to get the date //////
function timeString () {
var now = new Date();
return now.getTime()
};
////// 
function deselect () {
var desc5 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty( stringIDToTypeID( "channel" ), stringIDToTypeID( "selection" ) );
desc5.putReference( stringIDToTypeID( "null" ), ref1 );
desc5.putEnumerated( stringIDToTypeID( "to" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "none" ) );
executeAction( stringIDToTypeID( "set" ), desc5, DialogModes.NO );
};
////// x //////
function getSubPathItemExtremes (theArray) {
    var theX1 = theArray[0][0][0];
    var theX2 = theArray[0][0][0];
    var theY1 = theArray[0][0][1];
    var theY2 = theArray[0][0][1];
for (var m = 1; m < theArray.length - 2; m++) {
    var theX1 = Math.min(theX1, theArray[m][0][0]);
    var theX2 = Math.max(theX2, theArray[m][0][0]);
    var theY1 = Math.min(theY1, theArray[m][0][1]);
    var theY2 = Math.max(theY2, theArray[m][0][1]);
    var theWidth = theX2 - theX1;
    var theHeight = theY2 - theY1;
    //alert ("number "+m+"\n"+theValue+"\n"+theWidth+"___"+theHeight)
};
return [theX1, theY1, theX2, theY2, theWidth, theHeight]
};
////// apply threshold //////
function applyThreshold (theValue) {
var desc232 = new ActionDescriptor();
desc232.putInteger( stringIDToTypeID( "level" ), theValue );
executeAction( stringIDToTypeID( "thresholdClassEvent" ), desc232, DialogModes.NO );
};
////// load channel as selection //////
function loadChannelAsSelection(theName, theInvert, theAdd) {  
try {
var idchannel = stringIDToTypeID( "channel" );
if (theAdd == false || theAdd == undefined) {
    var desc70 = new ActionDescriptor();
    var ref9 = new ActionReference();
    ref9.putProperty( idchannel, stringIDToTypeID( "selection" ) );
desc70.putReference( stringIDToTypeID( "null" ), ref9 );
    var ref10 = new ActionReference();
    ref10.putEnumerated( idchannel, idchannel, stringIDToTypeID( theName ) );
desc70.putReference( stringIDToTypeID( "to" ), ref10 );
desc70.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( stringIDToTypeID( "set" ), desc70, DialogModes.NO );
} else {
    var desc221 = new ActionDescriptor();
        var ref5 = new ActionReference();
        ref5.putEnumerated( idchannel, idchannel, stringIDToTypeID(theName) );
        desc221.putReference( stringIDToTypeID( "null" ), ref5 );
desc221.putBoolean(charIDToTypeID("Invr"), theInvert);
        var ref6 = new ActionReference();
        ref6.putProperty( idchannel, stringIDToTypeID( "selection" ) );
    desc221.putReference( stringIDToTypeID( "to" ), ref6 );
executeAction( stringIDToTypeID( "add" ), desc221, DialogModes.NO );
}
} catch (_error) {alert (_error)}
};
////// make a rectangular selection //////
function rectangularSelection (x1, y1, x2, y2, theAdd, theIntersect) {
if (theAdd == false || theAdd == undefined) {var idset = stringIDToTypeID( "set" )}
else {var idset = stringIDToTypeID( "addTo" )};
if (theIntersect == true) {var idset = stringIDToTypeID( "interfaceWhite" );};
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 );
};
////// polygonal lasso tool //////
function polygonalLassoTool (theArray, theSubtract, theAdd) {
if (theSubtract == false || theSubtract == undefined) {var idset = stringIDToTypeID( "set" )}
else {var idset = stringIDToTypeID( "subtractFrom" )};
if (theAdd == true) {var idset = stringIDToTypeID( "addTo" )};
    var desc15 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putProperty( stringIDToTypeID( "channel" ), stringIDToTypeID( "selection" ) );
    desc15.putReference( stringIDToTypeID( "null" ), ref2 );
        var desc16 = new ActionDescriptor();
            var list2 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
                var desc17 = new ActionDescriptor();
                var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
                desc17.putUnitDouble( stringIDToTypeID( "horizontal" ), idpixelsUnit, theArray[m][0] );
                desc17.putUnitDouble( stringIDToTypeID( "vertical" ), idpixelsUnit, theArray[m][1] );
            list2.putObject( stringIDToTypeID( "paint" ), desc17 );
};
        desc16.putList( stringIDToTypeID( "points" ), list2 );
    desc15.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "polygon" ), desc16 );
    var idantiAlias = stringIDToTypeID( "antiAlias" );
    desc15.putBoolean( idantiAlias, false );
executeAction( idset, desc15, DialogModes.NO );
};
////// expand selection //////
function expandSelection (theValue) {
    var idExpn = charIDToTypeID( "Expn" );
        var desc5 = new ActionDescriptor();
        var idBy = charIDToTypeID( "By  " );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc5.putUnitDouble( idBy, idPxl, theValue );
   executeAction( idExpn, desc5, DialogModes.NO );
};
//////
function createSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer() {
// =======================================================
var desc7 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "Clrs" ) );
desc7.putReference( charIDToTypeID( "null" ), ref2 );
executeAction( charIDToTypeID( "Rset" ), desc7, DialogModes.NO );
// =======================================================
var desc7 = new ActionDescriptor();
var ref5 = new ActionReference();
ref5.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Frwr" ) );
desc7.putReference( charIDToTypeID( "null" ), ref5 );
desc7.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc7, DialogModes.NO );
// =======================================================
var desc19 = new ActionDescriptor();
var ref6 = new ActionReference();
ref6.putClass( stringIDToTypeID( "adjustmentLayer" ) );
desc19.putReference( stringIDToTypeID( "null" ), ref6 );
var desc20 = new ActionDescriptor();
    var desc21 = new ActionDescriptor();
    desc21.putEnumerated( stringIDToTypeID( "presetKind" ), stringIDToTypeID( "presetKindType" ), stringIDToTypeID( "presetKindDefault" ) );
var idselectiveColor = stringIDToTypeID( "selectiveColor" );
desc20.putObject( stringIDToTypeID( "type" ), idselectiveColor, desc21 );
var idadjustmentLayer = stringIDToTypeID( "adjustmentLayer" );
desc19.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "adjustmentLayer" ), desc20 );
executeAction( stringIDToTypeID( "make" ), desc19, DialogModes.NO );
// =======================================================
var idcolors = stringIDToTypeID( "colors" );
var idcolorCorrection = stringIDToTypeID( "colorCorrection" );
var desc137 = new ActionDescriptor();
var ref18 = new ActionReference();
ref18.putEnumerated( stringIDToTypeID( "adjustmentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc137.putReference( stringIDToTypeID( "null" ), ref18 );
var desc138 = new ActionDescriptor();
    var list12 = new ActionList();
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "magenta" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "reds" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "yellows" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "greens" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "blues" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "cyans" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "whites" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), -100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "neutrals" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), -100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "blacks" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), -100.000000 );
    list12.putObject( idcolorCorrection, desc139 );
desc138.putList( idcolorCorrection, list12 );
desc138.putEnumerated( stringIDToTypeID( "method" ), stringIDToTypeID( "correctionMethod" ), stringIDToTypeID( "absolute" ) );
var idselectiveColor = stringIDToTypeID( "selectiveColor" );
desc137.putObject( stringIDToTypeID( "to" ), idselectiveColor, desc138 );
executeAction( stringIDToTypeID( "set" ), desc137, DialogModes.NO );
// =======================================================
var desc211 = new ActionDescriptor();
var ref25 = new ActionReference();
ref25.putClass( stringIDToTypeID( "adjustmentLayer" ) );
desc211.putReference( stringIDToTypeID( "null" ), ref25 );
var desc212 = new ActionDescriptor();
    var desc213 = new ActionDescriptor();
    desc213.putInteger( stringIDToTypeID( "level" ), 220 );
var idthresholdClassEvent = stringIDToTypeID( "thresholdClassEvent" );
desc212.putObject( stringIDToTypeID( "type" ), idthresholdClassEvent, desc213 );
var idadjustmentLayer = stringIDToTypeID( "adjustmentLayer" );
desc211.putObject( stringIDToTypeID( "using" ), idadjustmentLayer, desc212 );
executeAction( stringIDToTypeID( "make" ), desc211, DialogModes.NO );

};
////// x //////
function polygonalLassoToolFromPathArray (theArray, theSubtract, theAdd) {
for (var a = 0; a < theArray.length; a++) {
    var thisOne = theArray[a];
    var thisArray = new Array;
    for (var k = 0; k < thisOne.length-2; k++){
        thisArray.push(thisOne[k][0])
    };
    polygonalLassoTool(thisArray, theSubtract, theAdd);
    };
};
////// use magic wand tool //////
function useMagicWand2022 (theCoord) {
var idnull = charIDToTypeID( "null" );
var idPxl = charIDToTypeID( "#Pxl" );
// select tool;
    var desc2 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putClass( stringIDToTypeID( "magicWandTool" ) );
    desc2.putReference( idnull, ref2 );
    desc2.putBoolean( stringIDToTypeID( "dontRecord" ), true );
    desc2.putBoolean( stringIDToTypeID( "forceNotify" ), true );
executeAction( charIDToTypeID( "slct" ), desc2, DialogModes.NO );
// apply tool;
    var desc2 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc2.putReference( idnull, ref2 );
        var desc3 = new ActionDescriptor();
        desc3.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, theCoord[0] );
        desc3.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, theCoord[1] );
    desc2.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Pnt " ), desc3 );
    desc2.putInteger( charIDToTypeID( "Tlrn" ), 30 );
    desc2.putBoolean( charIDToTypeID( "AntA" ), true );
    desc2.putBoolean( stringIDToTypeID("merged"), true);
executeAction( charIDToTypeID( "setd" ), desc2, DialogModes.NO );
};
////// fill black //////
function fillWithBlack (theColor) {
try {
var desc20 = new ActionDescriptor();
desc20.putEnumerated( stringIDToTypeID( "using" ), stringIDToTypeID( "fillContents" ), stringIDToTypeID( theColor ) );
desc20.putUnitDouble( stringIDToTypeID( "opacity" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
desc20.putEnumerated( stringIDToTypeID( "mode" ), stringIDToTypeID( "blendMode" ), stringIDToTypeID( "normal" ) );
executeAction( stringIDToTypeID( "fill" ), desc20, DialogModes.NO );
} catch (e) {}
};
////// invert selection //////
function invertSelection () {
// =======================================================
executeAction( charIDToTypeID( "Invs" ), undefined, DialogModes.NO );
};

 

I attach a JPG sample here for test

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 ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

That takes some specific changes and those might not work out on other images. 

Also there is a dark line on the left edge and the colorful headline could become a problem. 

Screenshot 2023-07-21 at 10.22.07.png

// selectTextsLeftOfBarGraphsYellowBackground
// create rectangular selection for texts left of bars;
// 2023, use it at your own risk;
var time1 = Number(timeString());
moveNumbersLeftOfBarGraphs ();
var time2 = Number(timeString());

////// move numbers to left of bar graphs //////
function moveNumbersLeftOfBarGraphs () {
if (app.documents.length > 0) {
// the number of pixels;
var theScale = 2;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.togglePalettes();
var myDocument = app.activeDocument;
if (myDocument.mode != "DocumentMode.RGB") {myDocument.convertProfile ("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true)};
var theLayer = myDocument.activeLayer;
// resize image;
myDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE);
myDocument.resizeImage (new UnitValue (theScale*100, "%"), new UnitValue (theScale*100, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
// create path;
createSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer();
loadChannelAsSelection("red", true, false);
myDocument.selection.expand(20);
myDocument.selection.contract(20);
myDocument.selection.invert(0);
var lineStartLeft = myDocument.selection.bounds[0];
deselect();
////////////////////////////////////
myDocument.layers[0].remove();
myDocument.layers[0].remove();
deselect ();
////////////////////////////////////
loadChannelAsSelection("red", true, false);
rectangularSelection (0, 0, lineStartLeft-4, myDocument.height, false, true);
rectangularSelection (10, 0, myDocument.width, myDocument.height, false, true);
myDocument.quickMaskMode = true;
useMagicWand2022 ([1,1]);
expandSelection(12);
invertSelection ();
fillWithBlack ("white");
deselect ();
applyThreshold(90);
myDocument.quickMaskMode = false;
var thePathIndex = makeWorkPath2 (0.5);
var thePath = collectPathInfoFromDesc2023 (myDocument, thePathIndex[0]);
deletePath (thePathIndex[0]);
////////////////////////////////////
var lineStartExtremes = getSubPathItemExtremes(thePath[0]);
var theNamesPath = [lineStartExtremes];
// process subpathitems;
for (var m = 1; m < thePath.length; m++) {
var theExtremes = getSubPathItemExtremes(thePath[m]);
// add subpathitem if within the vertical dimensions;
if (theExtremes[1] >= lineStartExtremes[1] && theExtremes[1] <= lineStartExtremes[3]) {
//    if (theExtremes[1] >= lineStartExtremes[1] && theExtremes[3] <= lineStartExtremes[3]) {
        theNamesPath[theNamesPath.length - 1][0] = Math.min(theNamesPath[theNamesPath.length - 1][0], theExtremes[0]);
    theNamesPath[theNamesPath.length - 1][1] = Math.min(theNamesPath[theNamesPath.length - 1][1], theExtremes[1]);
    theNamesPath[theNamesPath.length - 1][2] = Math.max(theNamesPath[theNamesPath.length - 1][2], theExtremes[2]);
    theNamesPath[theNamesPath.length - 1][3] = Math.max(theNamesPath[theNamesPath.length - 1][3], theExtremes[3]);
} else {
// new rectangle;
if (theExtremes[1] > lineStartExtremes[3] && theExtremes[3] > lineStartExtremes[3]) {
    lineStartExtremes = theExtremes;
    theNamesPath.push(theExtremes)
}
};
};
////////////////////////////////////
myDocument.resizeImage (new UnitValue (100/theScale, "%"), new UnitValue (100/theScale, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
//alert (theNamesPath.join("\n\n"));
rectangularSelection (theNamesPath[0][0]/theScale, theNamesPath[0][1]/theScale, theNamesPath[0][2]/theScale, theNamesPath[0][3]/theScale, false, false);
for (var n = 0; n < theNamesPath.length; n++) {
    rectangularSelection (theNamesPath[n][0]/theScale, theNamesPath[n][1]/theScale, theNamesPath[n][2]/theScale, theNamesPath[n][3]/theScale, true, false)
};
////////////////////////////////////
// reset;
app.preferences.rulerUnits = originalRulerUnits;
app.togglePalettes();
}
};
////// collect path info from actiondescriptor, indices start at 1, not 0 //////
function collectPathInfoFromDesc2023 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// based of functions from xbytor’s stdlib;
var idPath = charIDToTypeID( "Path" );
var ref = new ActionReference();
// check if thePath is an index or a dom-path;
if (thePath.constructor == Number) {
ref.putIndex(idPath, thePath)
}
else {
thePath.select();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Path" ), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
};
// get stuff;
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
    var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
    var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
    switch (operation1) {
        case 1097098272:
        var operation = 1097098272 //cTID('Add ');
        break;
        case 1398961266:
        var operation = 1398961266 //cTID('Sbtr');
        break;
        case 1231975538:
        var operation = 1231975538 //cTID('Intr');
        break;
        default:
//		case 1102:
        var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
        break;
        };
// for subpathitem’s count;
    for (var n = 0; n < listKey.count; n++) {
        theArray.push(new Array);
        var points = listKey.getObjectValue(n).getList(sTID('points'));
        try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
        catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
        for (var o = 0; o < points.count; o++) {
            var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
            var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
            var thisPoint = [anchor];
            try {
                var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
                var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
                thisPoint.push(leftDirection)
                }
            catch (e) {
                thisPoint.push(anchor)
                };
            try {
                var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
                var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
                thisPoint.push(rightDirection)
                }
            catch (e) {
                thisPoint.push(anchor)
                };
            try {
                var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
                thisPoint.push(smoothOr)
                }
            catch (e) {thisPoint.push(false)};
            theArray[theArray.length - 1].push(thisPoint);
            };
        theArray[theArray.length - 1].push(closed);
        theArray[theArray.length - 1].push(operation);
        };
    };
// by xbytor, thanks to him;
function cTID (s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };
function sTID (s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// delete path by id //////
function deletePath (theID) {
var desc32 = new ActionDescriptor();
    var ref9 = new ActionReference();
    ref9.putIndex ( stringIDToTypeID( "path" ), theID );
    desc32.putReference( stringIDToTypeID( "null" ), ref9 );
executeAction( stringIDToTypeID( "delete" ), desc32, DialogModes.NO );
};
////// load path as selection //////
function loadPathAsSelection (theIndex) {
    var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc1.putReference( charIDToTypeID( "null" ), ref1 );
        var ref2 = new ActionReference();
        ref2.putIndex( charIDToTypeID( "Path" ), theIndex );
    desc1.putReference( charIDToTypeID( "T   " ), ref2 );
    desc1.putInteger( charIDToTypeID( "Vrsn" ), 1 );
    desc1.putBoolean( stringIDToTypeID( "vectorMaskParams" ), true );
executeAction( charIDToTypeID( "setd" ), desc1, DialogModes.NO );
};
////// determine selected path //////
function selectedPath2020 () {
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref);
var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
//
var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Path"), theIndex); 
var pathDesc = executeActionGet(ref);
var theKind = pathDesc.getEnumerationValue(stringIDToTypeID("kind"));
var theName = pathDesc.getString(stringIDToTypeID("pathName"));
//
return [theIndex, theKind, theName];
}
catch (e) {return undefined}
};
////// make work path from selection //////
function makeWorkPath2 (theTolerance) {
var idPath = charIDToTypeID( "Path" );
var idmake = stringIDToTypeID( "make" );
var idFrom = charIDToTypeID( "From" );
var idnull = stringIDToTypeID( "null" );
// =======================================================
var desc5 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putClass( idPath );
desc5.putReference( idnull, ref3 );
var ref4 = new ActionReference();
ref4.putProperty( charIDToTypeID( "csel" ), charIDToTypeID( "fsel" ) );
desc5.putReference( idFrom, ref4 );
desc5.putUnitDouble( charIDToTypeID( "Tlrn" ), charIDToTypeID( "#Pxl" ), theTolerance );
executeAction( idmake, desc5, DialogModes.NO );
// =======================================================
var desc7 = new ActionDescriptor();
    var ref3 = new ActionReference();
    ref3.putClass( idPath );
desc7.putReference( idnull, ref3 );
var idfrom = stringIDToTypeID( "from" );
    var ref4 = new ActionReference();
    ref4.putProperty( idPath, stringIDToTypeID( "workPath" ) );
desc7.putReference( idFrom, ref4 );
desc7.putString( stringIDToTypeID( "name" ), Math.random() );
executeAction( idmake, desc7, DialogModes.NO );
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref);
var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
return [theIndex/*, theKind, theName*/];
}
catch (e) {return undefined}
};
////// function to get the date //////
function timeString () {
var now = new Date();
return now.getTime()
};
////// 
function deselect () {
var desc5 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty( stringIDToTypeID( "channel" ), stringIDToTypeID( "selection" ) );
desc5.putReference( stringIDToTypeID( "null" ), ref1 );
desc5.putEnumerated( stringIDToTypeID( "to" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "none" ) );
executeAction( stringIDToTypeID( "set" ), desc5, DialogModes.NO );
};
////// x //////
function getSubPathItemExtremes (theArray) {
    var theX1 = theArray[0][0][0];
    var theX2 = theArray[0][0][0];
    var theY1 = theArray[0][0][1];
    var theY2 = theArray[0][0][1];
for (var m = 1; m < theArray.length - 2; m++) {
    var theX1 = Math.min(theX1, theArray[m][0][0]);
    var theX2 = Math.max(theX2, theArray[m][0][0]);
    var theY1 = Math.min(theY1, theArray[m][0][1]);
    var theY2 = Math.max(theY2, theArray[m][0][1]);
    var theWidth = theX2 - theX1;
    var theHeight = theY2 - theY1;
    //alert ("number "+m+"\n"+theValue+"\n"+theWidth+"___"+theHeight)
};
return [theX1, theY1, theX2, theY2, theWidth, theHeight]
};
////// apply threshold //////
function applyThreshold (theValue) {
var desc232 = new ActionDescriptor();
desc232.putInteger( stringIDToTypeID( "level" ), theValue );
executeAction( stringIDToTypeID( "thresholdClassEvent" ), desc232, DialogModes.NO );
};
////// load channel as selection //////
function loadChannelAsSelection(theName, theInvert, theAdd) {  
try {
var idchannel = stringIDToTypeID( "channel" );
if (theAdd == false || theAdd == undefined) {
    var desc70 = new ActionDescriptor();
    var ref9 = new ActionReference();
    ref9.putProperty( idchannel, stringIDToTypeID( "selection" ) );
desc70.putReference( stringIDToTypeID( "null" ), ref9 );
    var ref10 = new ActionReference();
    ref10.putEnumerated( idchannel, idchannel, stringIDToTypeID( theName ) );
desc70.putReference( stringIDToTypeID( "to" ), ref10 );
desc70.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( stringIDToTypeID( "set" ), desc70, DialogModes.NO );
} else {
    var desc221 = new ActionDescriptor();
        var ref5 = new ActionReference();
        ref5.putEnumerated( idchannel, idchannel, stringIDToTypeID(theName) );
        desc221.putReference( stringIDToTypeID( "null" ), ref5 );
desc221.putBoolean(charIDToTypeID("Invr"), theInvert);
        var ref6 = new ActionReference();
        ref6.putProperty( idchannel, stringIDToTypeID( "selection" ) );
    desc221.putReference( stringIDToTypeID( "to" ), ref6 );
executeAction( stringIDToTypeID( "add" ), desc221, DialogModes.NO );
}
} catch (_error) {alert (_error)}
};
////// make a rectangular selection //////
function rectangularSelection (x1, y1, x2, y2, theAdd, theIntersect) {
if (theAdd == false || theAdd == undefined) {var idset = stringIDToTypeID( "set" )}
else {var idset = stringIDToTypeID( "addTo" )};
if (theIntersect == true) {var idset = stringIDToTypeID( "interfaceWhite" );};
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 );
};
////// polygonal lasso tool //////
function polygonalLassoTool (theArray, theSubtract, theAdd) {
if (theSubtract == false || theSubtract == undefined) {var idset = stringIDToTypeID( "set" )}
else {var idset = stringIDToTypeID( "subtractFrom" )};
if (theAdd == true) {var idset = stringIDToTypeID( "addTo" )};
    var desc15 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putProperty( stringIDToTypeID( "channel" ), stringIDToTypeID( "selection" ) );
    desc15.putReference( stringIDToTypeID( "null" ), ref2 );
        var desc16 = new ActionDescriptor();
            var list2 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
                var desc17 = new ActionDescriptor();
                var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
                desc17.putUnitDouble( stringIDToTypeID( "horizontal" ), idpixelsUnit, theArray[m][0] );
                desc17.putUnitDouble( stringIDToTypeID( "vertical" ), idpixelsUnit, theArray[m][1] );
            list2.putObject( stringIDToTypeID( "paint" ), desc17 );
};
        desc16.putList( stringIDToTypeID( "points" ), list2 );
    desc15.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "polygon" ), desc16 );
    var idantiAlias = stringIDToTypeID( "antiAlias" );
    desc15.putBoolean( idantiAlias, false );
executeAction( idset, desc15, DialogModes.NO );
};
////// expand selection //////
function expandSelection (theValue) {
    var idExpn = charIDToTypeID( "Expn" );
        var desc5 = new ActionDescriptor();
        var idBy = charIDToTypeID( "By  " );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc5.putUnitDouble( idBy, idPxl, theValue );
   executeAction( idExpn, desc5, DialogModes.NO );
};
//////
function createSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer() {
// =======================================================
var desc7 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "Clrs" ) );
desc7.putReference( charIDToTypeID( "null" ), ref2 );
executeAction( charIDToTypeID( "Rset" ), desc7, DialogModes.NO );
// =======================================================
var desc7 = new ActionDescriptor();
var ref5 = new ActionReference();
ref5.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Frwr" ) );
desc7.putReference( charIDToTypeID( "null" ), ref5 );
desc7.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc7, DialogModes.NO );
// =======================================================
var desc19 = new ActionDescriptor();
var ref6 = new ActionReference();
ref6.putClass( stringIDToTypeID( "adjustmentLayer" ) );
desc19.putReference( stringIDToTypeID( "null" ), ref6 );
var desc20 = new ActionDescriptor();
    var desc21 = new ActionDescriptor();
    desc21.putEnumerated( stringIDToTypeID( "presetKind" ), stringIDToTypeID( "presetKindType" ), stringIDToTypeID( "presetKindDefault" ) );
var idselectiveColor = stringIDToTypeID( "selectiveColor" );
desc20.putObject( stringIDToTypeID( "type" ), idselectiveColor, desc21 );
var idadjustmentLayer = stringIDToTypeID( "adjustmentLayer" );
desc19.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "adjustmentLayer" ), desc20 );
executeAction( stringIDToTypeID( "make" ), desc19, DialogModes.NO );
// =======================================================
var idcolors = stringIDToTypeID( "colors" );
var idcolorCorrection = stringIDToTypeID( "colorCorrection" );
var desc137 = new ActionDescriptor();
var ref18 = new ActionReference();
ref18.putEnumerated( stringIDToTypeID( "adjustmentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc137.putReference( stringIDToTypeID( "null" ), ref18 );
var desc138 = new ActionDescriptor();
    var list12 = new ActionList();
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "magenta" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "reds" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "yellows" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "greens" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "blues" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "cyans" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "whites" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), -100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "neutrals" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), -100.000000 );
        list12.putObject( idcolorCorrection, desc139 );
        var desc139 = new ActionDescriptor();
        desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "blacks" ) );
        desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), -100.000000 );
    list12.putObject( idcolorCorrection, desc139 );
desc138.putList( idcolorCorrection, list12 );
desc138.putEnumerated( stringIDToTypeID( "method" ), stringIDToTypeID( "correctionMethod" ), stringIDToTypeID( "absolute" ) );
var idselectiveColor = stringIDToTypeID( "selectiveColor" );
desc137.putObject( stringIDToTypeID( "to" ), idselectiveColor, desc138 );
executeAction( stringIDToTypeID( "set" ), desc137, DialogModes.NO );
// =======================================================
var desc211 = new ActionDescriptor();
var ref25 = new ActionReference();
ref25.putClass( stringIDToTypeID( "adjustmentLayer" ) );
desc211.putReference( stringIDToTypeID( "null" ), ref25 );
var desc212 = new ActionDescriptor();
    var desc213 = new ActionDescriptor();
    desc213.putInteger( stringIDToTypeID( "level" ), 220 );
var idthresholdClassEvent = stringIDToTypeID( "thresholdClassEvent" );
desc212.putObject( stringIDToTypeID( "type" ), idthresholdClassEvent, desc213 );
var idadjustmentLayer = stringIDToTypeID( "adjustmentLayer" );
desc211.putObject( stringIDToTypeID( "using" ), idadjustmentLayer, desc212 );
executeAction( stringIDToTypeID( "make" ), desc211, DialogModes.NO );

};
////// x //////
function polygonalLassoToolFromPathArray (theArray, theSubtract, theAdd) {
for (var a = 0; a < theArray.length; a++) {
    var thisOne = theArray[a];
    var thisArray = new Array;
    for (var k = 0; k < thisOne.length-2; k++){
        thisArray.push(thisOne[k][0])
    };
    polygonalLassoTool(thisArray, theSubtract, theAdd);
    };
};
////// use magic wand tool //////
function useMagicWand2022 (theCoord) {
var idnull = charIDToTypeID( "null" );
var idPxl = charIDToTypeID( "#Pxl" );
// select tool;
    var desc2 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putClass( stringIDToTypeID( "magicWandTool" ) );
    desc2.putReference( idnull, ref2 );
    desc2.putBoolean( stringIDToTypeID( "dontRecord" ), true );
    desc2.putBoolean( stringIDToTypeID( "forceNotify" ), true );
executeAction( charIDToTypeID( "slct" ), desc2, DialogModes.NO );
// apply tool;
    var desc2 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc2.putReference( idnull, ref2 );
        var desc3 = new ActionDescriptor();
        desc3.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, theCoord[0] );
        desc3.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, theCoord[1] );
    desc2.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Pnt " ), desc3 );
    desc2.putInteger( charIDToTypeID( "Tlrn" ), 30 );
    desc2.putBoolean( charIDToTypeID( "AntA" ), true );
    desc2.putBoolean( stringIDToTypeID("merged"), true);
executeAction( charIDToTypeID( "setd" ), desc2, DialogModes.NO );
};
////// fill black //////
function fillWithBlack (theColor) {
try {
var desc20 = new ActionDescriptor();
desc20.putEnumerated( stringIDToTypeID( "using" ), stringIDToTypeID( "fillContents" ), stringIDToTypeID( theColor ) );
desc20.putUnitDouble( stringIDToTypeID( "opacity" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
desc20.putEnumerated( stringIDToTypeID( "mode" ), stringIDToTypeID( "blendMode" ), stringIDToTypeID( "normal" ) );
executeAction( stringIDToTypeID( "fill" ), desc20, DialogModes.NO );
} catch (e) {}
};
////// invert selection //////
function invertSelection () {
// =======================================================
executeAction( charIDToTypeID( "Invs" ), undefined, 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
Engaged ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

quote

That takes some specific changes and those might not work out on other images. 

Also there is a dark line on the left edge and the colorful headline could become a problem. 


By @c.pfaffenbichler

Therefore, isn't it better to create the script in such a way that in each type of chart image, I first select text on the left side with the color range and then execute the script? 

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
Engaged ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

quote

T

By @c.pfaffenbichler

Can you tell me how to increase space that must apply by following script between layers to 2X? (this is your script that shared with me before)  

// lift discontinuous content from layer onto individual layers and offset them;
// for rgb-images;
// 2023, use it at your own risk;
if (app.documents.length > 0 && app.activeDocument.mode == DocumentMode.RGB && activeDocument.activeLayer.kind == "LayerKind.NORMAL") {
	app.activeDocument.suspendHistory("split layers", "main ()");
	};
function main () {
myDocument = app.activeDocument;
myDocument.activeChannels = [myDocument.channels[0], myDocument.channels[1], myDocument.channels[2]];
var theOffset = 50;
// load transarency;
// =======================================================
    var desc11 = new ActionDescriptor();
        var ref6 = new ActionReference();
        ref6.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc11.putReference( charIDToTypeID( "null" ), ref6 );
        var ref7 = new ActionReference();
        ref7.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
    desc11.putReference( charIDToTypeID( "T   " ), ref7 );
executeAction( charIDToTypeID( "setd" ), desc11, DialogModes.NO );
//
var check = true;
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// set to 72ppi;
var originalResolution = app.activeDocument.resolution;
myDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE);
var theLayer = myDocument.activeLayer;
// use threshold to heighten non black pixels;
myDocument.quickMaskMode = true;
myDocument.activeLayer.threshold(1);
myDocument.quickMaskMode = false;
// create work path;
makeWorkPath2(1);
var subPathsNumber = myDocument.pathItems[myDocument.pathItems.length-1].subPathItems.length;
// do the operation;
{
	var thePathInfo = collectPathInfoFromDesc2012(myDocument, myDocument.pathItems[myDocument.pathItems.length-1]);
    var theLayers = new Array;
// create one path for every subpathitem:
	for (var m = 0; m < thePathInfo.length; m++) {
		var theSubPath = thePathInfo[m];
		var aPath = createPath2012 ([theSubPath], m+"_path");
		aPath.makeSelection(0, true, SelectionType.REPLACE);
// expand;
		myDocument.selection.expand(6);
// layer via copy;
		try {
			var id14 = charIDToTypeID( "CpTL" );
			executeAction( id14, undefined, DialogModes.NO );
			myDocument.activeLayer.name = theLayer.name + "_" + (m+1)
			}
		catch (e) {};
        theLayers.push(myDocument.activeLayer);
		myDocument.pathItems[myDocument.pathItems.length-1].remove();
		myDocument.activeLayer = theLayer;
		};
		theLayer.visible = false;
	};
// offset; 
    for (var n = 1; n < theLayers.length; n++) {
        theLayers[n].translate (0, theOffset*n);
    };
    myDocument.crop([0 ,0 ,myDocument.width, myDocument.height + theOffset * (theLayers.length-1)]);
// reset;
app.preferences.rulerUnits = originalRulerUnits;
myDocument.resizeImage (undefined, undefined, originalResolution, ResampleMethod.NONE);
};
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2012 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// based of functions from xbytor’s stdlib;
var ref = new ActionReference();
for (var l = 0; l < myDocument.pathItems.length; l++) {
	var thisPath = myDocument.pathItems[l];
	if (thisPath == thePath && thisPath.name == "Work Path") {
		ref.putProperty(cTID("Path"), cTID("WrPt"));
		};
	if (thisPath == thePath && thisPath.name != "Work Path" && thisPath.kind != PathKind.VECTORMASK) {
		ref.putIndex(cTID("Path"), l + 1);
		};
	if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
        var idPath = charIDToTypeID( "Path" );
        var idPath = charIDToTypeID( "Path" );
        var idvectorMask = stringIDToTypeID( "vectorMask" );
        ref.putEnumerated( idPath, idPath, idvectorMask );
		};
	};
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
	var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
	var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
	switch (operation1) {
		case 1097098272:
		var operation = 1097098272 //cTID('Add ');
		break;
		case 1398961266:
		var operation = 1398961266 //cTID('Sbtr');
		break;
		case 1231975538:
		var operation = 1231975538 //cTID('Intr');
		break;
		default:
//		case 1102:
		var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
		break;
		};
// for subpathitem’s count;
	for (var n = 0; n < listKey.count; n++) {
		theArray.push(new Array);
		var points = listKey.getObjectValue(n).getList(sTID('points'));
		try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
		catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
		for (var o = 0; o < points.count; o++) {
			var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
			var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
			var thisPoint = [anchor];
			try {
				var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
				var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
				thisPoint.push(leftDirection)
				}
			catch (e) {
				thisPoint.push(anchor)
				};
			try {
				var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
				var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
				thisPoint.push(rightDirection)
				}
			catch (e) {
				thisPoint.push(anchor)
				};
			try {
				var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
				thisPoint.push(smoothOr)
				}
			catch (e) {thisPoint.push(false)};
			theArray[theArray.length - 1].push(thisPoint);
			};
		theArray[theArray.length - 1].push(closed);
		theArray[theArray.length - 1].push(operation);
		};
	};
// by xbytor, thanks to him;
function cTID (s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };
function sTID (s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2012(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// thanks to xbytor;
cTID = function(s) {return app.charIDToTypeID(s)};
sTID = function(s) {return app.stringIDToTypeID(s)};
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(cTID('Path'), cTID('WrPt'));
    desc1.putReference(sTID('null'), ref1);
    var list1 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
	var thisSubPath = theArray[m];
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
    var list2 = new ActionList();
    var desc3 = new ActionDescriptor();
    desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
    var list3 = new ActionList();
for (var n = 0; n < thisSubPath.length - 2; n++) {
	var thisPoint = thisSubPath[n];
    var desc4 = new ActionDescriptor();
    var desc5 = new ActionDescriptor();
    desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
    desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
    desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
    var desc6 = new ActionDescriptor();
    desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
    desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
    desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
    var desc7 = new ActionDescriptor();
    desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
    desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
    desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
    desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
    list3.putObject(cTID('Pthp'), desc4);
	};
    desc3.putList(cTID('Pts '), list3);
    list2.putObject(cTID('Sbpl'), desc3);
    desc2.putList(cTID('SbpL'), list2);
    list1.putObject(cTID('PaCm'), desc2);
	};
    desc1.putList(cTID('T   '), list1);
    executeAction(cTID('setd'), desc1, DialogModes.NO)
if (hasVectorMask() == false) {
app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1].name = thePathsName;
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1];
}
else {
app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2].name = thePathsName;
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2];
};
app.preferences.rulerUnits = originalRulerUnits;
return myPathItem
};
////// make work path from selection //////
function makeWorkPath2 (theTolerance) {
    var idPath = charIDToTypeID( "Path" );
    var idmake = stringIDToTypeID( "make" );
    var idFrom = charIDToTypeID( "From" );
    var idnull = stringIDToTypeID( "null" );
    // =======================================================
    var desc5 = new ActionDescriptor();
    var ref3 = new ActionReference();
    ref3.putClass( idPath );
    desc5.putReference( idnull, ref3 );
    var ref4 = new ActionReference();
    ref4.putProperty( charIDToTypeID( "csel" ), charIDToTypeID( "fsel" ) );
    desc5.putReference( idFrom, ref4 );
    desc5.putUnitDouble( charIDToTypeID( "Tlrn" ), charIDToTypeID( "#Pxl" ), theTolerance );
    executeAction( idmake, desc5, DialogModes.NO );
    // =======================================================
    var desc7 = new ActionDescriptor();
        var ref3 = new ActionReference();
        ref3.putClass( idPath );
    desc7.putReference( idnull, ref3 );
    var idfrom = stringIDToTypeID( "from" );
        var ref4 = new ActionReference();
        ref4.putProperty( idPath, stringIDToTypeID( "workPath" ) );
    desc7.putReference( idFrom, ref4 );
    desc7.putString( stringIDToTypeID( "name" ), Math.random() );
    executeAction( idmake, desc7, DialogModes.NO );
    try {
    var ref = new ActionReference();
    ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
    var docDesc = executeActionGet(ref);
    var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
    return [theIndex/*, theKind, theName*/];
    }
    catch (e) {return undefined}
    };
// from »Flatten All Masks.jsx« by jeffrey tranberry;
function hasVectorMask() {
	var hasVectorMask = false;
	try {
		var ref = new ActionReference();
		var keyVectorMaskEnabled = app.stringIDToTypeID( 'vectorMask' );
		var keyKind = app.charIDToTypeID( 'Knd ' );
		ref.putEnumerated( app.charIDToTypeID( 'Path' ), app.charIDToTypeID( 'Ordn' ), keyVectorMaskEnabled );
		var desc = executeActionGet( ref );
		if ( desc.hasKey( keyKind ) ) {
			var kindValue = desc.getEnumerationValue( keyKind );
			if (kindValue == keyVectorMaskEnabled) {
				hasVectorMask = true;
			}
		}
	}catch(e) {
		hasVectorMask = false;
	}
	return hasVectorMask;
};

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
Engaged ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

quote
quote

T

By @c.pfaffenbichler

Can you tell me how to increase space that must apply by following script between layers to 2X? (this is your script that shared with me before)  


By @abolfazl29032603daba

@c.pfaffenbichler  

no need answer sir 

I modified it by chatGPT 

// lift discontinuous content from layer onto individual layers and offset them;
// for rgb-images;
// 2023, use it at your own risk;
if (app.documents.length > 0 && app.activeDocument.mode == DocumentMode.RGB && activeDocument.activeLayer.kind == "LayerKind.NORMAL") {
	app.activeDocument.suspendHistory("split layers", "main ()");
	};
function main () {
myDocument = app.activeDocument;
myDocument.activeChannels = [myDocument.channels[0], myDocument.channels[1], myDocument.channels[2]];
var theOffset = 100;
// load transarency;
// =======================================================
    var desc11 = new ActionDescriptor();
        var ref6 = new ActionReference();
        ref6.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc11.putReference( charIDToTypeID( "null" ), ref6 );
        var ref7 = new ActionReference();
        ref7.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
    desc11.putReference( charIDToTypeID( "T   " ), ref7 );
executeAction( charIDToTypeID( "setd" ), desc11, DialogModes.NO );
//
var check = true;
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// set to 72ppi;
var originalResolution = app.activeDocument.resolution;
myDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE);
var theLayer = myDocument.activeLayer;
// use threshold to heighten non black pixels;
myDocument.quickMaskMode = true;
myDocument.activeLayer.threshold(1);
myDocument.quickMaskMode = false;
// create work path;
makeWorkPath2(1);
var subPathsNumber = myDocument.pathItems[myDocument.pathItems.length-1].subPathItems.length;
// do the operation;
{
	var thePathInfo = collectPathInfoFromDesc2012(myDocument, myDocument.pathItems[myDocument.pathItems.length-1]);
    var theLayers = new Array;
// create one path for every subpathitem:
	for (var m = 0; m < thePathInfo.length; m++) {
		var theSubPath = thePathInfo[m];
		var aPath = createPath2012 ([theSubPath], m+"_path");
		aPath.makeSelection(0, true, SelectionType.REPLACE);
// expand;
		myDocument.selection.expand(6);
// layer via copy;
		try {
			var id14 = charIDToTypeID( "CpTL" );
			executeAction( id14, undefined, DialogModes.NO );
			myDocument.activeLayer.name = theLayer.name + "_" + (m+1)
			}
		catch (e) {};
        theLayers.push(myDocument.activeLayer);
		myDocument.pathItems[myDocument.pathItems.length-1].remove();
		myDocument.activeLayer = theLayer;
		};
		theLayer.visible = false;
	};
// offset; 
    for (var n = 1; n < theLayers.length; n++) {
        theLayers[n].translate (0, theOffset*2*n);
    };
    myDocument.crop([0 ,0 ,myDocument.width, myDocument.height + theOffset *2* (theLayers.length-1)]);
// reset;
app.preferences.rulerUnits = originalRulerUnits;
myDocument.resizeImage (undefined, undefined, originalResolution, ResampleMethod.NONE);
};
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2012 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// based of functions from xbytor’s stdlib;
var ref = new ActionReference();
for (var l = 0; l < myDocument.pathItems.length; l++) {
	var thisPath = myDocument.pathItems[l];
	if (thisPath == thePath && thisPath.name == "Work Path") {
		ref.putProperty(cTID("Path"), cTID("WrPt"));
		};
	if (thisPath == thePath && thisPath.name != "Work Path" && thisPath.kind != PathKind.VECTORMASK) {
		ref.putIndex(cTID("Path"), l + 1);
		};
	if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
        var idPath = charIDToTypeID( "Path" );
        var idPath = charIDToTypeID( "Path" );
        var idvectorMask = stringIDToTypeID( "vectorMask" );
        ref.putEnumerated( idPath, idPath, idvectorMask );
		};
	};
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
	var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
	var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
	switch (operation1) {
		case 1097098272:
		var operation = 1097098272 //cTID('Add ');
		break;
		case 1398961266:
		var operation = 1398961266 //cTID('Sbtr');
		break;
		case 1231975538:
		var operation = 1231975538 //cTID('Intr');
		break;
		default:
//		case 1102:
		var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
		break;
		};
// for subpathitem’s count;
	for (var n = 0; n < listKey.count; n++) {
		theArray.push(new Array);
		var points = listKey.getObjectValue(n).getList(sTID('points'));
		try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
		catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
		for (var o = 0; o < points.count; o++) {
			var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
			var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
			var thisPoint = [anchor];
			try {
				var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
				var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
				thisPoint.push(leftDirection)
				}
			catch (e) {
				thisPoint.push(anchor)
				};
			try {
				var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
				var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
				thisPoint.push(rightDirection)
				}
			catch (e) {
				thisPoint.push(anchor)
				};
			try {
				var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
				thisPoint.push(smoothOr)
				}
			catch (e) {thisPoint.push(false)};
			theArray[theArray.length - 1].push(thisPoint);
			};
		theArray[theArray.length - 1].push(closed);
		theArray[theArray.length - 1].push(operation);
		};
	};
// by xbytor, thanks to him;
function cTID (s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };
function sTID (s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2012(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// thanks to xbytor;
cTID = function(s) {return app.charIDToTypeID(s)};
sTID = function(s) {return app.stringIDToTypeID(s)};
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(cTID('Path'), cTID('WrPt'));
    desc1.putReference(sTID('null'), ref1);
    var list1 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
	var thisSubPath = theArray[m];
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
    var list2 = new ActionList();
    var desc3 = new ActionDescriptor();
    desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
    var list3 = new ActionList();
for (var n = 0; n < thisSubPath.length - 2; n++) {
	var thisPoint = thisSubPath[n];
    var desc4 = new ActionDescriptor();
    var desc5 = new ActionDescriptor();
    desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
    desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
    desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
    var desc6 = new ActionDescriptor();
    desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
    desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
    desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
    var desc7 = new ActionDescriptor();
    desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
    desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
    desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
    desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
    list3.putObject(cTID('Pthp'), desc4);
	};
    desc3.putList(cTID('Pts '), list3);
    list2.putObject(cTID('Sbpl'), desc3);
    desc2.putList(cTID('SbpL'), list2);
    list1.putObject(cTID('PaCm'), desc2);
	};
    desc1.putList(cTID('T   '), list1);
    executeAction(cTID('setd'), desc1, DialogModes.NO)
if (hasVectorMask() == false) {
app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1].name = thePathsName;
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1];
}
else {
app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2].name = thePathsName;
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2];
};
app.preferences.rulerUnits = originalRulerUnits;
return myPathItem
};
////// make work path from selection //////
function makeWorkPath2 (theTolerance) {
    var idPath = charIDToTypeID( "Path" );
    var idmake = stringIDToTypeID( "make" );
    var idFrom = charIDToTypeID( "From" );
    var idnull = stringIDToTypeID( "null" );
    // =======================================================
    var desc5 = new ActionDescriptor();
    var ref3 = new ActionReference();
    ref3.putClass( idPath );
    desc5.putReference( idnull, ref3 );
    var ref4 = new ActionReference();
    ref4.putProperty( charIDToTypeID( "csel" ), charIDToTypeID( "fsel" ) );
    desc5.putReference( idFrom, ref4 );
    desc5.putUnitDouble( charIDToTypeID( "Tlrn" ), charIDToTypeID( "#Pxl" ), theTolerance );
    executeAction( idmake, desc5, DialogModes.NO );
    // =======================================================
    var desc7 = new ActionDescriptor();
        var ref3 = new ActionReference();
        ref3.putClass( idPath );
    desc7.putReference( idnull, ref3 );
    var idfrom = stringIDToTypeID( "from" );
        var ref4 = new ActionReference();
        ref4.putProperty( idPath, stringIDToTypeID( "workPath" ) );
    desc7.putReference( idFrom, ref4 );
    desc7.putString( stringIDToTypeID( "name" ), Math.random() );
    executeAction( idmake, desc7, DialogModes.NO );
    try {
    var ref = new ActionReference();
    ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
    var docDesc = executeActionGet(ref);
    var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
    return [theIndex/*, theKind, theName*/];
    }
    catch (e) {return undefined}
    };
// from »Flatten All Masks.jsx« by jeffrey tranberry;
function hasVectorMask() {
	var hasVectorMask = false;
	try {
		var ref = new ActionReference();
		var keyVectorMaskEnabled = app.stringIDToTypeID( 'vectorMask' );
		var keyKind = app.charIDToTypeID( 'Knd ' );
		ref.putEnumerated( app.charIDToTypeID( 'Path' ), app.charIDToTypeID( 'Ordn' ), keyVectorMaskEnabled );
		var desc = executeActionGet( ref );
		if ( desc.hasKey( keyKind ) ) {
			var kindValue = desc.getEnumerationValue( keyKind );
			if (kindValue == keyVectorMaskEnabled) {
				hasVectorMask = true;
			}
		}
	}catch(e) {
		hasVectorMask = false;
	}
	return hasVectorMask;
};

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
Engaged ,
Jul 24, 2023 Jul 24, 2023

Copy link to clipboard

Copied

quote

That takes some specific changes and those might not work out on other images. 

Also there is a dark line on the left edge and the colorful headline could become a problem. 

Screenshot 2023-07-21 at 10.22.07.png

 


By @c.pfaffenbichler

If i get different image with different background color next time, can i modify your script by chatGPT for it? 

If i want to modify your script for it, what i must request from chatGPT? for example i must get color code of background and text color code and provide them to chatGPT and what i must ask from it?

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 ,
Jul 24, 2023 Jul 24, 2023

Copy link to clipboard

Copied

Chat GPT is none of my business. 

 

I think you should familiarize yourself with Photoshop Scripting, go through the operations to determine at which step the actual result does not meet the expected result anymore, figure out which of the preceding steps needs modification, change it and test again. 

 

Or, if you are especially industrious, try to create a proper AI application for this task – which is not something I could do and that would exceed Photoshop’s current capabilities. 

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
Engaged ,
Aug 15, 2023 Aug 15, 2023

Copy link to clipboard

Copied

LATEST
quote

C

By @c.pfaffenbichler

Hi, Can you tell me why following photoshop script that you provide to me why not working on attached sample JPG file? 
https://drive.google.com/file/d/1Ll8auf_e2g4qdYyhPAzPXyb0zwgFS20k/view?usp=sharing
 

Please tell me how you find problem too. for example with which tool you found that image have dirt 

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
Engaged ,
Jun 24, 2023 Jun 24, 2023

Copy link to clipboard

Copied

quote

This should perform at least somewhat faster if you want to give it a try: 

 

 

 


By @c.pfaffenbichler

 

How can i run a script on only selected layer? (not all layers - only selected layer)

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
Engaged ,
Jul 10, 2023 Jul 10, 2023

Copy link to clipboard

Copied

quote

This should perform at least somewhat faster if you want to give it a try: 


By @c.pfaffenbichler

I have two question about your script. 

1) can you tell me why your script not working on attached sample png? 

2) how can i run your script on specific layer only and not all image layers?(both png and jpg format). for example in following i want to run your script on »Layer 1« only? 

f7222d41-c09a-43ec-bfad-61d409234a8d.gif

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