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

Need a script to spacing vertically between different image components

Engaged ,
Jun 23, 2023 Jun 23, 2023

I have some transparent PNG chart images like following: 

6.png 

Now i want to spacing vertically between different image components like following: 

6(edit).png 

which script can do this? 

maybe a script need to convert all components of image to separate layers and then make space between layers and increase crop.

TOPICS
Actions and scripting
1.0K
Translate
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 24, 2023 Jun 24, 2023
// 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 theOf
...
Translate
Community Expert , Jun 25, 2023 Jun 25, 2023

You can remove the if-clause

 

if (subPathsNumber > 30) {
	check = confirm("warning\rthere appear to be "+subPathsNumber+" elements.\rif this number is too high noise may have caused them.\rthis may result in a crash.\rproceed?")
	};

 

and then the line

 

if (check == true)

 

and the corresponding closing brackets. 

Translate
Adobe
Community Expert ,
Jun 23, 2023 Jun 23, 2023

If you have all components on single layer then yes, each components needs to be on its own layer and canvas size or image must be enlarged to fit all components with larger spacing between them. 

 

If you have chart images that are similar or exactly the same in terms of number of components, spacing between them... then Photoshop action may work for you, otherwise I am not sure, perhaps script can work in some circumstances.

 

I will tag few scripters which can give you precise answer or guideline or even script @c.pfaffenbichler @Stephen Marsh @Chuck Uebele 

Translate
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
quote

If you have all components on single layer then yes,


By @Bojan Živković

my images components are on single layer but script can convert all components of my images into separate layers easily because my images are transparent

Translate
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 24, 2023 Jun 24, 2023
// 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;
// check for a high number of paths;
if (subPathsNumber > 30) {
	check = confirm("warning\rthere appear to be "+subPathsNumber+" elements.\rif this number is too high noise may have caused them.\rthis may result in a crash.\rproceed?")
	};
// do the operation;
if (check == true) {
	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;
};
Translate
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

wow - wonderful

Translate
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
quote

By @c.pfaffenbichler

some scripts like your script that use split 2 layer feature sometimes ask a question for spliting layers. how to remove this question from similar and your script? 
photo_2023-06-25_07-55-03.jpg

Translate
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 25, 2023 Jun 25, 2023

You can remove the if-clause

 

if (subPathsNumber > 30) {
	check = confirm("warning\rthere appear to be "+subPathsNumber+" elements.\rif this number is too high noise may have caused them.\rthis may result in a crash.\rproceed?")
	};

 

and then the line

 

if (check == true)

 

and the corresponding closing brackets. 

Translate
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 25, 2023 Jun 25, 2023
LATEST
quote

You can remove the if-clause

 

 

if (subPathsNumber > 30) {
	check = confirm("warning\rthere appear to be "+subPathsNumber+" elements.\rif this number is too high noise may have caused them.\rthis may result in a crash.\rproceed?")
	};

 

 

and then the line

 

 

if (check == true)

 

 

and the corresponding closing brackets. 


By @c.pfaffenbichler

this mean i must remove following: 

if (subPathsNumber > 30) {
	check = confirm("warning\rthere appear to be "+subPathsNumber+" elements.\rif this number is too high noise may have caused them.\rthis may result in a crash.\rproceed?")
	};

after removeing i must remove following? 

if (check == true)

 

Translate
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