def hello_world(): app = ps.Application() doc = app.documents.add() text_color = ps.SolidColor() text_color.rgb.green = 255 new_text_layer = doc.artLayers.add() new_text_layer.kind = ps.LayerKind.TextLayer new_text_layer.textItem.contents = 'Hello, World!' new_text_layer.textItem.position = [160, 167] new_text_layer.textItem.size = 40 new_text_layer.textItem.color = text_color options = ps.JPEGSaveOptions(quality=5) jpg = 'd:/hello_world.jpg' doc.saveAs(jpg, options, asCopy=True) app.doJavaScript(f'alert("save to jpg: {jpg}")')
start_ruler_units = app.Preferences.RulerUnits app.preferences.rulerUnits = ps.Units.Pixels selRef = app.activeDocument.selection offset = 10 selBounds = ((offset, offset), (app.activeDocument.width - offset, offset), (app.activeDocument.width - offset, app.activeDocument.height - offset), (offset, app.activeDocument.height - offset)) selRef.select(selBounds) selRef.selectBorder(5) # create text color properties strokeColor = ps.SolidColor() strokeColor.cmyk.cyan = 58 strokeColor.cmyk.magenta = 0 strokeColor.cmyk.yellow = 70 strokeColor.cmyk.black = 0 app.displayDialogs = ps.DialogModes.DisplayNoDialogs selRef.stroke(strokeColor, 2, ps.StrokeLocation.OutsideStroke, ps.ColorBlendMode.ColorBlendMode, 75, True) # Set ruler units back the way we found it. app.preferences.rulerUnits = start_ruler_units else: print("Operation cannot be performed on background layer") else: print("Create a document with an active selection before running this "
fileName = os.path.join(os.path.dirname(__file__), "layer_comps.psd") docRef = app.open(fileName) nLayerSets = len(list((i, x) for i, x in enumerate(docRef.layerSets))) - 1 nArtLayers = len( list((i, x) for i, x in enumerate(docRef.layerSets[nLayerSets].artLayers)), ) active_layer = docRef.activeLayer = docRef.layerSets[nLayerSets].artLayers[ nArtLayers] sel_area = ((0, 212), (300, 212), (300, 300), (0, 300)) docRef.selection.select(sel_area, ps.SelectionType.ReplaceSelection, 20, True) print(active_layer.name) active_layer.applyAddNoise(15, ps.NoiseDistribution.GaussianNoise, False) backColor = ps.SolidColor() backColor.hsb.hue = 0 backColor.hsb.saturation = 0 backColor.hsb.brightness = 100 app.backgroundColor = backColor sel_area2 = ((120, 20), (210, 20), (210, 110), (120, 110)) docRef.selection.select(sel_area2, ps.SelectionType.ReplaceSelection, 25, False) active_layer.applyDiffuseGlow(9, 12, 15) active_layer.applyGlassEffect( 7, 3, 7, False, ps.TextureType.TinyLensTexture,
import photoshop as ps # Get photoshop instance. app = ps.Application() # Get current active document. doc = app.activeDocument # Add a solid color. textColor = ps.SolidColor() textColor.rgb.red = 43.0 textColor.rgb.green = 197.0 textColor.rgb.blue = 0.0 # Create empty layer. new_text_layer = doc.artLayers.add() # Set empty layer type to text layer new_text_layer.kind = ps.LayerKind.TextLayer # Set current text layer contents to "Hello, World!". new_text_layer.textItem.contents = 'Hello, World!' # Change current text layer position. new_text_layer.textItem.position = [160, 167] # Change current text layer text size. new_text_layer.textItem.size = 36 # Change current text layer color. new_text_layer.textItem.color = textColor