Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python photoshop #17

Open
abdalwdod opened this issue Mar 13, 2022 · 3 comments
Open

Python photoshop #17

abdalwdod opened this issue Mar 13, 2022 · 3 comments

Comments

@abdalwdod
Copy link

How can i create file Psd and insert in it a new image

@BlaCoder
Copy link

Hey, I had the same doubt writing a code to do so and I managed a way to do; Since Photoshop doesn't equally have a way to insert a image as "Smart Object", I had to use this snippet:

def Apply(file):
jsx = r"""
var idPlc = charIDToTypeID( "Plc " );
var desc1883 = new ActionDescriptor();
var idIdnt = charIDToTypeID( "Idnt" );
desc1883.putInteger( idIdnt, 24 );
var idnull = charIDToTypeID( "null" );
desc1883.putPath( idnull, new File( '""" + file + """') );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc1883.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc1884 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idRlt = charIDToTypeID( "#Rlt" );
desc1884.putUnitDouble( idHrzn, idRlt, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idRlt = charIDToTypeID( "#Rlt" );
desc1884.putUnitDouble( idVrtc, idRlt, -0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc1883.putObject( idOfst, idOfst, desc1884 );
executeAction( idPlc, desc1883, DialogModes.NO );
"""
app.doJavascript(jsx)

Since it uses javascript, make sure the file instance applied at the function follows this format: "path\to\item", ok?

Hope it helps!

@Mossad-55
Copy link

I wan to replace an image in a specific layer. Is there a way i can do it ?!

@BlaCoder
Copy link

BlaCoder commented Aug 8, 2022

I wan to replace an image in a specific layer. Is there a way i can do it ?!

So far, either in Photoshop documentation have a specific method for replacing images in a layer, the best you can do is turn the layer in a Smart Object kind and use this code in javascript:

function Replace(img) {
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
var desc1852 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc1852.putPath( idnull, new File(img) );
executeAction( idplacedLayerReplaceContents, desc1852, DialogModes.NO );
}

Make sure the "img" is a string and in the same format used above;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants