コード例 #1
0
ファイル: pdfutils.py プロジェクト: aminba90/PythonCourse
def makeA85Image(filename, IMG=None, detectJpeg=False):
    import zlib
    img = ImageReader(filename)
    if IMG is not None:
        IMG.append(img)
        if detectJpeg and img.jpeg_fh():
            return None

    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 makeA85Image(filename,IMG=None, detectJpeg=False):
    import zlib
    img = ImageReader(filename)
    if IMG is not None:
        IMG.append(img)
        if detectJpeg and img.jpeg_fh():
            return None

    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
コード例 #3
0
    def PIL_imagedata(self):
        image = self.image
        if image.format == 'JPEG':
            fp = image.fp
            fp.seek(0)
            return self._jpg_imagedata(fp)
        self.source = 'PIL'
        zlib = import_zlib()
        if not zlib: return

        bpc = 8
        # Use the colorSpace in the image
        if image.mode == 'CMYK':
            myimage = image
            colorSpace = 'DeviceCMYK'
            bpp = 4
        elif image.mode == '1':
            myimage = image
            colorSpace = 'DeviceGray'
            bpp = 1
            bpc = 1
        elif image.mode == 'L':
            myimage = image
            colorSpace = 'DeviceGray'
            bpp = 1
        else:
            myimage = image.convert('RGB')
            colorSpace = 'RGB'
            bpp = 3
        imgwidth, imgheight = myimage.size

        # this describes what is in the image itself
        # *NB* according to the spec you can only use the short form in inline images
        imagedata = [
            'BI /W %d /H %d /BPC %d /CS /%s /F [%s/Fl] ID' %
            (imgwidth, imgheight, bpc, colorSpace, rl_config.useA85 and '/A85 '
             or '')
        ]

        #use a flate filter and, optionally, Ascii Base 85 to compress
        raw = (myimage.tobytes
               if hasattr(myimage, 'tobytes') else myimage.tostring)()
        rowstride = (imgwidth * bpc * bpp + 7) >> 3
        assert len(
            raw) == rowstride * imgheight, "Wrong amount of data for image"
        data = zlib.compress(raw)  #this bit is very fast...
        if rl_config.useA85:
            data = asciiBase85Encode(data)  #...sadly this may not be
        #append in blocks of 60 characters
        pdfutils._chunker(data, imagedata)
        imagedata.append('EI')
        return (imagedata, imgwidth, imgheight)
コード例 #4
0
ファイル: pdfimages.py プロジェクト: FatihZor/infernal-twin
    def PIL_imagedata(self):
        image = self.image
        if image.format == "JPEG":
            fp = image.fp
            fp.seek(0)
            return self._jpg_imagedata(fp)
        self.source = "PIL"
        zlib = import_zlib()
        if not zlib:
            return

        bpc = 8
        # Use the colorSpace in the image
        if image.mode == "CMYK":
            myimage = image
            colorSpace = "DeviceCMYK"
            bpp = 4
        elif image.mode == "1":
            myimage = image
            colorSpace = "DeviceGray"
            bpp = 1
            bpc = 1
        elif image.mode == "L":
            myimage = image
            colorSpace = "DeviceGray"
            bpp = 1
        else:
            myimage = image.convert("RGB")
            colorSpace = "RGB"
            bpp = 3
        imgwidth, imgheight = myimage.size

        # this describes what is in the image itself
        # *NB* according to the spec you can only use the short form in inline images
        imagedata = [
            "BI /W %d /H %d /BPC %d /CS /%s /F [%s/Fl] ID"
            % (imgwidth, imgheight, bpc, colorSpace, rl_config.useA85 and "/A85 " or "")
        ]

        # use a flate filter and, optionally, Ascii Base 85 to compress
        raw = (myimage.tobytes if hasattr(myimage, "tobytes") else myimage.tostring)()
        rowstride = (imgwidth * bpc * bpp + 7) >> 3
        assert len(raw) == rowstride * imgheight, "Wrong amount of data for image"
        data = zlib.compress(raw)  # this bit is very fast...
        if rl_config.useA85:
            data = asciiBase85Encode(data)  # ...sadly this may not be
        # append in blocks of 60 characters
        pdfutils._chunker(data, imagedata)
        imagedata.append("EI")
        return (imagedata, imgwidth, imgheight)
