本文整理汇总了Python中calibre.utils.magick.Image.size方法的典型用法代码示例。如果您正苦于以下问题:Python Image.size方法的具体用法?Python Image.size怎么用?Python Image.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.utils.magick.Image
的用法示例。
在下文中一共展示了Image.size方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: browse_icon
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def browse_icon(self, name="blank.png"):
cherrypy.response.headers["Content-Type"] = "image/png"
cherrypy.response.headers["Last-Modified"] = self.last_modified(self.build_time)
if not hasattr(self, "__browse_icon_cache__"):
self.__browse_icon_cache__ = {}
if name not in self.__browse_icon_cache__:
if name.startswith("_"):
name = sanitize_file_name2(name[1:])
try:
with open(os.path.join(config_dir, "tb_icons", name), "rb") as f:
data = f.read()
except:
raise cherrypy.HTTPError(404, "no icon named: %r" % name)
else:
try:
data = I(name, data=True)
except:
raise cherrypy.HTTPError(404, "no icon named: %r" % name)
img = Image()
img.load(data)
width, height = img.size
scaled, width, height = fit_image(width, height, 48, 48)
if scaled:
img.size = (width, height)
self.__browse_icon_cache__[name] = img.export("png")
return self.__browse_icon_cache__[name]
示例2: browse_icon
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def browse_icon(self, name='blank.png'):
cherrypy.response.headers['Content-Type'] = 'image/png'
cherrypy.response.headers['Last-Modified'] = self.last_modified(self.build_time)
if not hasattr(self, '__browse_icon_cache__'):
self.__browse_icon_cache__ = {}
if name not in self.__browse_icon_cache__:
if name.startswith('_'):
name = sanitize_file_name2(name[1:])
try:
with open(os.path.join(config_dir, 'tb_icons', name), 'rb') as f:
data = f.read()
except:
raise cherrypy.HTTPError(404, 'no icon named: %r'%name)
else:
try:
data = I(name, data=True)
except:
raise cherrypy.HTTPError(404, 'no icon named: %r'%name)
img = Image()
img.load(data)
width, height = img.size
scaled, width, height = fit_image(width, height, 48, 48)
if scaled:
img.size = (width, height)
self.__browse_icon_cache__[name] = img.export('png')
return self.__browse_icon_cache__[name]
示例3: create_cover
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def create_cover(report, icons=(), cols=5, size=60, padding=8):
icons = icons or tuple(default_cover_icons(cols))
rows = int(math.ceil(len(icons) / cols))
canvas = create_canvas(cols * (size + padding), rows * (size + padding), '#eeeeee')
y = -size - padding // 2
x = 0
for i, icon in enumerate(icons):
if i % cols == 0:
y += padding + size
x = padding // 2
else:
x += size + padding
if report and icon in report.name_map:
ipath = os.path.join(report.path, report.name_map[icon])
else:
ipath = I(icon, allow_user_override=False)
img = Image()
with open(ipath, 'rb') as f:
img.load(f.read())
scaled, nwidth, nheight = fit_image(img.size[0], img.size[1], size, size)
img.size = nwidth, nheight
dx = (size - nwidth) // 2
canvas.compose(img, x + dx, y)
return canvas.export('JPEG')
示例4: convert_image
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def convert_image(url, data, sizes, grayscale, removetrans, imgtype="jpg", background="#ffffff"):
export = False
img = Image()
img.load(data)
owidth, oheight = img.size
nwidth, nheight = sizes
scaled, nwidth, nheight = fit_image(owidth, oheight, nwidth, nheight)
if normalize_format_name(img.format) == "gif" and GifInfo(StringIO(data), CHECK_IS_ANIMATED).frameCount > 1:
raise exceptions.RejectImage("Animated gifs come out purely--not going to use it.")
if scaled:
img.size = (nwidth, nheight)
export = True
if normalize_format_name(img.format) != imgtype:
export = True
if removetrans and img.has_transparent_pixels():
canvas = Image()
canvas.create_canvas(int(img.size[0]), int(img.size[1]), unicode(background))
canvas.compose(img)
img = canvas
export = True
if grayscale and img.type != "GrayscaleType":
img.type = "GrayscaleType"
export = True
if export:
return (img.export(convtype[imgtype]), imgtype, imagetypes[imgtype])
else:
logger.debug("image used unchanged")
return (data, imgtype, imagetypes[imgtype])
示例5: convert_image
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def convert_image(url,data,sizes,grayscale,
removetrans,imgtype="jpg",background='#ffffff'):
export = False
img = Image()
img.load(data)
owidth, oheight = img.size
nwidth, nheight = sizes
scaled, nwidth, nheight = fit_image(owidth, oheight, nwidth, nheight)
if scaled:
img.size = (nwidth, nheight)
export = True
if normalize_format_name(img.format) != imgtype:
export = True
if removetrans and img.has_transparent_pixels():
canvas = Image()
canvas.create_canvas(int(img.size[0]), int(img.size[1]), str(background))
canvas.compose(img)
img = canvas
export = True
if grayscale and img.type != "GrayscaleType":
img.type = "GrayscaleType"
export = True
if export:
return (img.export(convtype[imgtype]),imgtype,imagetypes[imgtype])
else:
logger.debug("image used unchanged")
return (data,imgtype,imagetypes[imgtype])
示例6: resize_image
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def resize_image(self, raw, base, max_width, max_height):
img = Image()
img.load(raw)
resized, nwidth, nheight = fit_image(img.size[0], img.size[1], max_width, max_height)
if resized:
img.size = (nwidth, nheight)
base, ext = os.path.splitext(base)
base = base + '-%dx%d%s' % (max_width, max_height, ext)
raw = img.export(ext[1:])
return raw, base, resized
示例7: create_cover_page
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def create_cover_page(
top_lines,
logo_path,
width=590,
height=750,
bgcolor="#ffffff",
output_format="jpg",
texture_data=None,
texture_opacity=1.0,
):
"""
Create the standard calibre cover page and return it as a byte string in
the specified output_format.
"""
canvas = create_canvas(width, height, bgcolor)
if texture_data and hasattr(canvas, "texture"):
texture = Image()
texture.load(texture_data)
texture.set_opacity(texture_opacity)
canvas.texture(texture)
bottom = 10
for line in top_lines:
twand = create_text_wand(line.font_size, font_path=line.font_path)
bottom = draw_centered_text(canvas, twand, line.text, bottom)
bottom += line.bottom_margin
bottom -= top_lines[-1].bottom_margin
foot_font = P("fonts/liberation/LiberationMono-Regular.ttf")
vanity = create_text_arc(__appname__ + " " + __version__, 24, font=foot_font, bgcolor="#00000000")
lwidth, lheight = vanity.size
left = int(max(0, (width - lwidth) / 2.0))
top = height - lheight - 10
canvas.compose(vanity, left, top)
available = (width, int(top - bottom) - 20)
if available[1] > 40:
logo = Image()
logo.open(logo_path)
lwidth, lheight = logo.size
scaled, lwidth, lheight = fit_image(lwidth, lheight, *available)
if scaled:
logo.size = (lwidth, lheight)
left = int(max(0, (width - lwidth) / 2.0))
top = bottom + 10
extra = int((available[1] - lheight) / 2.0)
if extra > 0:
top += extra
canvas.compose(logo, left, top)
return canvas.export(output_format)
示例8: thumbnail
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def thumbnail(data, width=120, height=120, bgcolor='#ffffff', fmt='jpg',
preserve_aspect_ratio=True, compression_quality=70):
img = Image()
img.load(data)
owidth, oheight = img.size
if not preserve_aspect_ratio:
scaled = owidth > width or oheight > height
nwidth = width
nheight = height
else:
scaled, nwidth, nheight = fit_image(owidth, oheight, width, height)
if scaled:
img.size = (nwidth, nheight)
canvas = create_canvas(img.size[0], img.size[1], bgcolor)
canvas.compose(img)
if fmt == 'jpg':
canvas.set_compression_quality(compression_quality)
return (canvas.size[0], canvas.size[1], canvas.export(fmt))
示例9: browse_icon
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def browse_icon(self, name='blank.png'):
cherrypy.response.headers['Content-Type'] = 'image/png'
cherrypy.response.headers['Last-Modified'] = self.last_modified(self.build_time)
if not hasattr(self, '__browse_icon_cache__'):
self.__browse_icon_cache__ = {}
if name not in self.__browse_icon_cache__:
try:
data = I(name, data=True)
except:
raise cherrypy.HTTPError(404, 'no icon named: %r'%name)
img = Image()
img.load(data)
width, height = img.size
scaled, width, height = fit_image(width, height, 48, 48)
if scaled:
img.size = (width, height)
self.__browse_icon_cache__[name] = img.export('png')
return self.__browse_icon_cache__[name]
示例10: thumbnail
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def thumbnail(data, width=120, height=120, bgcolor='#ffffff', fmt='jpg',
preserve_aspect_ratio=True, compression_quality=70):
img = Image()
img.load(data)
owidth, oheight = img.size
if width is None:
width = owidth
if height is None:
height = oheight
if not preserve_aspect_ratio:
scaled = owidth > width or oheight > height
nwidth = width
nheight = height
else:
scaled, nwidth, nheight = fit_image(owidth, oheight, width, height)
if scaled:
img.size = (nwidth, nheight)
canvas = create_canvas(img.size[0], img.size[1], bgcolor)
canvas.compose(img)
data = image_to_data(canvas.img, compression_quality=compression_quality)
return (canvas.size[0], canvas.size[1], data)
示例11: HandleImage
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import size [as 别名]
def HandleImage(self, imageData, imagePath):
from calibre.utils.magick import Image
img = Image()
img.load(imageData)
(x,y) = img.size
if self.opts:
if self.opts.snb_full_screen:
SCREEN_X, SCREEN_Y = self.opts.output_profile.screen_size
else:
SCREEN_X, SCREEN_Y = self.opts.output_profile.comic_screen_size
else:
SCREEN_X = 540
SCREEN_Y = 700
# Handle big image only
if x > SCREEN_X or y > SCREEN_Y:
xScale = float(x) / SCREEN_X
yScale = float(y) / SCREEN_Y
scale = max(xScale, yScale)
# TODO : intelligent image rotation
# img = img.rotate(90)
# x,y = y,x
img.size = (x / scale, y / scale)
img.save(imagePath)