本文整理汇总了Python中psd_tools.PSDImage类的典型用法代码示例。如果您正苦于以下问题:Python PSDImage类的具体用法?Python PSDImage怎么用?Python PSDImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PSDImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
"""
psd-tools.py
Usage:
psd-tools.py convert <psd_filename> <out_filename> [options]
psd-tools.py export_layer <psd_filename> <layer_index> <out_filename> [options]
psd-tools.py debug <filename> [options]
psd-tools.py -h | --help
psd-tools.py --version
Options:
-v --verbose Be more verbose.
--encoding <encoding> Text encoding [default: utf8].
"""
args = docopt.docopt(main.__doc__)
if args['--verbose']:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.INFO)
encoding = args['--encoding']
if args['convert']:
psd = PSDImage.load(args['<psd_filename>'], encoding=encoding)
im = psd.as_PIL()
im.save(args['<out_filename>'])
elif args['export_layer']:
psd = PSDImage.load(args['<psd_filename>'], encoding=encoding)
index = int(args['<layer_index>'])
im = psd.layers[index].as_PIL()
im.save(args['<out_filename>'])
print(psd.layers)
psd.as_PIL()
elif args['debug']:
with open(args['<filename>'], "rb") as f:
decoded = psd_tools.decoder.parse(
psd_tools.reader.parse(f, encoding)
)
print("\nHeader\n------")
print(decoded.header)
print("\nDecoded data\n-----------")
pprint(decoded)
print("\nLayers\n------")
pprint(group_layers(decoded))
示例2: test_embedded
def test_embedded():
# This file contains both an embedded and linked png
psd = PSDImage.load(os.path.join(DATA_PATH, 'placedLayer.psd'))
embedded = psd.embedded[0]
assert embedded.filename == 'linked-layer.png'
with open(os.path.join(DATA_PATH, 'linked-layer.png'), 'rb') as f:
assert embedded.data == f.read()
示例3: export_tex
def export_tex(fn, downscale=2, ext='.png'):
print 'processing', fn
psd=PSDImage.load(fn+".psd")
im=psd.as_PIL()
wd,ht=im.size
if downscale>1: im=im.resize((wd/downscale, ht/downscale), Image.ANTIALIAS)
im.save(os.path.join(target_path, fn+ext))
示例4: loadPSD
def loadPSD( self, path ):
image = PSDImage.load( path )
for processor in self.processors:
processor.onLoadImage( image )
self.processGroup( image.layers )
self.dirty = True
示例5: test_blend_transparent_areas
def test_blend_transparent_areas():
psd = PSDImage.load(full_name('blend_modes2.psd'))
composite_image = psd.as_PIL()
merged_image = psd.as_PIL_merged()
assert merged_image is not None
assert tobytes(composite_image) == tobytes(merged_image)
示例6: make_scene
def make_scene(psdPath, resDirPath):
psdDirPath, psdFileName = os.path.split(psdPath)
mapName = os.path.splitext(psdFileName)[0]
mapDirPath = os.path.join(resDirPath, mapName)
imageDirPath = os.path.join(mapDirPath, 'images')
sceneFilePath = os.path.join(mapDirPath, 'scene.json')
if not os.access(imageDirPath, os.R_OK):
os.makedirs(imageDirPath)
psd = PSDImage.load(psdPath)
layerInfos = []
for layer in psd.layers:
if layer.name == 'num':
continue
layerInfo = dict(
name=layer.name.encode('utf8'),
x=layer.bbox.x1,
y=psd.header.height - layer.bbox.y2,
w=layer.bbox.width,
h=layer.bbox.height)
layerInfos.append(layerInfo)
if True:
image = layer.as_PIL()
image.save('{0}/{1}.png'.format(imageDirPath, layer.name))
sceneDict = dict(layers=layerInfos, header=dict(width=psd.header.width, height=psd.header.height))
open(sceneFilePath, 'w').write(json.dumps(sceneDict, indent=4))
示例7: convert_psd_to_jpg
def convert_psd_to_jpg(psd_path, jpg_path, *,
quality, max_width=None, max_height=None):
"""
Convert a PSD at a given path to a JPG at a given path.
Optional arguments for setting JPG quality from 0 to 100, max width in px,
and max height in px.
"""
print('%s %s %s' % (psd_path, CONVERT_TO_CHAR, jpg_path))
img = PSDImage.load(psd_path).as_PIL()
width, height = img.size
if max_width or max_height:
if max_width and max_height:
new_size_a = downsize_by_height(width=width, height=height,
new_height=max_height)
new_size_b = downsize_by_width(width=width, height=height,
new_width=max_width)
if new_size_a[0] * new_size_a[1] <= new_size_b[0] * new_size_b[1]:
new_size = new_size_a
else:
new_size = new_size_b
elif max_height:
new_size = downsize_by_height(width=width, height=height,
new_height=max_height)
elif max_width:
new_size = downsize_by_width(width=width, height=height,
new_width=max_width)
(img.resize(new_size, resample=PIL.Image.ANTIALIAS)
.save(jpg_path, quality=quality))
else:
img.save(jpg_path, quality=quality)
示例8: main
def main():
"""
psd-tools.py
Usage:
psd-tools.py <filename> [--encoding <encoding>] [--verbose]
psd-tools.py convert <psd_filename> <out_filename> [--verbose]
psd-tools.py export_layer <psd_filename> <layer_index> <out_filename> [--verbose]
psd-tools.py -h | --help
psd-tools.py --version
Options:
-v --verbose Be more verbose.
--encoding <encoding> Text encoding [default: utf8].
"""
args = docopt.docopt(main.__doc__)
if args["--verbose"]:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.INFO)
if args["convert"]:
psd = PSDImage.load(args["<psd_filename>"])
im = psd.as_PIL()
im.save(args["<out_filename>"])
elif args["export_layer"]:
psd = PSDImage.load(args["<psd_filename>"])
index = int(args["<layer_index>"])
im = psd.layers[index].as_PIL()
im.save(args["<out_filename>"])
print(psd.layers)
psd.as_PIL()
else:
encoding = args["--encoding"]
with open(args["<filename>"], "rb") as f:
decoded = psd_tools.decoder.parse(psd_tools.reader.parse(f, encoding))
print(decoded.header)
pprint.pprint(decoded.image_resource_blocks)
pprint.pprint(decoded.layer_and_mask_data)
pprint.pprint(decoded.image_data)
pprint.pprint(group_layers(decoded))
示例9: PsdToPngConverter
def PsdToPngConverter(directory, filename):
psd = PSDImage.load(directory + glo.s + filename)
#print "psd.header\n " , psd.header
merged_image = psd.as_PIL()
# print "image being saved to: " , directory + glo.s + filename[:-4] + '.png'
merged_image.save(directory + glo.s + filename[:-4] + '.png')
return
示例10: open_image
def open_image(path):
# if it's a psd maybe we can selectively specify layers?
# e.g. "path/to/foo.psd{export}"
return _sanitize_rgba(
PSDImage.load(path).as_PIL() \
if path.lower().endswith('.psd') \
else Image.open(path)
)
示例11: openImage
def openImage( filepath ):
name, ext = os.path.splitext( filepath )
if ext.lower() == '.psd':
from psd_tools import PSDImage
pimage = PSDImage.load( filepath )
if not pimage: sys.exit( 'failed loading file' )
img = pimage.as_PIL()
else:
img = Image.open(filepath)
return img
示例12: loadPSD
def loadPSD( self, path ):
image = PSDImage.load( path )
#meta data
bx0 , by0 , bx1 , by1 = image.bbox
self.bbox = ( bx0, by0, bx1, by1 )
self.tileSize = ( bx1, by1 )
for layer in image.layers:
theme = self.collectTheme( layer )
if theme :
self.themes.append( theme )
示例13: test_blend_modes_basics
def test_blend_modes_basics():
psd = PSDImage.load(full_name('blend_modes.psd'))
composite_image = psd.as_PIL()
merged_image = psd.as_PIL_merged()
for i in range(27):
is_separable = DIFF_STATS_PER_MODE[i][0]
is_precise = DIFF_STATS_PER_MODE[i][1]
deviation_neg = DIFF_STATS_PER_MODE[i][2]
deviation_pos = DIFF_STATS_PER_MODE[i][3]
match_count = DIFF_STATS_PER_MODE[i][4]
y = i // 7 * 200
x = i % 7 * 200
bbox = (x, y, x + 200, y + 200)
ethalon = composite_image.crop(bbox)
result = merged_image.crop(bbox)
if is_separable:
diff = _get_diff_channels(ethalon, result)
if is_precise:
assert len(diff[0]) == 1
assert len(diff[1]) == 1
assert len(diff[2]) == 1
assert 127 in diff[0]
assert 127 in diff[1]
assert 127 in diff[2]
else:
keys_r = sorted(diff[0].keys())
keys_g = sorted(diff[1].keys())
keys_b = sorted(diff[2].keys())
min_color_value = min(keys_r[ 0], keys_g[ 0], keys_b[ 0])
max_color_value = max(keys_r[-1], keys_g[-1], keys_b[-1])
assert max_color_value - 127 == deviation_pos
assert min_color_value - 127 == deviation_neg
assert diff[0][127] >= match_count
assert diff[1][127] >= match_count
assert diff[2][127] >= match_count
else:
diff = _get_diff_luminance(ethalon, result)
if is_precise:
assert len(diff) == 1
assert 127 in diff
else:
keys = sorted(diff.keys())
assert keys[-1] - 127 == deviation_pos
assert keys[ 0] - 127 == deviation_neg
assert diff[127] >= match_count
示例14: process
def process(self):
psd_file = self.arguments['<psd>']
psd = PSDImage.load(psd_file)
print psd.header
print psd.layers
source_bbox = psd.bbox
for item in psd.layers:
if item.visible:
self.encode(item, source_bbox)
示例15: writeLayerImages
def writeLayerImages(filenameIn, outFolderName):
psd = PSDImage.load(filenameIn)
if not os.path.exists(outFolderName):
os.makedirs(outFolderName)
for curLayer in psd.layers:
img = curLayer.as_PIL()
slash = "/"
if os.name != 'posix':
slash = "\\"
img.save(outFolderName + slash + curLayer.name + ".png")