Save the following in a `.psjs` file: const photoshop = require("photoshop");
const app = photoshop.app;
const core = photoshop.core;
const executeAsModal = core.executeAsModal;
const imaging = photoshop.imaging;
const storage = require("uxp").storage;
const lfs = storage.localFileSystem;
const constants = photoshop.constants;
const convertStringToArray = (str) => {
return str.split("\n").map((line) => {
const [x, y] = line.split(";");
return { x: parseInt(x, 10), y: parseInt(y, 10) };
});
};
const width = 20;
const height = 20;
const { types, formats, modes, errors } = require("uxp").storage;
let f = await lfs.getFileForOpening();
const txtContent = await f.read({ format: formats.utf8 });
const points = convertStringToArray(txtContent);
const doc = await app.documents.add({
width,
height,
mode: constants.NewDocumentMode.GRAYSCALE,
});
let pixelsArray = new Uint8Array(width * height).fill(255);
points.forEach(({ x, y }) => {
pixelsArray[y * width + x] = 0;
});
const imageData = await imaging.createImageDataFromBuffer(pixelsArray, {
width,
height,
components: 1,
colorSpace: "Grayscale",
});
await imaging.putPixels({
layerID: app.activeDocument.activeLayers[0].id,
imageData,
commandName: "LED stuff",
}); Then File > Scripts > Browse... and get it. It will pop up a file selection dialog; I've pointed it to a `pixels.csv` file with the following content: 0;0
1;1
2;2
3;3
4;4
5;5
6;6
7;7
8;8
9;9
10;10
11;11
12;12
13;13
14;14
15;15
16;16
17;17
18;18
19;19 It creates a new document, 20x20px (the doc size is hardwired for simplicity) and fill it with black pixels at the x,y coords in the csv, like so: It's a toy example, but you can tweak it to fit your purposes—if I've properly understood what you're after. Please note that in PS the cartesian plane points downwards, y values must be adjusted if one expects it to be as we're taught in school 🙂 Cheers, Davide
... View more