Skip to content

Instantly share code, notes, and snippets.

@rishabhgupta
Last active August 23, 2020 22:02
Show Gist options
  • Save rishabhgupta/b9ce3344a1ae1bc863ba15be4d531586 to your computer and use it in GitHub Desktop.
Save rishabhgupta/b9ce3344a1ae1bc863ba15be4d531586 to your computer and use it in GitHub Desktop.
Photoshop
#include "/Users/cipherhack/Documents/Adobe Scripts/json2.js"
// Suppress dialogs
app.displayDialogs = DialogModes.NO;
// Read cast data from json file
const jsonFile = File("/Users/cipherhack/Documents/Adobe Scripts/cast.json");
jsonFile.open ('r');
const data = jsonFile.read();
jsonFile.close();
// Close the file as we don't need it anymore
var castData= JSON.parse(data);
castData = castData['cast'];
// Export JPEG Configuration
var jpegConfig = new JPEGSaveOptions();
jpegConfig.quality = 10;
var document = app.activeDocument;
var nameTextLayer = document.layerSets.getByName ('TEXT').layers.getByName('actorName');
var characterTextLayer = document.layerSets.getByName ('TEXT').layers.getByName('characterName');
for(var actor = 0; actor<castData.length; actor ++) {
// For each actor create a jpeg file
var filename = '/Users/cipherhack/Desktop/Avengers/' + castData[actor]['character'] + '.jpg';
var file = File(filename);
// Set text of the name layer to actors name
nameTextLayer.textItem.contents = castData[actor]['name'];
// Set text of character layer
characterTextLayer.textItem.contents = castData[actor]['character'];
// Save JPEG file
document.saveAs (file, jpegConfig);
}
{
"cast": [{
"name": "Robert Downey Jr",
"character": "Iron Man"
},
{
"name": "Chris Evans",
"character": "Captain America"
},
{
"name": "Brie Larson",
"character": "Captain Marvel"
},
{
"name": "Chris Hemsworth",
"character": "Thor"
},
{
"name": "Mark Ruffalo",
"character": "Hulk"
},
{
"name": "Scarlett Johansson",
"character": "Black Widow"
},
{
"name": "Karen Gillan",
"character": "Nebula"
},
{
"name": "Paul Rudd",
"character": "Ant-Man"
},
{
"name": "Jeremy Renner",
"character": "Hawkeye"
},
{
"name": "Don Cheadle",
"character": "War Machine"
},
{
"name": "Benedict Cumberbatch",
"character": "Doctor Strange"
},
{
"name": "Tom Holland",
"character": "Spider-Man"
},
]
}
const file = File("/Users/cipherhack/Desktop/helloWorld.psd");
var document = app.open(file);
var layerSets = document.layerSets.add();
layerSets.name = "TEXT";
// Get the current document
var document = app.activeDocument;
// Create color object of color red
var fillColor = new SolidColor();
fillColor.rgb.red = 222;
fillColor.rgb.green = 0;
fillColor.rgb.blue = 0;
// Add a new layer called Background
var layer = document.artLayers.add();
layer.name = "Background";
// Select the entire layer
document.selection.selectAll()
// Fill the selection with color
document.selection.fill(fillColor);
// Deselect
document.selection.deselect();
// Create a new text layer inside our layour group called layerSets
var newLayer = layerSets.artLayers.add();
newLayer.kind = LayerKind.TEXT;
newLayer.name = "MoveName"
// Set font size, font style and position
newLayer.textItem.size = 50;
newLayer.textItem.font = "Verdana";
newLayer.textItem.position = [350, 400];
newLayer.textItem.contents = "AVENGERS";
// Get the layer by name and call remove
document.artLayers.getByName ('Background').remove();
// Get the layer set by name and call remove
document.layerSets.getByName ('TEXT').remove();
// Get all layers in a layerset and call removeAll()
document.layerSets.getByName ('TEXT').layers.removeAll()
// Get the active document
var document = app.activeDocument;
// export file options
var jpegConfig = new JPEGSaveOptions();
jpegConfig.quality = 10;
// File path to export
var filename = '/Users/cipherhack/Desktop/photoshop/avengers.jpg';
var file = File(filename);
document.saveAs (file, jpegConfig);
// Create a new document
// 50cm X 50cm at 72 dpi
// Title: helloPhotoshop
var document = app.documents.add(50, 50, 72, "helloPhotoshop");
// Add a new layer
var layer = document.artLayers.add()
layer.kind = LayerKind.TEXT;
layer.textItem.contents = "Hello Photoshop!";
layer.textItem.size = 50;
app.displayDialogs = DialogModes.NO;
// Include the json parser
#include "/Users/cipherhack/Documents/Adobe Scripts/json2.js"
const jsonFile = File("/Users/cipherhack/Documents/Adobe Scripts/cast.json");
// Open the JSON file in read mode
jsonFile.open ('r');
// Store the data
const data = jsonFile.read();
// Close the file as we no longer need it
jsonFile.close();
// Use the parser to perse json data
const castData= JSON.parse(data);
alert(castData['cast'][0].name);
var document = app.documents.add(50, 50, 72, "helloPhotoshop");
// Add a new layer
var layer = document.artLayers.add()
layer.kind = LayerKind.TEXT;
layer.textItem.contents = "Hello Photoshop!";
layer.textItem.size = 50;
// Saving the file
const file = File("/Users/cipherhack/Desktop/helloPhotoshop.psd");
document.saveAs(file);
// OPEN the previously created file.
const file = File("/Users/cipherhack/Desktop/helloPhotoshop.psd");
var document = app.open(file);
// Get the 'Hello Photoshop!' text layer
var layer = document.artLayers.getByName ('Hello Photoshop!');
// Change its contents
layer.textItem.contents = "Hello Photoshop CC!";
// SAVE the document
document.save();
var fillColor = new SolidColor();
fillColor.rgb.red = 0;
fillColor.rgb.green = 183;
fillColor.rgb.blue = 159;
// Set the background layer as the active layer
document.activeLayer = document.artLayers.getByName ('Background');
document.selection.selectAll();
document.selection.fill(fillColor)
document.selection.deselect();
// Changing the blend mode of the text layer to softlight
var textLayer = document.layerSets.getByName ('TEXT').layers.getByName('MovieName');
textLayer.blendMode = BlendMode.SOFTLIGHT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment