####### Auto Buttons for Paint Shop Pro Photo ####### # # # A script for PSPX, PSPX1, PSPX2 # # Copyright (C) 2008 Allicorn # # Contact allicorn[AT]gmail.com # # # ##################################################### from PSPApp import * from os import getcwd # Define script properties needed by PSP def ScriptProperties(): return { 'Author': u'Allicorn', 'Copyright': u'2008', 'Description': u'Create sets of buttons from a single multi-layer image', 'Host': u'Paint Shop Pro', 'Host Version': u'' } # Define a group of GeneralSettings parameters that ensure every script # command will run without prompting for input from the user def MyGeneralSettings(Environment): return { 'ExecutionMode': App.Constants.ExecutionMode.Silent, # Silent operation 'AutoActionMode': App.Constants.AutoActionMode.AllAlways, # Always accept any prompts 'Version': ((10,0,1),1) # Require PSP version 10 or greater } # Find out where the multi-layer source image is saved so that we # can place all the generated button GIFs into the same directory CurrentPath = getcwd() # Begin the business part... def Do(Environment): ##################### BASE SEQUENCE ##################### # # Iterate through all layers, turn everything off except the layer called "BASE" # Set a flag indicating whether or not there is a layer called "ROLLOVER" # Set a flag indicating whether or not there is a layer called "ACTIVE" # HasRollover = False HasActive = False # Ensure we're starting at the bottom of the layers list try: App.Do( Environment, 'SelectLayer', { 'Path': (9999,-9999, [], False ) } ) except: pass LayerNum = 1 FoundLayer = True while FoundLayer == True: Props = App.Do( Environment, 'ReturnLayerProperties' ) LayerName = Props[ 'General' ][ 'Name' ] Enable = False if LayerName=='BASE': Enable = True if LayerName=='ROLLOVER': HasRollover = True if LayerName=='ACTIVE': HasActive = True # Ensure the BASE background layer is visible App.Do( Environment, 'LayerProperties', { 'General': { 'IsVisible': Enable, }, 'GeneralSettings': MyGeneralSettings(Environment) }) LayerNum += 1 FoundLayer = App.Do( Environment, 'SelectNextLayer' ) # END WHILE # # Iterate through all layers, turning on each non-BASE non-ROLLOVER non-ACTIVE # layer one at a time and saving an image. # # Ensure we're starting at the bottom of the layers list try: App.Do( Environment, 'SelectLayer', { 'Path': (9999,-9999, [], False ) } ) except: pass FoundLayer = True while FoundLayer == True: Props = App.Do( Environment, 'ReturnLayerProperties' ) LayerName = Props[ 'General' ][ 'Name' ] Enable = False if LayerName!='BASE' and LayerName!='ROLLOVER' and LayerName!='ACTIVE': # Enable the layer of interest App.Do( Environment, 'LayerProperties', { 'General': { 'IsVisible': True }, 'GeneralSettings': MyGeneralSettings(Environment) }) # Create clipboard data for temporary image App.Do( Environment, 'CopyMerged', { 'GeneralSettings': MyGeneralSettings(Environment) }) # Disable the layer of interest App.Do( Environment, 'LayerProperties', { 'General': { 'IsVisible': False }, 'GeneralSettings': MyGeneralSettings(Environment) }) # Create temporary image App.Do( Environment, 'PasteGraphicAsNewImage', { 'CreateFromDropData': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Select temporary image App.Do( Environment, 'SelectDocument', { 'SelectedImage': 0, 'Strict': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Flatten and palettize image App.Do( Environment, 'DecreaseColorsTo256', { 'Boost': False, 'BoostAmount': 1, 'IncludeWindowsColors': False, 'ReductionMethod': 'ErrorDiffusionDither', 'PaletteMethod': 'OptimizedOctree', 'ReduceBleeding': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Get image info from which we can examine the palette of the new image ImageInfo = App.Do( Environment, 'ReturnImageInfo', { 'GeneralSettings': MyGeneralSettings(Environment) }) # Locate the Magenta color Palette = ImageInfo['PaletteColorList'] MagentaIndex = -1 a = 0 while a < 256: Color = Palette[a] if Color[0]==255: if Color[1]==0: if Color[2]==255: MagentaIndex = a a+=1 # Set no transparency since we couldn't find any Magenta if MagentaIndex==-1: App.Do( Environment, 'SetPaletteTransparency', { 'PaletteTransparency': App.Constants.PaletteTransparency.NoTransparency, 'GeneralSettings': MyGeneralSettings(Environment) }) # Set Palette Transparency on the temporary image else: App.Do( Environment, 'SetPaletteTransparency', { 'PaletteIndex': MagentaIndex, 'PaletteTransparency': App.Constants.PaletteTransparency.PaletteEntry, 'GeneralSettings': MyGeneralSettings(Environment) }) # Save the temporary image App.Do( Environment, 'FileSaveAs', { 'Encoding': { 'GIF': { 'Interlaced': False, 'Version': App.Constants.GifVersion.Gif89a } }, 'FileName': CurrentPath+u'\\'+LayerName+'.gif', 'FileFormat': App.Constants.FileFormat.GIF, 'FormatDesc': u'GIF CompuServe Graphics Interchange', 'GeneralSettings': MyGeneralSettings(Environment), 'DefaultProperties': [] }) # Close the temporary image App.Do( Environment, 'FileClose', { 'GeneralSettings': MyGeneralSettings(Environment) }) # Select original image App.Do( Environment, 'SelectDocument', { 'SelectedImage': 0, 'Strict': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Move on to the next layer FoundLayer = App.Do( Environment, 'SelectNextLayer' ) # END WHILE ##################### ROLLOVER SEQUENCE ##################### # # IF the image has a layer called "ROLLOVER", then we need to run the process again # Iterate through all layers, turn everything off except the layer called "ROLLOVER" # if HasRollover: # Ensure we're starting at the bottom of the layers list try: App.Do( Environment, 'SelectLayer', { 'Path': (9999,-9999, [], False ) } ) except: pass LayerNum = 1 FoundLayer = True while FoundLayer == True: Props = App.Do( Environment, 'ReturnLayerProperties' ) LayerName = Props[ 'General' ][ 'Name' ] Enable = False if LayerName=='ROLLOVER': Enable = True # Ensure the ROLLOVER background layer is visible App.Do( Environment, 'LayerProperties', { 'General': { 'IsVisible': Enable }, 'GeneralSettings': MyGeneralSettings(Environment) }) LayerNum += 1 FoundLayer = App.Do( Environment, 'SelectNextLayer' ) # END WHILE # # Iterate through all layers, turning on each non-BASE non-ROLLOVER non-ACTIVE # layer one at a time and saving an image. # # Ensure we're starting at the bottom of the layers list try: App.Do( Environment, 'SelectLayer', { 'Path': (9999,-9999, [], False ) } ) except: pass FoundLayer = True while FoundLayer == True: Props = App.Do( Environment, 'ReturnLayerProperties' ) LayerName = Props[ 'General' ][ 'Name' ] Enable = False if LayerName!='BASE' and LayerName!='ROLLOVER' and LayerName!='ACTIVE': # Enable the layer of interest App.Do( Environment, 'LayerProperties', { 'General': { 'IsVisible': True, }, 'GeneralSettings': MyGeneralSettings(Environment) }) # Create clipboard data for temporary image App.Do( Environment, 'CopyMerged', { 'GeneralSettings': MyGeneralSettings(Environment) }) # Disable the layer of interest App.Do( Environment, 'LayerProperties', { 'General': { 'IsVisible': False }, 'GeneralSettings': MyGeneralSettings(Environment) }) # Create temporary image App.Do( Environment, 'PasteGraphicAsNewImage', { 'CreateFromDropData': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Select temporary image App.Do( Environment, 'SelectDocument', { 'SelectedImage': 0, 'Strict': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Flatten and palettize image App.Do( Environment, 'DecreaseColorsTo256', { 'Boost': False, 'BoostAmount': 1, 'IncludeWindowsColors': False, 'ReductionMethod': 'ErrorDiffusionDither', 'PaletteMethod': 'OptimizedOctree', 'ReduceBleeding': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Get the image info from which we can examine the palette ImageInfo = App.Do( Environment, 'ReturnImageInfo', { 'GeneralSettings': MyGeneralSettings(Environment) }) # Locate the Magenta color Palette = ImageInfo['PaletteColorList'] MagentaIndex = -1 a = 0 while a < 256: Color = Palette[a] if Color[0]==255: if Color[1]==0: if Color[2]==255: MagentaIndex = a a+=1 # Set no transparency since we couldn't find any Magenta if MagentaIndex==-1: App.Do( Environment, 'SetPaletteTransparency', { 'PaletteTransparency': App.Constants.PaletteTransparency.NoTransparency, 'GeneralSettings': MyGeneralSettings(Environment) }) # Set Palette Transparency on the temporary image else: App.Do( Environment, 'SetPaletteTransparency', { 'PaletteIndex': MagentaIndex, 'PaletteTransparency': App.Constants.PaletteTransparency.PaletteEntry, 'GeneralSettings': MyGeneralSettings(Environment) }) # Save the temporary image App.Do( Environment, 'FileSaveAs', { 'Encoding': { 'GIF': { 'Interlaced': False, 'Version': App.Constants.GifVersion.Gif89a } }, 'FileName': CurrentPath+u'\\ro_'+LayerName+'.gif', 'FileFormat': App.Constants.FileFormat.GIF, 'FormatDesc': u'GIF CompuServe Graphics Interchange', 'GeneralSettings': MyGeneralSettings(Environment), 'DefaultProperties': [] }) # Close the temporary image App.Do( Environment, 'FileClose', { 'GeneralSettings': MyGeneralSettings(Environment) }) # Select original image App.Do( Environment, 'SelectDocument', { 'SelectedImage': 0, 'Strict': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Move on to the next layer FoundLayer = App.Do( Environment, 'SelectNextLayer' ) # END WHILE ##################### ACTIVE SEQUENCE ##################### # # IF the image has a layer called "ACTIVE" then we need to run the process again # Iterate through all layers, turn everything off except the layer called "ACTIVE" # if HasActive: # Ensure we're starting at the bottom of the layers list try: App.Do( Environment, 'SelectLayer', { 'Path': (9999,-9999, [], False ) } ) except: pass LayerNum = 1 FoundLayer = True while FoundLayer == True: Props = App.Do( Environment, 'ReturnLayerProperties' ) LayerName = Props[ 'General' ][ 'Name' ] Enable = False if LayerName=='ACTIVE': Enable = True # Ensure the ACTIVE background layer is visible App.Do( Environment, 'LayerProperties', { 'General': { 'IsVisible': Enable }, 'GeneralSettings': MyGeneralSettings(Environment) }) LayerNum += 1 FoundLayer = App.Do( Environment, 'SelectNextLayer' ) # END WHILE # # Iterate through all layers, turning on each non-BASE non-ROLLOVER non-ACTIVE # layer one at a time and saving an image. # # Ensure we're starting at the bottom of the layers list try: App.Do( Environment, 'SelectLayer', { 'Path': (9999,-9999, [], False ) } ) except: pass FoundLayer = True while FoundLayer == True: Props = App.Do( Environment, 'ReturnLayerProperties' ) LayerName = Props[ 'General' ][ 'Name' ] Enable = False if LayerName!='BASE' and LayerName!='ROLLOVER' and LayerName!='ACTIVE': # Enable the layer of interest App.Do( Environment, 'LayerProperties', { 'General': { 'IsVisible': True }, 'GeneralSettings': MyGeneralSettings(Environment) }) # Create clipboard data for temporary image App.Do( Environment, 'CopyMerged', { 'GeneralSettings': MyGeneralSettings(Environment) }) # Disable the layer of interest App.Do( Environment, 'LayerProperties', { 'General': { 'IsVisible': False }, 'GeneralSettings': MyGeneralSettings(Environment) }) # Create temporary image App.Do( Environment, 'PasteGraphicAsNewImage', { 'CreateFromDropData': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Select temporary image App.Do( Environment, 'SelectDocument', { 'SelectedImage': 0, 'Strict': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Flatten and palettize image App.Do( Environment, 'DecreaseColorsTo256', { 'Boost': False, 'BoostAmount': 1, 'IncludeWindowsColors': False, 'ReductionMethod': 'ErrorDiffusionDither', 'PaletteMethod': 'OptimizedOctree', 'ReduceBleeding': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Get the image info from which we can examine the palette ImageInfo = App.Do( Environment, 'ReturnImageInfo', { 'GeneralSettings': MyGeneralSettings(Environment) }) # Locate the Magenta color Palette = ImageInfo['PaletteColorList'] MagentaIndex = -1 a = 0 while a < 256: Color = Palette[a] if Color[0]==255: if Color[1]==0: if Color[2]==255: MagentaIndex = a a+=1 # Set no transparency since we couldn't find any Magenta if MagentaIndex==-1: App.Do( Environment, 'SetPaletteTransparency', { 'PaletteTransparency': App.Constants.PaletteTransparency.NoTransparency, 'GeneralSettings': MyGeneralSettings(Environment) }) # Set Palette Transparency on the temporary image else: App.Do( Environment, 'SetPaletteTransparency', { 'PaletteIndex': MagentaIndex, 'PaletteTransparency': App.Constants.PaletteTransparency.PaletteEntry, 'GeneralSettings': MyGeneralSettings(Environment) }) # Save the temporary image App.Do( Environment, 'FileSaveAs', { 'Encoding': { 'GIF': { 'Interlaced': False, 'Version': App.Constants.GifVersion.Gif89a } }, 'FileName': CurrentPath+u'\\ac_'+LayerName+'.gif', 'FileFormat': App.Constants.FileFormat.GIF, 'FormatDesc': u'GIF CompuServe Graphics Interchange', 'GeneralSettings': MyGeneralSettings(Environment), 'DefaultProperties': [] }) # Close the temporary image App.Do( Environment, 'FileClose', { 'GeneralSettings': MyGeneralSettings(Environment) }) # Select original image App.Do( Environment, 'SelectDocument', { 'SelectedImage': 0, 'Strict': True, 'GeneralSettings': MyGeneralSettings(Environment) }) # Move on to the next layer FoundLayer = App.Do( Environment, 'SelectNextLayer' ) # END WHILE