Last active
December 17, 2020 02:02
-
-
Save anton-liubushkin/470cd046f785e32e2aa964f2a7091a62 to your computer and use it in GitHub Desktop.
Copy base64 data of all selected Photoshop layers into clipboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init(); | |
funtion init() { | |
var layerID, pngPath, pngFile, pngData64, pngBase64Image; | |
layerID = app.activeDocument.activeLayer.id; | |
pngPath = new File(Folder.temp + "/" + layerID).fsName; | |
writeLayerPNGfile(pngPath); | |
pngFile = new File(pngPath + ".base64"); | |
pngFile.open('r'); | |
pngFile.encoding = "UTF-8"; | |
pngData64 = pngFile.read(); | |
pngFile.close(); | |
pngFile.remove(); | |
pngBase64Image = "data:img/png;base64," + pngData64; | |
copyTextToClipboard(pngBase64Image); | |
}; | |
function writeLayerPNGfile(path) { | |
var desc = new ActionDescriptor(); | |
desc.putBoolean(stringIDToTypeID("selectedLayers"), true); // Get data from all selected layers | |
desc.putString(stringIDToTypeID("rawPixmapFilePath"), path); // Path to file | |
desc.putBoolean(stringIDToTypeID("bounds"), true); | |
desc.putInteger(stringIDToTypeID("width"), 10000); // Max size in pixels | |
desc.putInteger(stringIDToTypeID("height"), 10000); | |
desc.putInteger(stringIDToTypeID("format"), 2); // raw pixels (Don't touch this!) | |
executeAction(stringIDToTypeID("sendLayerThumbnailToNetworkClient"), desc, DialogModes.NO); | |
} | |
function copyTextToClipboard(text, tag) { | |
var strDesc = new ActionDescriptor(); | |
strDesc.putString(charIDToTypeID('TxtD'), text); | |
executeAction(stringIDToTypeID("textToClipboard"), strDesc, DialogModes.NO); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment