Exemple #1
0
 def process_gif(self, source, target, size):
     from pgmagick import ImageList, Geometry
     list = ImageList()
     list.readImages(source)
     list.scaleImages(Geometry(size['size'][0], size['size'][1]))
     list.writeImages(target.name)
     pass
    def resize0( srcFile="", destFile="", w=200,h=200 ):
        imgs = ImageList()
        imgs.readImages( srcFile )
        imgs.scaleImages("%dx>"%w)

        imgs.writeImages(destFile)
        return "True"
    def resize0(srcFile="", destFile="", w=200, h=200):
        imgs = ImageList()
        imgs.readImages(srcFile)
        imgs.scaleImages("%dx>" % w)

        imgs.writeImages(destFile)
        return "True"
 def resize2( srcFile="", destFile="", w=200, h=200, Ignore=False ):
     imgs = ImageList()
     imgs.readImages( srcFile )
     if ( h != -1 ):
         imgs.scaleImages("%dx%d!" % (w,h))
     else:
         imgs.scaleImages("%dx!" % w )
     imgs.writeImages(destFile)
     return "True"
 def resize2(srcFile="", destFile="", w=200, h=200, Ignore=False):
     imgs = ImageList()
     imgs.readImages(srcFile)
     if (h != -1):
         imgs.scaleImages("%dx%d!" % (w, h))
     else:
         imgs.scaleImages("%dx!" % w)
     imgs.writeImages(destFile)
     return "True"
    def resize4(srcFile="", destFile="", w=200, h=200):
        imgs = ImageList()
        imgs.readImages(srcFile)
        imgs.scaleImages("%dx%d<" % (int(w), int(h)))
        """
        gifFrame0 = imgs.__getitem__(0)

        sw = gifFrame0.columns()
        sh = gifFrame0.rows()
        #小于指定的宽高时才拉伸,notice是等比缩放,目标尺寸不成比例时不会达到目标尺寸
        if ( sw < w or sh < h ):
            imgs.scaleImages("%dx%d" % (int(w),int(h)))
        """
        imgs.writeImages(destFile)
        return "True"
    def resize4( srcFile="", destFile="", w=200,h=200 ):
        imgs = ImageList()
        imgs.readImages( srcFile )
        imgs.scaleImages("%dx%d<" % (int(w),int(h)))
        """
        gifFrame0 = imgs.__getitem__(0)

        sw = gifFrame0.columns()
        sh = gifFrame0.rows()
        #小于指定的宽高时才拉伸,notice是等比缩放,目标尺寸不成比例时不会达到目标尺寸
        if ( sw < w or sh < h ):
            imgs.scaleImages("%dx%d" % (int(w),int(h)))
        """
        imgs.writeImages(destFile)
        return "True"
    def resize5(srcFile="", destFile="", w=200, h=200):
        imgs = ImageList()
        outImgs = ImageList()
        imgs.readImages(srcFile)
        gifFrameLen = len(imgs)
        #取得gif的第0帧
        img = imgs.__getitem__(0)
        #sw源图宽度
        sw = img.columns()
        sh = img.rows()
        #要缩略的宽度
        rw = w
        #要缩略的高度
        rh = h

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

        if (sw > w):
            imgs.scaleImages("%dx" % w)
        #
        #??长大高小的图片处理问题:1600x94 转换为160x298按照宽度等比缩放
        #??长大高小的图片处理问题:1600x94 转换为522x294
        #若源图的宽高比大于目标图的宽高比时,则按照高进行缩放后再裁剪宽度
        else:
            if (sratio > rratio):
                hscale = float(rh) / float(sh)
                w = int(sw * hscale)
                h = int(sh * hscale)
                #print (sw,sh,w,h,rw,rh,hscale)
                #就高缩放
                imgs.scaleImages("%dx" % (w))

            #若源图的宽高比小于目标图的宽高比时,则按照宽进行缩放后再裁剪高度
            else:
                wscale = float(rw) / float(sw)

                w = int(sw * wscale)
                h = int(sh * wscale)
                #print (sw,sh,w,h,rw,rh,wscale)
                #就宽缩放
                imgs.scaleImages("%dx%d" % (w, h))
                #缩放完后遍历裁剪
            for i in range(gifFrameLen):
                tmpImg = imgs.__getitem__(i)
                tmpImg.crop(Geometry(rw, rh, 0, 0))
                tmpImg.profile("*", Blob())
                outImgs.append(tmpImg)
                #(102, 900, 160, 1411, 160, 298)
                #print( sw,sh,w,h,rw,rh)

        if (len(outImgs) > 0):
            outImgs.writeImages(destFile)
        else:
            imgs.writeImages(destFile)
        return "True"
    def resize5( srcFile="", destFile="", w=200,h=200 ):
        imgs = ImageList()
        outImgs = ImageList()
        imgs.readImages( srcFile )
        gifFrameLen = len( imgs )
        #取得gif的第0帧
        img = imgs.__getitem__( 0 )
        #sw源图宽度
        sw = img.columns()
        sh = img.rows()
        #要缩略的宽度
        rw = w
        #要缩略的高度
        rh = h

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

        if ( sw>w ):
            imgs.scaleImages( "%dx"%w)
        #
        #??长大高小的图片处理问题:1600x94 转换为160x298按照宽度等比缩放
        #??长大高小的图片处理问题:1600x94 转换为522x294
        #若源图的宽高比大于目标图的宽高比时,则按照高进行缩放后再裁剪宽度
        else:
            if ( sratio > rratio ):
                hscale = float(rh)/float(sh)
                w = int(sw*hscale)
                h = int(sh*hscale)
                #print (sw,sh,w,h,rw,rh,hscale)
                #就高缩放
                imgs.scaleImages( "%dx"%(w) )

            #若源图的宽高比小于目标图的宽高比时,则按照宽进行缩放后再裁剪高度
            else:
                wscale = float(rw)/float(sw)

                w = int(sw*wscale)
                h = int(sh*wscale)
                #print (sw,sh,w,h,rw,rh,wscale)
                #就宽缩放
                imgs.scaleImages("%dx%d"%(w,h))
                #缩放完后遍历裁剪
            for i in range( gifFrameLen ):
                tmpImg = imgs.__getitem__( i )
                tmpImg.crop(Geometry( rw,rh,0,0 ) )
                tmpImg.profile("*", Blob())
                outImgs.append( tmpImg )
                #(102, 900, 160, 1411, 160, 298)
                #print( sw,sh,w,h,rw,rh)

        if ( len( outImgs ) > 0 ):
            outImgs.writeImages(destFile)
        else:
            imgs.writeImages(destFile)
        return "True"
 def resize3( srcFile="", destFile="", w=200, h=200, Ignore=False ):
     imgs = ImageList()
     imgs.readImages(srcFile)
     imgs.scaleImages("%dx%d>"%(w,h))
     imgs.writeImages(destFile)
     return "True"
    def resize6( srcFile="", destFile="", w=200,h=200 ):
        imgs = ImageList()

        imgs.readImages(srcFile)
        gifFrameLen = len(imgs)

        #若只有一帧直接调用静态方法输出
        if ( gifFrameLen == 1 ):
            return staticPhoto.resize6(srcFile,destFile,w,h)

        outImg = ImageList()

        #取得第0帧
        gifFrame0 = imgs.__getitem__(0)

        #sw源图宽度
        sw = gifFrame0.columns()
        sh = gifFrame0.rows()
        #如果宽高比大小于倍则转成静态图片
        if ( int(sw/sh) > 5 ):
            return staticPhoto.resize1(srcFile,destFile,w,h)

        #要缩略的宽度
        rw = w
        #要缩略的高度
        rh = h

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

        #若源图的宽高比大于目标图的宽高比时,则按照高进行缩放后再裁剪宽度
        if ( sratio > rratio ):
            hscale = float(rh)/float(sh)
            w = int(sw*hscale)
            h = int(sh*hscale)
            #print (sw,sh,w,h,rw,rh,hscale)
            #就高缩放
            imgs.scaleImages("%dx%d"%(w,h))

            #计算裁剪宽的部分的横坐标,超出的宽的部分进行裁剪
            tmpRowsPos = int((sw*hscale - rw)/2)
            #imgs.coalesceImags(Geometry( rw,rh,tmpRowsPos,0 ))
            for i in range( gifFrameLen ):
                tmpImg = imgs.__getitem__(i)
                #print w,h,sw,sh,rw,rh,tmpRowsPos,i,gifFrameLen,tmpImg.columns(),tmpImg.rows()
                #594 260 320 140 132 260 231 0 145 320 140

                if ( sw == tmpImg.columns() and sh == tmpImg.rows() and tmpRowsPos > 0 ):
                    return staticPhoto.resize1(srcFile,destFile,rw,rh)
                tmpImg.crop(Geometry( rw,rh,tmpRowsPos,0 ) )
                tmpImg.profile("*", Blob())
                outImg.append(tmpImg)
            outImg.writeImages(destFile)
            return "True"
        #若源图的宽高比小于目标图的宽高比时,则按照宽进行缩放后再裁剪高度
        else:
            wscale = float(rw)/float(sw)
            w = int(sw*wscale)
            h = int(sh*wscale)
            #print (sw,sh,w,h,rw,rh,wscale)
            #就宽缩放
            imgs.scaleImages("%dx%d"%(w,h))
            tmpColsPos = int((sh*wscale-rh)/2 )

            for i in range(gifFrameLen):
                if ( i == 0 ):
                    tmpImg = gifFrame0
                else:
                    tmpImg = imgs.__getitem__(i)
                if ( sw == tmpImg.columns() and sh == tmpImg.rows() and tmpColsPos > 0 ):
                    return staticPhoto.resize1(srcFile,destFile,rw,rh)
                tmpImg.crop( Geometry( rw,rh,0,tmpColsPos ) )
                tmpImg.profile("*", Blob())
                outImg.append(tmpImg)
            outImg.writeImages(destFile)
            return "True"
        return "True"
