layeredimage/io/layered.py
def openLayer_LAYERED(file: str) -> LayeredImage:
	"""Open a .layered file into a layered image."""
	blendLookup = {
		"NORMAL": BlendType.NORMAL,
		"MULTIPLY": BlendType.MULTIPLY,
		"ADDITIVE": BlendType.ADDITIVE,
		"COLOURBURN": BlendType.COLOURBURN,
		"COLOURDODGE": BlendType.COLOURDODGE,
		"REFLECT": BlendType.REFLECT,
		"GLOW": BlendType.GLOW,
		"OVERLAY": BlendType.OVERLAY,
		"DIFFERENCE": BlendType.DIFFERENCE,
		"NEGATION": BlendType.NEGATION,
		"LIGHTEN": BlendType.LIGHTEN,
		"DARKEN": BlendType.DARKEN,
		"SCREEN": BlendType.SCREEN,
		"XOR": BlendType.XOR,
		"SOFTLIGHT": BlendType.SOFTLIGHT,
		"HARDLIGHT": BlendType.HARDLIGHT,
		"GRAINEXTRACT": BlendType.GRAINEXTRACT,
		"GRAINMERGE": BlendType.GRAINMERGE,
		"DIVIDE": BlendType.DIVIDE,
		"HUE": BlendType.HUE,
		"SATURATION": BlendType.SATURATION,
		"COLOUR": BlendType.COLOUR,
		"LUMINOSITY": BlendType.LUMINOSITY,
		"PINLIGHT": BlendType.PINLIGHT,
		"VIVIDLIGHT": BlendType.VIVIDLIGHT,
		"EXCLUSION": BlendType.EXCLUSION,
		"DESTIN": BlendType.DESTIN,
		"DESTOUT": BlendType.DESTOUT,
		"DESTATOP": BlendType.DESTATOP,
		"SRCATOP": BlendType.SRCATOP,
	}
	layersAndGroups = []
	with zipfile.ZipFile(file, "r") as layered:
		with layered.open("stack.json") as stackJson:
			stack = json.load(stackJson)
		# Iterate through the layers and groups
		for layerOrGroup in stack["layersAndGroups"]:
			if layerOrGroup["type"] == "LAYER":
				layersAndGroups.append(grabLayer_LAYERED(layered, layerOrGroup, blendLookup))
			else:
				# If its a group grab the layers
				layers = [
					grabLayer_LAYERED(layered, layer, blendLookup)
					for layer in layerOrGroup["layers"]
				]
				layersAndGroups.append(
					Group(
						layerOrGroup["name"],
						layers,
						layerOrGroup["dimensions"],
						layerOrGroup["offsets"],
						layerOrGroup["opacity"],
						layerOrGroup["visible"],
						blendModeLookup(layerOrGroup["blendmode"], blendLookup),
					)
				)
		return LayeredImage(layersAndGroups, stack["dimensions"])
Open a .layered file into a layered image.
Open a .layered file into a layered image.
Open a . layered file into a layered image .
def openLayer_LAYERED(file: str) -> LayeredImage:
	blendLookup = {
		"NORMAL": BlendType.NORMAL,
		"MULTIPLY": BlendType.MULTIPLY,
		"ADDITIVE": BlendType.ADDITIVE,
		"COLOURBURN": BlendType.COLOURBURN,
		"COLOURDODGE": BlendType.COLOURDODGE,
		"REFLECT": BlendType.REFLECT,
		"GLOW": BlendType.GLOW,
		"OVERLAY": BlendType.OVERLAY,
		"DIFFERENCE": BlendType.DIFFERENCE,
		"NEGATION": BlendType.NEGATION,
		"LIGHTEN": BlendType.LIGHTEN,
		"DARKEN": BlendType.DARKEN,
		"SCREEN": BlendType.SCREEN,
		"XOR": BlendType.XOR,
		"SOFTLIGHT": BlendType.SOFTLIGHT,
		"HARDLIGHT": BlendType.HARDLIGHT,
		"GRAINEXTRACT": BlendType.GRAINEXTRACT,
		"GRAINMERGE": BlendType.GRAINMERGE,
		"DIVIDE": BlendType.DIVIDE,
		"HUE": BlendType.HUE,
		"SATURATION": BlendType.SATURATION,
		"COLOUR": BlendType.COLOUR,
		"LUMINOSITY": BlendType.LUMINOSITY,
		"PINLIGHT": BlendType.PINLIGHT,
		"VIVIDLIGHT": BlendType.VIVIDLIGHT,
		"EXCLUSION": BlendType.EXCLUSION,
		"DESTIN": BlendType.DESTIN,
		"DESTOUT": BlendType.DESTOUT,
		"DESTATOP": BlendType.DESTATOP,
		"SRCATOP": BlendType.SRCATOP,
	}
	layersAndGroups = []
	with zipfile.ZipFile(file, "r") as layered:
		with layered.open("stack.json") as stackJson:
			stack = json.load(stackJson)
		for layerOrGroup in stack["layersAndGroups"]:
			if layerOrGroup["type"] == "LAYER":
				layersAndGroups.append(grabLayer_LAYERED(layered, layerOrGroup, blendLookup))
			else:
				layers = [
					grabLayer_LAYERED(layered, layer, blendLookup)
					for layer in layerOrGroup["layers"]
				]
				layersAndGroups.append(
					Group(
						layerOrGroup["name"],
						layers,
						layerOrGroup["dimensions"],
						layerOrGroup["offsets"],
						layerOrGroup["opacity"],
						layerOrGroup["visible"],
						blendModeLookup(layerOrGroup["blendmode"], blendLookup),
					)
				)
		return LayeredImage(layersAndGroups, stack["dimensions"])