コード例 #5
0
ファイル: pdfimages.py プロジェクト: CometHale/lphw
    def PIL_imagedata(self):
        image = self.image
        if image.format=='JPEG':
            fp=image.fp
            fp.seek(0)
            return self._jpg_imagedata(fp)
        self.source = 'PIL'
        zlib = import_zlib()
        if not zlib: return

        bpc = 8
        # Use the colorSpace in the image
        if image.mode == 'CMYK':
            myimage = image
            colorSpace = 'DeviceCMYK'
            bpp = 4
        elif image.mode == '1':
            myimage = image
            colorSpace = 'DeviceGray'
            bpp = 1
            bpc = 1
        elif image.mode == 'L':
            myimage = image
            colorSpace = 'DeviceGray'
            bpp = 1
        else:
            myimage = image.convert('RGB')
            colorSpace = 'RGB'
            bpp = 3
        imgwidth, imgheight = myimage.size

        # this describes what is in the image itself
        # *NB* according to the spec you can only use the short form in inline images
        imagedata=['BI /W %d /H %d /BPC %d /CS /%s /F [%s/Fl] ID' % (imgwidth, imgheight, bpc, colorSpace, rl_config.useA85 and '/A85 ' or '')]

        #use a flate filter and, optionally, Ascii Base 85 to compress
        raw = myimage.tostring()
        rowstride = (imgwidth*bpc*bpp+7)/8
        assert len(raw) == rowstride*imgheight, "Wrong amount of data for image"
        data = zlib.compress(raw)    #this bit is very fast...
        if rl_config.useA85:
            data = asciiBase85Encode(data) #...sadly this may not be
        #append in blocks of 60 characters
        pdfutils._chunker(data,imagedata)
        imagedata.append('EI')
        return (imagedata, imgwidth, imgheight)
コード例 #6
0
ファイル: pdfimages.py プロジェクト: glosoftgroup/odoo-sample
 def _jpg_imagedata(self,imageFile):
     info = pdfutils.readJPEGInfo(imageFile)
     self.source = 'JPEG'
     imgwidth, imgheight = info[0], info[1]
     if info[2] == 1:
         colorSpace = 'DeviceGray'
     elif info[2] == 3:
         colorSpace = 'DeviceRGB'
     else: #maybe should generate an error, is this right for CMYK?
         colorSpace = 'DeviceCMYK'
     imageFile.seek(0) #reset file pointer
     imagedata = []
     #imagedata.append('BI /Width %d /Height /BitsPerComponent 8 /ColorSpace /%s /Filter [/Filter [ /ASCII85Decode /DCTDecode] ID' % (info[0], info[1], colorSpace))
     imagedata.append('BI /W %d /H %d /BPC 8 /CS /%s /F [%s/DCT] ID' % (imgwidth, imgheight, colorSpace, rl_config.useA85 and '/A85 ' or ''))
     #write in blocks of (??) 60 characters per line to a list
     data = imageFile.read()
     if rl_config.useA85:
         data = asciiBase85Encode(data)
     pdfutils._chunker(data,imagedata)
     imagedata.append('EI')
     return (imagedata, imgwidth, imgheight)
コード例 #7
0
ファイル: pdfutils.py プロジェクト: aminba90/PythonCourse
 def encrypt(self, s):
     return self.__rotate(
         asciiBase85Encode(''.join(map(chr, self.__fusc(list(map(ord,
                                                                 s)))))),
         self._n)
コード例 #8
0
ファイル: pdfutils.py プロジェクト: Aeium/dotStudio
 def encrypt(self,s):
     return self.__rotate(asciiBase85Encode(''.join(map(chr,self.__fusc(list(map(ord,s)))))),self._n)