Exemple #12
0
from pgmagick import Image, ImageList, Geometry, Color

imgs = ImageList()
for color in ('red', 'blue', 'green', 'black', 'yellow'):
    imgs.append(Image(Geometry(200, 200), Color(color)))
imgs.animationDelayImages(100)
imgs.scaleImages(Geometry(100, 100))
print len(imgs)
imgs.writeImages('output.gif')

imgs = ImageList()
imgs.readImages('output.gif')
for img in imgs:
    print img
Exemple #13
0
#imgFrame0 = Image( srcGifFrame0 )
#imgFrame1 = Image( srcGifFrame1 )
#imgFrame2 = Image( srcGifFrame2 )

#imgFrame2.write('aaaa.gif')
imgs = ImageList()
outImage = ImageList()
#imgs.append(imgFrame0)
#imgs.append(imgFrame1)
#imgs.append(imgFrame2)
#imgs.animationDelayImages(100)
a = ImageType()

imgs.readImages(srcGifFrame0)
imgs.scaleImages("550x550")
img = imgs.__getitem__(0)
print img.columns(), img.rows()

print len(imgs)
#imgs.animationDelayImages(100)
imgs.writeImages('./test.gif')
"""
from pgmagick import Image, ImageList, Geometry, Color



imgs = ImageList()

for color in ('red', 'blue', 'green', 'black', 'yellow'):
Exemple #14
0
#imgFrame0 = Image( srcGifFrame0 )
#imgFrame1 = Image( srcGifFrame1 )
#imgFrame2 = Image( srcGifFrame2 )

#imgFrame2.write('aaaa.gif')
imgs = ImageList(  )
outImage = ImageList()
#imgs.append(imgFrame0)
#imgs.append(imgFrame1)
#imgs.append(imgFrame2)
#imgs.animationDelayImages(100)
a = ImageType()

imgs.readImages(srcGifFrame0)
imgs.scaleImages( "550x550")
img = imgs.__getitem__( 0 )
print img.columns(),img.rows()

print len( imgs )
#imgs.animationDelayImages(100)
imgs.writeImages( './test.gif' )

"""
from pgmagick import Image, ImageList, Geometry, Color



