本文整理汇总了Python中pgmagick.api.Image.scale方法的典型用法代码示例。如果您正苦于以下问题:Python Image.scale方法的具体用法?Python Image.scale怎么用?Python Image.scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmagick.api.Image
的用法示例。
在下文中一共展示了Image.scale方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_size_property
# 需要导入模块: from pgmagick.api import Image [as 别名]
# 或者: from pgmagick.api.Image import scale [as 别名]
def test_size_property(self):
im = Image((500, 300), 'red')
self.assertEqual(im.width, 500)
self.assertEqual(im.height, 300)
im.scale(0.5)
self.assertEqual(im.width, 250)
self.assertEqual(im.height, 150)
示例2: test_unicodefilename
# 需要导入模块: from pgmagick.api import Image [as 别名]
# 或者: from pgmagick.api.Image import scale [as 别名]
def test_unicodefilename(self):
self.img.write('unicode.png')
if sys.version_info >= (3, ):
img = Image('unicode.png')
else:
img = Image(unicode('unicode.png'))
img.scale(0.5)
if sys.version_info >= (3, ):
img.write('unicode.jpg')
else:
img.write(unicode('unicode.jpg'))
示例3: _ensure
# 需要导入模块: from pgmagick.api import Image [as 别名]
# 或者: from pgmagick.api.Image import scale [as 别名]
def _ensure(id_, folderer, getter):
folder = folderer(id_)
# Create folder if it does not exists
if not os.path.exists(folder):
os.makedirs(folder)
# Download image
original = os.path.join(folder, ORIGINAL_FILENAME)
if not os.path.exists(original):
getter(original)
# Create thumbnail
thumb = os.path.join(folder, THUMBNAIL_FILENAME)
if os.path.exists(original) and not os.path.exists(thumb):
img = Image(original)
img.scale((THUMBNAIL_SIZE, THUMBNAIL_SIZE))
img.write(thumb)
示例4: test_scale_with_filtertype
# 需要导入模块: from pgmagick.api import Image [as 别名]
# 或者: from pgmagick.api.Image import scale [as 别名]
def test_scale_with_filtertype(self):
img = Image((600, 400), 'gradient:#ffffff-#000000')
img.scale(0.6, 'Catrom')
img.write('t.jpg')
m = hashlib.md5()
with open('t.jpg', 'rb') as fp:
m.update(fp.read())
scale_with_filtertype_catrom_digest = m.hexdigest()
img = Image((600, 400), 'gradient:#ffffff-#000000')
img.scale(0.6, 'Cubic')
img.write('t.jpg')
m = hashlib.md5()
with open('t.jpg', 'rb') as fp:
m.update(fp.read())
scale_with_filtertype_cubic_digest = m.hexdigest()
img = Image((600, 400), 'gradient:#ffffff-#000000')
img.scale(0.6)
img.write('t.jpg')
m = hashlib.md5()
with open('t.jpg', 'rb') as fp:
m.update(fp.read())
scale_digest = m.hexdigest()
self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_digest)
self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_with_filtertype_cubic_digest)
示例5: test_scale
# 需要导入模块: from pgmagick.api import Image [as 别名]
# 或者: from pgmagick.api.Image import scale [as 别名]
def test_scale(self):
im = Image((600, 400), 'red')
im.scale(0.6)
im.write('t.jpg')
示例6: Image
# 需要导入模块: from pgmagick.api import Image [as 别名]
# 或者: from pgmagick.api.Image import scale [as 别名]
class Image( object ):
"""
This is pgmagick.api.Image adapter.And add some util tools.
"""
def __init__( self, filename = None, color = None, *args, **kargs ):
"""
Init a adapter.
:Args:
- filename - This param is a file name or Image of pgmagick.
- Color - This is color of pgmagick.api.
"""
if isinstance( filename, OrginallyImage ):
self.__apiImage = ApiImage()
self.__apiImage.img = filename
else:
self.__apiImage = ApiImage( filename, color, args, kargs )
def border( self, size, color_str = "white" ):
"""
Set a border and color.
:Args:
- size - This is dict. (example: {"width":2,"height":2} )
- color_str - The default value is white. ( example: "#ffeeff" )
"""
img = self.get_pgmagick_image()
img.borderColor( Color( color_str ) )
img.border( Geometry( size.get("width"), size.get("height") ) );
def crop( self, bounds ):
"""
Crop this image.
:Args:
- bounds - This is bounds dict. ( example:{"width":40,"height":40,"x":0,"y":0} )
"""
img = self.get_pgmagick_image()
img.crop( Geometry( bounds.get("width"), bounds.get("height"), bounds.get("x"), bounds.get("y") ) )
def resize( self, size, is_force = False ):
"""
Reset a size.
:Args:
- size - This is dict. (example: {"width":2,"height":2} )
- isForce - This is boolean.The image width or height will be possible less to set size,when isForce is true.
"""
if is_force:
self.__apiImage.scale( ( size.get("width"), size.get("height") ) )
else:
height = self.__apiImage.height
width = self.__apiImage.width
ratio_height = float( size.get("height") ) / float( height )
ratio_width = float( size.get("width") ) / float( width )
ratio = 1
if ratio_height < ratio_width:
ratio = ratio_width
else:
ratio = ratio_height
self.__apiImage.scale( ( ratio * width, ratio * height ) )
def get_blob( self ):
"""
Get a blob object.
"""
blob = Blob()
img = self.get_pgmagick_image()
img.write( blob, "png" )
return blob
#.........这里部分代码省略.........
示例7: test_scale
# 需要导入模块: from pgmagick.api import Image [as 别名]
# 或者: from pgmagick.api.Image import scale [as 别名]
def test_scale(self):
img = Image((600, 400), 'gradient:#ffffff-#000000')
img.scale(0.6)
img.write('t.jpg')
示例8: test_unicodefilename
# 需要导入模块: from pgmagick.api import Image [as 别名]
# 或者: from pgmagick.api.Image import scale [as 别名]
def test_unicodefilename(self):
self.img.write('unicode.png')
img = Image(u'unicode.png')
img.scale(0.5)
img.write(u'unicode.jpg')