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


Python Image.scale方法代码示例

本文整理汇总了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)
开发者ID:suoinguon,项目名称:pgmagick,代码行数:9,代码来源:test_pgmagick_api.py

示例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'))
开发者ID:suoinguon,项目名称:pgmagick,代码行数:13,代码来源:test_pgmagick_api.py

示例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)
开发者ID:nublic,项目名称:Nublic,代码行数:17,代码来源:images.py

示例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)
开发者ID:hhatto,项目名称:pgmagick,代码行数:26,代码来源:test_pgmagick_api.py

示例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')
开发者ID:suoinguon,项目名称:pgmagick,代码行数:6,代码来源:test_pgmagick_api.py

示例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


#.........这里部分代码省略.........
开发者ID:SparrowJang,项目名称:icon_converter,代码行数:103,代码来源:adapter.py

示例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')
开发者ID:hhatto,项目名称:pgmagick,代码行数:6,代码来源:test_pgmagick_api.py

示例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')
开发者ID:hhatto,项目名称:pgmagick,代码行数:7,代码来源:test_pgmagick_api.py


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