Пример #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 = api.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))
Пример #2
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 = api.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
Пример #3
0
 def tostring(self):
     size = api.size_t()
     return api.MagickGetImageBlob(self._wand, size)