add Python .write_to_buffer()

now we need to be able to get the bytes from a VipsBlob
This commit is contained in:
John Cupitt 2014-09-01 17:44:33 +01:00
parent 804a2e6fca
commit 6779e141a7
3 changed files with 28 additions and 0 deletions

3
TODO
View File

@ -1,6 +1,9 @@
- python: - python:
- try6 produces a VipsBlob object ... need to turn this into a Python
buffer, or whatever they are called now
- add more constructors - add more constructors
- need more writers - need more writers

13
python/try6.py Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/python
import sys
import logging
logging.basicConfig(level = logging.DEBUG)
from gi.repository import Vips
from vips8 import vips
a = Vips.Image.new_from_file(sys.argv[1])
a.write_to_buffer(".jpg")

View File

@ -207,6 +207,16 @@ def vips_image_write_to_file(self, vips_filename, **kwargs):
_call_base(saver, [filename], kwargs, self, option_string) _call_base(saver, [filename], kwargs, self, option_string)
def vips_image_write_to_buffer(self, vips_filename, **kwargs):
filename = Vips.filename_get_filename(vips_filename)
option_string = Vips.filename_get_options(vips_filename)
saver = Vips.Foreign.find_save_buffer(filename)
if saver == None:
raise Error('No known saver for "%s".' % filename)
logging.debug('Image.write_to_buffer: saver = %s' % saver)
return _call_base(saver, [], kwargs, self, option_string)
# apply a function to a thing, or map over a list # apply a function to a thing, or map over a list
# we often need to do something like (1.0 / other) and need to work for lists # we often need to do something like (1.0 / other) and need to work for lists
# as well as scalars # as well as scalars
@ -319,6 +329,8 @@ setattr(Vips.Image, 'new_from_file', classmethod(vips_image_new_from_file))
# instance methods # instance methods
Vips.Image.write_to_file = vips_image_write_to_file Vips.Image.write_to_file = vips_image_write_to_file
Vips.Image.write_to_buffer = vips_image_write_to_buffer
Vips.Image.__getattr__ = vips_image_getattr Vips.Image.__getattr__ = vips_image_getattr
Vips.Image.__add__ = vips_add Vips.Image.__add__ = vips_add
Vips.Image.__radd__ = vips_add Vips.Image.__radd__ = vips_add