Last active
August 23, 2020 22:02
-
-
Save rishabhgupta/b9ce3344a1ae1bc863ba15be4d531586 to your computer and use it in GitHub Desktop.
Photoshop
This file contains 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
#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); | |
} |
This file contains 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
{ | |
"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" | |
}, | |
] | |
} |
This file contains 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
const file = File("/Users/cipherhack/Desktop/helloWorld.psd"); | |
var document = app.open(file); |
This file contains 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
var layerSets = document.layerSets.add(); | |
layerSets.name = "TEXT"; |
This file contains 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
// 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(); |
This file contains 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
// 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"; |
This file contains 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
// 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(); |
This file contains 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
// Get all layers in a layerset and call removeAll() | |
document.layerSets.getByName ('TEXT').layers.removeAll() |
This file contains 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
// 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); |
This file contains 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
// 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; |
This file contains 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
app.displayDialogs = DialogModes.NO; |
This file contains 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
// 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); |
This file contains 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
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); |
This file contains 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
// 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(); |
This file contains 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
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