I currently have this code working for a document or layer selection, but when I try to use artboard layer id, I get an error
Unsupported layer type
I’m likely overlooking a step to get this to work. I tried sourceBounds to what I thought was the right dimensions, but it only returns a white background? Am I using the wrong sourceBounds or is this just not possible for artboards?
import { AdobeLayer } from "./types";
const photoshop = require("photoshop");
const { batchPlay } = require("photoshop").action;
const app = photoshop.app;
const imaging = photoshop.imaging;
const executeAsModal = photoshop.core.executeAsModal;
const kSRGBProfile = "sRGB IEC61966-2.1";
const thumbnailHeight = 150;
interface PixelOptions {
documentID: number;
layerID?: number;
targetSize: { height: number };
componentSize: -1 | 8 | 16 | 32;
applyAlpha: boolean;
colorProfile: string;
sourceBounds?: { left: number; top: number; right: number; bottom: number };
}
export async function getImageThumbnail(activeLayer: AdobeLayer | undefined): Promise<string> {
let targetDocument = app.activeDocument;
if (targetDocument === undefined) {
throw new Error("No open document");
}
const options: PixelOptions = {
documentID: targetDocument.id,
targetSize: { height: thumbnailHeight },
componentSize: 8,
applyAlpha: true,
colorProfile: kSRGBProfile,
};
console.log("getImageThumbnail", activeLayer);
if (activeLayer !== undefined) {
options["layerID"] = activeLayer.id;
}
const pixels = await executeAsModal(async () => {
return await imaging.getPixels(options);
});
let jpegData = await imaging.encodeImageData({
imageData: pixels.imageData,
base64: true,
});
const dataUrl = "data:image/jpeg;base64," + jpegData;
pixels.imageData.dispose();
return dataUrl;
}