The end goal is to import an image from a fixed path as a background layer and transform it to fit the canvas. Right now I am struggling with even importing an image at all.
When searching I find entries describing how to do it in XD or entries on how to load objs and txt files or how to open an image and duplicate its background layer into the current document.
I have tried (for the first time in my life) to create my own batchplay code with alchemist, too, but it doesnt do anything and doesnt throw any errors either (though I wonder how it should even work, as i dont see how the code would know in which document to load the image, also, do I need a sessionToken for this?):
const { app, core } = require("photoshop");
async function importGradient() {
return require("photoshop").action.batchPlay(
[
{
"_obj": "placeEvent",
"ID": 7,
"null": {
"_path": "C:\\STAPELVERARBEITUNG\\Hintergrund_Artikel_Verlauf2000x2000MitteHeller.tif",
"_kind": "local"
},
"freeTransformCenterState": {
"_enum": "quadCenterState",
"_value": "QCSAverage"
},
"offset": {
"_obj": "offset",
"horizontal": {
"_unit": "pixelsUnit",
"_value": 0
},
"vertical": {
"_unit": "pixelsUnit",
"_value": 0
}
},
"replaceLayer": {
"_obj": "placeEvent",
"to": {
"_ref": "layer",
"_id": 7
}
},
"_isCommand": true
},
],
{}
);
};
async function main(){
await core.executeAsModal(() => {
importGradient()
});
}
document.getElementById('myBTN').addEventListener('click', () => { main(); });
Again, if who ever wants to help would like to go the extra step, I would need to check wether the lowest layer is a background layer and unset it if it is, would need to move the new layer to the bottom of the stack and fit it into the current canvas, so I would appreciate help with that, too, on the other hand I dont want to ask for too much at once.
At least conceptual guidance on how to approach this would be awesome! Thanks in advance!
Edit:
This and this suggests I need to create that whole sessionToken shebang (I seriously hate it, becaus it makes life too complicated and would be happy if Adobe could alter their approach). I did that for saving already, so should get that working somehow. Could somebody at least explain how to put the image file, after I have the correct object, as a layer?