imgs = ImageList()

for color in ('red', 'blue', 'green', 'black', 'yellow'):
 def resize3(srcFile="", destFile="", w=200, h=200, Ignore=False):
     imgs = ImageList()
     imgs.readImages(srcFile)
     imgs.scaleImages("%dx%d>" % (w, h))
     imgs.writeImages(destFile)
     return "True"
Exemple #16
0
from pgmagick import Image, ImageList, Geometry, Color

imgs = ImageList()
for color in ("red", "blue", "green", "black", "yellow"):
    imgs.append(Image(Geometry(200, 200), Color(color)))
imgs.animationDelayImages(100)
imgs.scaleImages(Geometry(100, 100))
print len(imgs)
imgs.writeImages("output.gif")

imgs = ImageList()
imgs.readImages("output.gif")
for img in imgs:
    print img
    def resize6(srcFile="", destFile="", w=200, h=200):
        imgs = ImageList()

        imgs.readImages(srcFile)
        gifFrameLen = len(imgs)

        #若只有一帧直接调用静态方法输出
        if (gifFrameLen == 1):
            return staticPhoto.resize6(srcFile, destFile, w, h)

        outImg = ImageList()

        #取得第0帧
        gifFrame0 = imgs.__getitem__(0)

        #sw源图宽度
        sw = gifFrame0.columns()
        sh = gifFrame0.rows()
        #如果宽高比大小于倍则转成静态图片
        if (int(sw / sh) > 5):
            return staticPhoto.resize1(srcFile, destFile, w, h)

        #要缩略的宽度
        rw = w
        #要缩略的高度
        rh = h

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

        #若源图的宽高比大于目标图的宽高比时,则按照高进行缩放后再裁剪宽度
        if (sratio > rratio):
            hscale = float(rh) / float(sh)
            w = int(sw * hscale)
            h = int(sh * hscale)
            #print (sw,sh,w,h,rw,rh,hscale)
            #就高缩放
            imgs.scaleImages("%dx%d" % (w, h))

            #计算裁剪宽的部分的横坐标,超出的宽的部分进行裁剪
            tmpRowsPos = int((sw * hscale - rw) / 2)
            #imgs.coalesceImags(Geometry( rw,rh,tmpRowsPos,0 ))
            for i in range(gifFrameLen):
                tmpImg = imgs.__getitem__(i)
                #print w,h,sw,sh,rw,rh,tmpRowsPos,i,gifFrameLen,tmpImg.columns(),tmpImg.rows()
                #594 260 320 140 132 260 231 0 145 320 140

                if (sw == tmpImg.columns() and sh == tmpImg.rows()
                        and tmpRowsPos > 0):
                    return staticPhoto.resize1(srcFile, destFile, rw, rh)
                tmpImg.crop(Geometry(rw, rh, tmpRowsPos, 0))
                tmpImg.profile("*", Blob())
                outImg.append(tmpImg)
            outImg.writeImages(destFile)
            return "True"
        #若源图的宽高比小于目标图的宽高比时,则按照宽进行缩放后再裁剪高度
        else:
            wscale = float(rw) / float(sw)
            w = int(sw * wscale)
            h = int(sh * wscale)
            #print (sw,sh,w,h,rw,rh,wscale)
            #就宽缩放
            imgs.scaleImages("%dx%d" % (w, h))
            tmpColsPos = int((sh * wscale - rh) / 2)

            for i in range(gifFrameLen):
                if (i == 0):
                    tmpImg = gifFrame0
                else:
                    tmpImg = imgs.__getitem__(i)
                if (sw == tmpImg.columns() and sh == tmpImg.rows()
                        and tmpColsPos > 0):
                    return staticPhoto.resize1(srcFile, destFile, rw, rh)
                tmpImg.crop(Geometry(rw, rh, 0, tmpColsPos))
                tmpImg.profile("*", Blob())
                outImg.append(tmpImg)
            outImg.writeImages(destFile)
            return "True"
        return "True"