Skip to main content
Participant
May 11, 2020
Question

Building my own Plug-in Filter

  • May 11, 2020
  • 1 reply
  • 1344 views

I am in the process of writing a plug-in filter in Adobe Photoshop and have the following question: Is it possible for a  plug-in filter to determine the pixel position (upper left corner, for example) of the passed in image via FilterRecord relative to the “main” image displayed in photoshop?   

This topic has been closed for replies.

1 reply

JJMack
Community Expert
Community Expert
May 11, 2020

I do not know actually what you are asking. However I would  think that any image passed is mass as a rectangle canvas where 0,0 will be top left  and width, height the bottom right.  If the image is being pass is a layer in the current document the.  Its relative  document position would also be included it may even be outside the document canvas.

JJMack
c.pfaffenbichler
Community Expert
Community Expert
May 11, 2020

And Layers’ bounds can be evaluated with JavaScript both via the DOM and AM-code. 

JJMack
Community Expert
Community Expert
May 11, 2020

Here is the script code for the current layer  the script will set guides for the layers bounds and its center and an display the  layer information.

 

// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events
app.bringToFront();

// Save the current preferences
var startRulerUnits = app.preferences.rulerUnits;
// Set Photoshop to use pixels 
app.preferences.rulerUnits = Units.PIXELS;

try{
	var LB = activeDocument.activeLayer.bounds;
	var LWidth = (LB[2].value) - (LB[0].value);
	var LHeight = (LB[3].value) - (LB[1].value);
	MarkX((LB[0].value + LWidth/2));
	MarkX(LB[0].value);
	MarkX(LB[2].value);
	MarkY((LB[1].value + LHeight/2));
	MarkY(LB[1].value)	
	MarkY(LB[3].value)
	alert("'" + activeDocument.activeLayer.name + "' Layer Bounds\nTop Left " +  LB[0].value + "X," +  LB[1].value + "Y   Bottom Right "  +  LB[2].value + "X," +  LB[3].value
		+ "Y\nWidth " +  LWidth + "px   Height " + LHeight +"px" 
		+ "\nLayer center relative to canvas " + (LB[0].value + LWidth/2) + "X," +  (LB[1].value + LHeight/2) +"Y" 
		, "Layer Bounds Info");
}
catch(e){alert("Requires a layer targered");}

// Return the app preferences
app.preferences.rulerUnits = startRulerUnits;
function MarkX(x) {
// =======================================================
var idMk = charIDToTypeID( "Mk  " );
    var desc61 = new ActionDescriptor();
    var idNw = charIDToTypeID( "Nw  " );
        var desc62 = new ActionDescriptor();
        var idPstn = charIDToTypeID( "Pstn" );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc62.putUnitDouble( idPstn, idPxl, x);
        var idOrnt = charIDToTypeID( "Ornt" );
        var idOrnt = charIDToTypeID( "Ornt" );
        var idVrtc = charIDToTypeID( "Vrtc" );
        desc62.putEnumerated( idOrnt, idOrnt, idVrtc );
    var idGd = charIDToTypeID( "Gd  " );
    desc61.putObject( idNw, idGd, desc62 );
executeAction( idMk, desc61, DialogModes.NO );
}
function MarkY(y) {
// =======================================================
var idMk = charIDToTypeID( "Mk  " );
    var desc63 = new ActionDescriptor();
    var idNw = charIDToTypeID( "Nw  " );
        var desc64 = new ActionDescriptor();
        var idPstn = charIDToTypeID( "Pstn" );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc64.putUnitDouble( idPstn, idPxl, y );
        var idOrnt = charIDToTypeID( "Ornt" );
        var idOrnt = charIDToTypeID( "Ornt" );
        var idHrzn = charIDToTypeID( "Hrzn" );
        desc64.putEnumerated( idOrnt, idOrnt, idHrzn );
    var idGd = charIDToTypeID( "Gd  " );
    desc63.putObject( idNw, idGd, desc64 );
executeAction( idMk, desc63, DialogModes.NO );
}

 

 

JJMack