def openLayer_LAYERED ( file : str ) -> LayeredImage : blendLookup = { "NORMAL" : BlendType . NORMAL , "MULTIPLY" : BlendType . MULTIPLY , "ADDITIVE" : BlendType . ADDITIVE , "COLOURBURN" : BlendType . COLOURBURN , "COLOURDODGE" : BlendType . COLOURDODGE , "REFLECT" : BlendType . REFLECT , "GLOW" : BlendType . GLOW , "OVERLAY" : BlendType . OVERLAY , "DIFFERENCE" : BlendType . DIFFERENCE , "NEGATION" : BlendType . NEGATION , "LIGHTEN" : BlendType . LIGHTEN , "DARKEN" : BlendType . DARKEN , "SCREEN" : BlendType . SCREEN , "XOR" : BlendType . XOR , "SOFTLIGHT" : BlendType . SOFTLIGHT , "HARDLIGHT" : BlendType . HARDLIGHT , "GRAINEXTRACT" : BlendType . GRAINEXTRACT , "GRAINMERGE" : BlendType . GRAINMERGE , "DIVIDE" : BlendType . DIVIDE , "HUE" : BlendType . HUE , "SATURATION" : BlendType . SATURATION , "COLOUR" : BlendType . COLOUR , "LUMINOSITY" : BlendType . LUMINOSITY , "PINLIGHT" : BlendType . PINLIGHT , "VIVIDLIGHT" : BlendType . VIVIDLIGHT , "EXCLUSION" : BlendType . EXCLUSION , "DESTIN" : BlendType . DESTIN , "DESTOUT" : BlendType . DESTOUT , "DESTATOP" : BlendType . DESTATOP , "SRCATOP" : BlendType . SRCATOP , } layersAndGroups = [ ] with zipfile . ZipFile ( file , "r" ) as layered : with layered . open ( "stack.json" ) as stackJson : stack = json . load ( stackJson ) for layerOrGroup in stack [ "layersAndGroups" ] : if layerOrGroup [ "type" ] == "LAYER" : layersAndGroups . append ( grabLayer_LAYERED ( layered , layerOrGroup , blendLookup ) ) else : layers = [ grabLayer_LAYERED ( layered , layer , blendLookup ) for layer in layerOrGroup [ "layers" ] ] layersAndGroups . append ( Group ( layerOrGroup [ "name" ] , layers , layerOrGroup [ "dimensions" ] , layerOrGroup [ "offsets" ] , layerOrGroup [ "opacity" ] , layerOrGroup [ "visible" ] , blendModeLookup ( layerOrGroup [ "blendmode" ] , blendLookup ) , ) ) return LayeredImage ( layersAndGroups , stack [ "dimensions" ] )
Open a .layered file into a layered image.
Open a . layered file into a layered image .
"""Open a .layered file into a layered image.""" # Iterate through the layers and groups # If its a group grab the layers
file
str