Example #1
0
 def save( self, file = None ):
     ''' Saves the image to a file.  If no file is specified, the file is
         saved with the original filename.'''
     if hasattr( file, 'write' ):
         size = size_t()
         b = api.MagickGetImageBlob( self._wand, size )
         try:
             file.write( ''.join( [chr( b[i] ) for i in range( 0, size.value + 1 )] ) )
         finally:
             api.MagickRelinquishMemory( b )
     else:
         self._check_wand_error( api.MagickWriteImage( self._wand, file ) )
Example #2
0
 def save(self, file=None):
     ''' Saves the image to a file.  If no file is specified, the file is
         saved with the original filename.'''
     if hasattr(file, 'write'):
         size = size_t()
         b = api.MagickGetImageBlob(self._wand, size)
         try:
             file.write(''.join(
                 [chr(b[i]) for i in range(0, size.value + 1)]))
         finally:
             api.MagickRelinquishMemory(b)
     else:
         self._check_wand_error(api.MagickWriteImage(self._wand, file))
Example #3
0
    def dump( self, type = None ):
        ''' Save the image to a buffer, if no type is specified, original type is used.
            returns image'''
        if type:
            api.MagickSetFilename( self._wand, 'buffer.%s' % type )  # hint image type

        result = ''
        size = size_t()
        b = api.MagickGetImageBlob( self._wand, size )
        try:
            result = ''.join( [chr( b[i] ) for i in range( 0, size.value + 1 )] )
        finally:
            api.MagickRelinquishMemory( b )

        return result
Example #4
0
    def dump(self, type=None):
        ''' Save the image to a buffer, if no type is specified, original type is used.
            returns image'''
        if type:
            api.MagickSetFilename(self._wand,
                                  'buffer.%s' % type)  # hint image type

        result = ''
        size = size_t()
        b = api.MagickGetImageBlob(self._wand, size)
        try:
            result = ''.join([chr(b[i]) for i in range(0, size.value + 1)])
        finally:
            api.MagickRelinquishMemory(b)

        return result