コード例 #1
0
def makeA85Image(filename, IMG=None):
    import zlib
    img = ImageReader(filename)
    if IMG is not None: IMG.append(img)

    imgwidth, imgheight = img.getSize()
    raw = img.getRGBData()

    code = []
    append = code.append
    # this describes what is in the image itself
    append('BI')
    append('/W %s /H %s /BPC 8 /CS /%s /F [/A85 /Fl]' %
           (imgwidth, imgheight, _mode2cs[img.mode]))
    append('ID')
    #use a flate filter and Ascii Base 85
    assert len(raw) == imgwidth * imgheight * _mode2bpp[
        img.mode], "Wrong amount of data for image"
    compressed = zlib.compress(raw)  #this bit is very fast...
    encoded = _AsciiBase85Encode(compressed)  #...sadly this may not be

    #append in blocks of 60 characters
    _chunker(encoded, code)

    append('EI')
    return code
コード例 #2
0
def cacheImageFile(filename, returnInMemory=0, IMG=None):
    "Processes image as if for encoding, saves to a file with .a85 extension."

    from reportlab.lib.utils import PIL_Image, open_for_read
    import zlib

    cachedname = os.path.splitext(filename)[0] + '.a85'
    if filename==cachedname:
        if cachedImageExists(filename):
            if returnInMemory: return split(open_for_read(cachedname).read(),LINEEND)[:-1]
        else:
            raise IOError, 'No such cached image %s' % filename
    else:
        img1 = PIL_Image.open(open_for_read(filename))
        img = img1.convert('RGB')
        if IMG is not None: IMG.append(img)
        imgwidth, imgheight = img.size
        code = []
        code.append('BI')   # begin image
        # this describes what is in the image itself
        code.append('/W %s /H %s /BPC 8 /CS /RGB /F [/A85 /Fl]' % (imgwidth, imgheight))
        code.append('ID')
        #use a flate filter and Ascii Base 85
        raw = img.tostring()
        assert(len(raw) == imgwidth * imgheight, "Wrong amount of data for image")
        compressed = zlib.compress(raw)   #this bit is very fast...
        encoded = _AsciiBase85Encode(compressed) #...sadly this isn't

        #write in blocks of 60 characters per line
        outstream = getStringIO(encoded)
        dataline = outstream.read(60)
        while dataline <> "":
            code.append(dataline)
            dataline = outstream.read(60)

        code.append('EI')
        if returnInMemory: return code

        #save it to a file
        f = open(cachedname,'wb')
        f.write(join(code, LINEEND)+LINEEND)
        f.close()
        if rl_config.verbose:
            print 'cached image as %s' % cachedname
コード例 #3
0
ファイル: pdfutils.py プロジェクト: tschalch/pyTray
def cacheImageFile(filename, returnInMemory=0, IMG=None):
    "Processes image as if for encoding, saves to a file with .a85 extension."

    from reportlab.lib.utils import open_for_read
    import zlib

    cachedname = os.path.splitext(filename)[0] + '.a85'
    if filename==cachedname:
        if cachedImageExists(filename):
            if returnInMemory: return split(open_for_read(cachedname).read(),LINEEND)[:-1]
        else:
            raise IOError, 'No such cached image %s' % filename
    else:
        img = ImageReader(filename)
        if IMG is not None: IMG.append(img)

        imgwidth, imgheight = img.getSize()
        raw = img.getRGBData()

        code = []
        # this describes what is in the image itself
        code.append('BI')
        code.append('/W %s /H %s /BPC 8 /CS /RGB /F [/A85 /Fl]' % (imgwidth, imgheight))
        code.append('ID')
        #use a flate filter and Ascii Base 85
        assert(len(raw) == imgwidth * imgheight, "Wrong amount of data for image")
        compressed = zlib.compress(raw)   #this bit is very fast...
        encoded = _AsciiBase85Encode(compressed) #...sadly this may not be

        #append in blocks of 60 characters
        _chunker(encoded,code)

        code.append('EI')
        if returnInMemory: return code

        #save it to a file
        f = open(cachedname,'wb')
        f.write(join(code, LINEEND)+LINEEND)
        f.close()
        if rl_config.verbose:
            print 'cached image as %s' % cachedname
コード例 #4
0
ファイル: pdfutils.py プロジェクト: 7o9/stdm-plugin
def makeA85Image(filename,IMG=None):
    import zlib
    img = ImageReader(filename)
    if IMG is not None: IMG.append(img)

    imgwidth, imgheight = img.getSize()
    raw = img.getRGBData()

    code = []
    append = code.append
    # this describes what is in the image itself
    append('BI')
    append('/W %s /H %s /BPC 8 /CS /%s /F [/A85 /Fl]' % (imgwidth, imgheight,_mode2cs[img.mode]))
    append('ID')
    #use a flate filter and Ascii Base 85
    assert len(raw) == imgwidth * imgheight*_mode2bpp[img.mode], "Wrong amount of data for image"
    compressed = zlib.compress(raw)   #this bit is very fast...
    encoded = _AsciiBase85Encode(compressed) #...sadly this may not be

    #append in blocks of 60 characters
    _chunker(encoded,code)

    append('EI')
    return code
コード例 #5
0
ファイル: pdfutils.py プロジェクト: 7o9/stdm-plugin
 def encrypt(self,s):
     return self.__rotate(_AsciiBase85Encode(''.join(map(chr,self.__fusc(map(ord,s))))),self._n)
コード例 #6
0
ファイル: pdfutils.py プロジェクト: OYZQ/odoo_qingjia
 def encrypt(self,s):
     return self.__rotate(_AsciiBase85Encode(''.join(map(chr,self.__fusc(map(ord,s))))),self._n)
コード例 #7
0
ファイル: test_rl_accel.py プロジェクト: boughattas50/M2M
 def test_AsciiBase85Encode(self):
     from _rl_accel import _AsciiBase85Encode
     assert _AsciiBase85Encode('Dragan Andric') == '6ul^K@;[2RDIdd%@f~>'
コード例 #8
0
ファイル: test_rl_accel.py プロジェクト: Jbaumotte/web2py
 def test_AsciiBase85Encode(self):
     from _rl_accel import _AsciiBase85Encode
     assert _AsciiBase85Encode('Dragan Andric')=='6ul^K@;[2RDIdd%@f~>'