当前位置: 首页>>代码示例>>Python>>正文


Python PSDImage.load方法代码示例

本文整理汇总了Python中psd_tools.PSDImage.load方法的典型用法代码示例。如果您正苦于以下问题:Python PSDImage.load方法的具体用法?Python PSDImage.load怎么用?Python PSDImage.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在psd_tools.PSDImage的用法示例。


在下文中一共展示了PSDImage.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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))
开发者ID:AndrewJHart,项目名称:psd-tools,代码行数:52,代码来源:cli.py

示例2: export_tex

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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))
开发者ID:e-dog,项目名称:ProceduralFairings,代码行数:9,代码来源:exportTex.py

示例3: test_embedded

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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()
开发者ID:EvgenKo423,项目名称:psd-tools,代码行数:9,代码来源:test_placed_layer.py

示例4: loadPSD

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
	def loadPSD( self, path ):
		image = PSDImage.load( path )
		for processor in self.processors:
			processor.onLoadImage( image ) 

		self.processGroup( image.layers )
		self.dirty = True
开发者ID:pixpil,项目名称:gii,代码行数:9,代码来源:PSDDeckPackProject.py

示例5: test_blend_transparent_areas

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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)
开发者ID:EvgenKo423,项目名称:psd-tools,代码行数:9,代码来源:test_blend_modes.py

示例6: make_scene

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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))
开发者ID:pystrategy,项目名称:vegabonds,代码行数:34,代码来源:manage.py

示例7: convert_psd_to_jpg

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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)
开发者ID:mplewis,项目名称:psdtojpg,代码行数:36,代码来源:psdtojpg.py

示例8: main

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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))
开发者ID:stefanklug,项目名称:psd-tools,代码行数:49,代码来源:cli.py

示例9: PsdToPngConverter

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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
开发者ID:yogurt3d,项目名称:Yogurt3D_v3,代码行数:10,代码来源:defs.py

示例10: open_image

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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)
	)
开发者ID:maxattack,项目名称:little-polygon,代码行数:11,代码来源:lputil.py

示例11: openImage

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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
开发者ID:pixpil,项目名称:gii,代码行数:12,代码来源:AtlasGenerator.py

示例12: loadPSD

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
	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 )
开发者ID:pixpil,项目名称:gii,代码行数:12,代码来源:psd2tileset.py

示例13: test_blend_modes_basics

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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
开发者ID:EvgenKo423,项目名称:psd-tools,代码行数:57,代码来源:test_blend_modes.py

示例14: process

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
    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)
开发者ID:indika,项目名称:PSDToCocoa,代码行数:13,代码来源:psd_to_cocoa.py

示例15: writeLayerImages

# 需要导入模块: from psd_tools import PSDImage [as 别名]
# 或者: from psd_tools.PSDImage import load [as 别名]
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")
开发者ID:kestrelm,项目名称:CreatureTools,代码行数:16,代码来源:layerExport.py


注:本文中的psd_tools.PSDImage.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。