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


Python Image.columns方法代码示例

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


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

示例1: post

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
    def post(self):
        # check pic exgister
        if self.request.files == {} or 'pic' not in self.request.files:
            self.write('<script>m_ksb_msg.show("请选择图片")</script>')
            return

        # check pic format
        image_type_list = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/bmp', 'image/png', 'image/x-png']
        send_file = self.request.files['pic'][0]

        if send_file['content_type'] not in image_type_list:
            self.write('<script>m_ksb_msg.show("仅支持jpg,jpeg,bmp,gif,png格式的图片!")</script>')
            return
        # check pic size 4M
        if len(send_file['body']) > 4 * 1024 * 1024:
            self.write('<script>m_ksb_msg.show("请上传4M以下的图片");</script>')
            return

        # create temp file
        tmp_file = tempfile.NamedTemporaryFile(delete=True)
        tmp_file.write(send_file['body'])
        tmp_file.seek(0)

        # illegal pic can't open with Image
        try:
            image_one = Image(tmp_file.name)
        except IOEturerror:
            logging.info(error)
            logging.info('+'*30 + '\n')
            logging.info(self.request.headers)
            tmp_file.close()
            self.write('<script>m_ksb_msg.show("图片不合法!")</script>')
            return

        # check pixel
        if image_one.columns() < 250 or image_one.rows() < 250 or \
                image_one.columns() > 2000 or image_one.rows() > 2000:
            tmp_file.close()
            self.write('<script>m_ksb_msg.show("图片长宽在250px~2000px之间!")</script>')
            return

        # saving
        image_path = "./static/pic/goods/"
        image_format = send_file['filename'].split('.').pop().lower()
        tmp_name = image_path + str(int(time.time())) + image_format
        image_one.write(tmp_name)

        # close temp
        tmp_file.close()
        self.write('<script>m_ksb_msg.show("文件上传成功,路径为:" + image_path[1:])</script>')
        return
开发者ID:onionisi,项目名称:booking,代码行数:53,代码来源:upload_test.py

示例2: emotion_to_avatar

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
def emotion_to_avatar(emotion, font_path, color=Color("black")):
    """使用颜文字(文本)来生成一张方形图片

    :type emotion: string
    :param emotion: 需要绘制在图像上的文本

    :type font_path: string
    :param font_path: 字体文件路径

    :type color: Color
    :param color: 绘制的文本颜色

    返回结果是一个 Image 对象,并叫将会被规整到 AVATAR_SIZE 设定的大小
    """
    font_size = 128
    max_size = len(emotion.decode('utf-8')) * font_size
    img = Image(Geometry(max_size, max_size), Color("white"))

    img.font(font_path)
    img.fontPointsize(font_size)
    img.annotate(emotion, GravityType.CenterGravity)
    img.trim()
    img.write('tmp.png')

    height = img.rows()
    width = img.columns()

    origin_pimg = PImage.open('tmp.png')
    new_pimg = PImage.new("RGB", (max(height, width), max(height, width)), "white")
    if height > width:
        new_pimg.paste(origin_pimg, ((height - width) / 2, 0))
    else:
        new_pimg.paste(origin_pimg, (0, (width - height) / 2))
    return new_pimg.resize(AVATAR_SIZE, PImage.ANTIALIAS)
开发者ID:Linusp,项目名称:diffusion,代码行数:36,代码来源:emotion.py

