本文整理汇总了Python中mutagen.flac.Picture.height方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.height方法的具体用法?Python Picture.height怎么用?Python Picture.height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.Picture
的用法示例。
在下文中一共展示了Picture.height方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_image
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import height [as 别名]
def set_image(self, image):
"""Replaces all embedded images by the passed image"""
with translate_errors():
tag = FLAC(self["~filename"])
try:
data = image.read()
except EnvironmentError as e:
raise AudioFileError(e)
pic = Picture()
pic.data = data
pic.type = APICType.COVER_FRONT
pic.mime = image.mime_type
pic.width = image.width
pic.height = image.height
pic.depth = image.color_depth
tag.add_picture(pic)
with translate_errors():
tag.save()
# clear vcomment tags
super(FLACFile, self).clear_images()
self.has_images = True
示例2: download_and_fix_ogg
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import height [as 别名]
def download_and_fix_ogg(ogg, audio_metadata, cover_art_file):
global DRY_RUN
if DRY_RUN:
print "This is a dry run. So pretending to download the ogg..."
return "/tmp/ogg"
print "Now downloading the ogg in order to set the metadata in it..."
if not LIVE and len(sys.argv) >= 6 and os.path.exists(sys.argv[5]):
ogg_local_fn = sys.argv[5]
print "(using presupplied file %s)" % ogg_local_fn
else:
f, metadata = client.get_file_and_metadata(ogg)
ogg_local_fn = fetch_file(f, metadata)
print "Successfully downloaded (to %s): now editing metadata..." % ogg_local_fn
audio = OggVorbis(ogg_local_fn)
for k in audio_metadata.keys():
audio[k] = audio_metadata[k]
# add cover art
im=Image.open(cover_art_file)
w,h=im.size
p=Picture()
imdata=open(cover_art_file,'rb').read()
p.data=imdata
p.type=3
p.desc=''
p.mime='image/jpeg';
p.width=w; p.height=h
p.depth=24
dt=p.write();
enc=base64.b64encode(dt).decode('ascii');
audio['metadata_block_picture']=[enc];
audio.save()
print "Successfully updated metadata."
return ogg_local_fn
示例3: get_image_size
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import height [as 别名]
def get_image_size(fname):
'''Determine the image type of fhandle and return its size.
from draco'''
with open(fname, 'rb') as fhandle:
head = fhandle.read(24)
if len(head) != 24:
return
if imghdr.what(fname) == 'png':
check = struct.unpack('>i', head[4:8])[0]
if check != 0x0d0a1a0a:
return
width, height = struct.unpack('>ii', head[16:24])
elif imghdr.what(fname) == 'gif':
width, height = struct.unpack('<HH', head[6:10])
elif imghdr.what(fname) == 'jpeg':
try:
fhandle.seek(0) # Read 0xff next
size = 2
ftype = 0
while not 0xc0 <= ftype <= 0xcf:
fhandle.seek(size, 1)
byte = fhandle.read(1)
while ord(byte) == 0xff:
byte = fhandle.read(1)
ftype = ord(byte)
size = struct.unpack('>H', fhandle.read(2))[0] - 2
# We are at a SOFn block
fhandle.seek(1, 1) # Skip `precision' byte.
height, width = struct.unpack('>HH', fhandle.read(4))
except Exception: #IGNORE:W0703
printError()
return
else:
return
fhandle.seek(0)
imgdata = fhandle.read()
img = Picture()
img.data = imgdata
img.width = width
img.height = height
return img
示例4: ogg_coverart
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import height [as 别名]
def ogg_coverart(config):
print("Adding " + config.coverart_mime + " cover art to " + config.ogg_file)
coverart = config.coverart
imgdata = open(coverart,'rb').read()
im = Image.open(coverart)
w,h = im.size
p = Picture()
p.data = imgdata
p.type = 3
p.desc = 'Cover'
p.mime = config.coverart_mime
p.width = w
p.height = h
p.depth = 24
dt=p.write()
enc=base64.b64encode(dt).decode('ascii')
audio = OggVorbis(config.ogg_file)
audio['metadata_block_picture']=[enc]
audio.save()
示例5: set_image
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import height [as 别名]
def set_image(self, image):
"""Replaces all embedded images by the passed image"""
try:
audio = self.MutagenType(self["~filename"])
data = image.file.read()
except EnvironmentError:
return
pic = Picture()
pic.data = data
pic.type = APICType.COVER_FRONT
pic.mime = image.mime_type
pic.width = image.width
pic.height = image.height
pic.depth = image.color_depth
audio.pop("coverart", None)
audio.pop("coverartmime", None)
audio["metadata_block_picture"] = base64.b64encode(pic.write())
audio.save()
self.has_images = True