Esempio n. 1
0
def test_constructor_with_file():
    w = Image(StringIO(GIF))
    assert 'GIF' == w.format
    assert (1,1) == w.size
    size = api.size_t()
    b = api.MagickGetImageBlob(w._wand, size)
    assert GIF == ''.join([chr(b[i]) for i in range(0, size.value + 1)])
Esempio n. 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 = 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))
Esempio n. 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 = 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
Esempio n. 4
0
def test_constructor_with_eps_file():
    w = Image(StringIO(EPS))
    assert 'EPS' == w.format
    size = api.size_t()
    b = api.MagickGetImageBlob(w._wand, size)
    assert EPS == ''.join([chr(b[i]) for i in range(0, size.value + 1)])