示例3: resize8

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
    def resize8( srcFile="", destFile="", w=200,h=200 ):
        img = Image(srcFile)

        #.def("extent", (void (Magick::Image::*)(const Magick::Geometry&, const Magick::Color&, const Magick::GravityType))&Magick::Image::extent)
        #白色背景图
        backImg = None

        #sw源图宽度
        sw = img.columns()
        #sh源图高度
        sh = img.rows()
        #若目标图的宽或高都比源图大则不处理
        if ( sw <= w and sh <= h ):
            backImg = Image(Geometry(w,h), 'white' )
            backImg.composite(img, GravityType.CenterGravity, co.OverCompositeOp)
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        #目标的宽或高都比源图的小则进行裁剪
        elif ( sw > w and sh > h ):
            #源图的宽高比
            sratio = float(sw)/float(sh)
            rratio = float(w)/float(h)
            #若源图宽高比大于目标图的宽高比的话,则就高缩放,从0,0位置裁前源图宽
            #print sratio,rratio
            if ( sratio > rratio ):
                hscale = float(h)/float(sh)
                rw = int(sw*hscale)
                rh = int(sh*hscale)
            else:
                wscale = float(w)/float(sw)
                rw = int(sw*wscale)
                rh = int(sh*wscale)

            linePos = int( (rw-w)/2)
            colPos = int( (rh-h)/2)

            img.scale("%dx%d"%(rw,rh))
            img.crop(Geometry(w,h,linePos,colPos))
            img.profile("*",Blob())
            img.write(destFile)
            return "True"
        elif ( sw > w ):
            backImg = Image(Geometry(w,h), 'white' )
            img.crop(Geometry(w,sh,int((sw-w)/2)))
            backImg.composite(img,GravityType.CenterGravity,co.OverCompositeOp )
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        elif ( sh > h ):
            backImg = Image(Geometry(w,h), 'white' )
            img.crop( Geometry(sw,h,0,int((sh-h)/2) ) )
            backImg.composite(img, GravityType.CenterGravity,co.OverCompositeOp )
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:59,代码来源:myGraphicsMagick.py

示例4: resize0

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
    def resize0( srcFile="", destFile="", w=200 ):

        img = Image(srcFile)
        sw = img.columns()
        sh = img.rows()
        if ( sw > w  ):
            tw = w
            th = sh*(float(w)/float(sw))
            img.scale("%dx%d"%(tw,th))
        img.profile("*", Blob())
        img.write(destFile)
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:14,代码来源:myGraphicsMagick.py

示例5: resize7

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
    def resize7( srcFile="", destFile="", w=200,h=200 ):
        img = Image(srcFile)

        #白色背景图
        backImg = None

        #sw源图宽度
        sw = img.columns()
        #sh源图高度
        sh = img.rows()
        #若目标图的宽或高都比源图大则不处理
        if ( sw <= w and sh <= h ):
            backImg = Image(Geometry(w,h), 'white' )
            backImg.composite(img, Geometry( sw, sh, 0, 0 ), co.OverCompositeOp)
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        #目标的宽或高都比源图的小则进行裁剪
        elif ( sw > w and sh > h ):
            #源图的宽高比
            sratio = float(sw)/float(sh)
            rratio = float(w)/float(h)
            #若源图宽高比大于目标图的宽高比的话,则就高缩放,从0,0位置裁前源图宽
            #print sratio,rratio
            if ( sratio > rratio ):
                hscale = float(h)/float(sh)
                rw = int(sw*hscale)
                rh = int(sh*hscale)
            else:
                wscale = float(w)/float(sw)
                rw = int(sw*wscale)
                rh = int(sh*wscale)
            img.scale("%dx%d"%(rw,rh))
            img.crop(Geometry(w,h,0,0))
            img.profile("*",Blob())
            img.write(destFile)
            return "True"
        elif ( sw > w ):
            backImg = Image(Geometry(w,h), 'white' )
            img.crop(Geometry(w,sh))
            backImg.composite(img,Geometry(w,h,0,0),co.OverCompositeOp )
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        elif ( sh > h ):
            backImg = Image(Geometry(w,h), 'white' )
            img.crop( Geometry(sw,h) )
            backImg.composite(img, Geometry(w,h,0,0),co.OverCompositeOp )
            backImg.profile("*",Blob())
            backImg.write(destFile)
            return "True"
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:54,代码来源:myGraphicsMagick.py

示例6: resize10

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
    def resize10( srcFile="", destFile="", w=200 ):
        img = Image( srcFile )
        sw = img.columns()
        sh = img.rows()
        scale = sw*sh

        if ( scale > w ):
            tw = int(sw*((float(w)/float(scale))**0.5))
            th = int(w/tw)
            img.scale("%dx%d"%(tw,th))
        img.profile("*",Blob())
        img.write(destFile)
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:15,代码来源:myGraphicsMagick.py

示例7: convertGMtoPIL

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
def convertGMtoPIL(gmimage):
    """
    Convert GraphicsMagick image to PIL

    work with grayscale and colour
    """
    img = Image(gmimage)  # make copy
    gmimage.depth(8)
    img.magick("RGB")
    w, h = img.columns(), img.rows()
    blob = Blob()
    img.write(blob)
    data = blob.data

    # convert string array to an RGB PIL image
    pilimage = PilImage.fromstring("RGB", (w, h), data)
    return pilimage
开发者ID:uq-eresearch,项目名称:uqam,代码行数:19,代码来源:source_generators.py

示例8: resize9

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
    def resize9( srcFile="", destFile="", w=200,h=200, color="", crop=False, align="center" ):
        img = Image(srcFile)

        #白色背景图
        backImg = None

        #sw源图宽度
        sw = img.columns()
        #sh源图高度
        sh = img.rows()

        #目标图与源图的宽比例
        wScale = float(w)/float(sw)
        #目标图与源图的高比例
        hScale = float(h)/float(sh)

        if ( w > sw or h > sh ):
            if (wScale == hScale ):
                tw = w
                th = h
            elif ( wScale < hScale ):
                th = h
                tw = sw*wScale
            else:
                tw = w
                th = sh*hScale
        elif( w<sw or h < sh ):
            if (wScale == hScale ):
                tw = w
                th = h
            elif ( wScale < hScale ):
                th = h
                tw = sw*wScale
            else:
                tw = w
                th = sh*hScale
        else:
            tw = sw
            th = sh
        img.scale("%dx%d"%(tw,th))
        backImg = Image(Geometry(w,h), 'white' )
        backImg.composite(img,GravityType.CenterGravity,co.OverCompositeOp )
        backImg.profile("*",Blob())
        backImg.write(destFile)
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:47,代码来源:myGraphicsMagick.py

示例9: resize1

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
    def resize1( srcFile="", destFile="", w=200,h=200 ):
        img = Image( srcFile )
        #sw源图宽度
        sw = img.columns()
        sh = img.rows()
        #要缩略的宽度
        rw = w
        #要缩略的高度
        rh = h

        #源图的宽高比
        sratio = float(sw)/float(sh)
        #目标图的宽高比
        rratio = float(rw)/float(rh)

        #若源图的宽高比大于目标图的宽高比时,则按照高进行缩放后再裁剪宽度
        if ( sratio > rratio ):
            hscale = float(rh)/float(sh)
            w = sw*hscale
            h = sh*hscale
            #print (sw,sh,w,h,rw,rh,hscale)
            #就高缩放
            img.scale("%dx%d"%(w,h))
            #计算裁剪宽的部分的横坐标,超出的宽的部分进行裁剪
            tmpRowsPos = int((sw*hscale - rw)/2)
            img.crop(Geometry( rw,rh,tmpRowsPos,0 ) )
        #若源图的宽高比小于目标图的宽高比时,则按照宽进行缩放后再裁剪高度
        else:
            wscale = float(rw)/float(sw)

            w = sw*wscale
            h = sh*wscale
            #print (sw,sh,w,h,rw,rh,wscale)
            #就宽缩放
            img.scale("%dx%d"%(w,h))
            tmpColsPos = int((sh*wscale-rh)/2 )
            img.crop( Geometry( rw,rh,0,tmpColsPos )  )
            #只有宽大于目标宽度的时候才进行缩略
        #elif ( sw > w ):
        #    pass
        #unicodestring.encode("utf-8")
        img.profile("*", Blob())
        img.write(destFile)
        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:46,代码来源:myGraphicsMagick.py

示例10: resize5

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
    def resize5( srcFile="", destFile="", w=200,h=200 ):

        #CONVERT_RESIZE_CROP = "%s -resize %d" + "x" + " -crop %d" + "x" + "%d" + "+0+0 +repage %s"
        img = Image( srcFile )
        sw = img.columns()
        sh = img.rows()

        #源图宽高比
        sratio = float(sw)/float(sh)
        #目标图宽高比
        tratio = float(w)/float(h)

        #若源图的宽高比大于目标图的宽高比,则
        if( sratio == tratio and (w==sw) and (h==sh )):
            img.profile("*",Blob())
            img.write(destFile)
            return "True"
        elif ( sratio > tratio ):
            hscale = float(w)/float(sw)
            tw = sw*hscale
            th = sh*hscale
            img.scale("%dx"%(tw))
            if ( th > h ):
                img.crop(Geometry(w,h))
            img.profile("*",Blob())
            img.write(destFile)
            return "True"
        elif( sratio < tratio ):
            wscale = float(w)/float(sw)

            tw = int(sw*wscale)
            th = int(sh*wscale)
            #260 132 670 502 0.388059701493 260 194

            img.scale("%dx%d"%(tw,th))
            if ( th > h ):
                img.crop(Geometry(w,h))
            img.profile("*",Blob())
            img.write(destFile)
            return "True"

        return "True"
开发者ID:sqj0213,项目名称:photoEncode,代码行数:44,代码来源:myGraphicsMagick.py

示例11: Blob

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('infiles', nargs='*', type=argparse.FileType('r'), default=sys.stdin)
parser.add_argument('-o', default="split%d.pnm")
args = parser.parse_args()

number = 0
outpattern = args.o

for file in args.infiles:
  blob = Blob(file.read())
  file.close()

  # upper half
  im = Image(blob)
  width = im.columns()
  height = im.rows() // 2
  geo = Geometry( '%dx%d' % (width,height) )
  im.crop(geo)
  im.write(outpattern % number)

  # lower half
  im = Image(blob)
  width = im.columns()
  height = im.rows() // 2
  geo = Geometry( '%dx%d+0+%d' % (width,height,height) )
  im.crop(geo)
  im.rotate(180)
  im.write(outpattern % (number + 1))

  number += 2
开发者ID:thkoch2001,项目名称:general-config,代码行数:32,代码来源:splitadfduplex.py

示例12: post

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import columns [as 别名]
    def post(self, gid=None):
        good_keys = ['catalog', 'name', 'subname', 'price', 'discount']
        good = dict()
        if gid:
            good = self.db.goods.find_one({'_id':gid})
        for key in good_keys:
            good[key] = self.get_argument(key, None)

        if gid:
            self.db.goods.save(good)
        else:
            #========= new id generate
            gid = 'G'+(str(uuid.uuid4()).split('-'))[4].upper()

            #========= image handler
            # check pic exgister
            if self.request.files == {} or 'pic' not in self.request.files:
                self.write('<script>alert("请选择图片")</script>')

            send_file = self.request.files['pic'][0]
            # check pic format
            image_type = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/bmp', 'image/png', 'image/x-png']
            if send_file['content_type'] not in image_type:
                self.write('<script>alert("仅支持jpg,jpeg,bmp,gif,png格式的图片")</script>')

            # check pic size 4M
            if len(send_file['body']) > 4 * 1024 * 1024:
                self.write('<script>alert("请上传4M以下的图片");</script>')

            # create temp file
            tmp_file = tempfile.NamedTemporaryFile(delete=True)
            tmp_file.write(send_file['body'])
            tmp_file.seek(0)

            # illegal pic can't open with Image
            try:
                image_one = Image(tmp_file.name)
            except IOError:
                logging.info(error)
                logging.info('+'*30 + '\n')
                logging.info(self.request.headers)
                tmp_file.close()
                self.write('<script>alert("图片不合法!")</script>')

            # check pixel
            if image_one.columns() < 250 or image_one.rows() < 250 or \
                    image_one.columns() > 2000 or image_one.rows() > 2000:
                tmp_file.close()
                self.write('<script>alert("图片长宽在250px~2000px之间!")</script>')

            # saving two type
            image_path = "./static/images/goods/"
            image_format = send_file['filename'].split('.').pop().lower()
            thumbnail_174 = image_path + gid + '_174.' + image_format
            image_one.quality(100)
            image_one.scale('174x174')
            image_one.write(str(thumbnail_174))

            thumbnail_94 = image_path + gid + '_94.' + image_format
            image_one.quality(100)
            image_one.scale('94x94')
            image_one.write(str(thumbnail_94))

            # close temp
            tmp_file.close()

            good['_id'] = gid
            good['image1'] = thumbnail_174
            good['image2'] = thumbnail_94

            self.db.goods.insert(good)

        self.redirect('/admin', permanent=True)
开发者ID:onionisi,项目名称:booking,代码行数:75,代码来源:main.py


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