3

I am trying to save the content of a GdkPixbuf.Pixbuf object to a file in Python 2.7.

It seems that the Pixbuf.save() method that appears in the documentation is not available from Python, and only Pixbuf.savev() is available.

I have searched high and low for the correct syntax for the method when used in Python, but all available examples use the old syntax:

pixbuf.savev("frame.jpg", "jpg", {"quality":"100"})

Trying this with Gtk3 throws an error such that I need to provide 4 parameters. Supposedly I have to split "quality" and "100" into two parameters. However, doing this throws an error:

pixbuf.savev("frame.jpg", "jpg", "quality", "100")

The Python interpreter replies with:

(GTKSample.py:9906): GdkPixbuf-WARNING **: Unrecognized parameter (q) passed to JPEG saver.
(GTKSample.py:9906): GdkPixbuf-WARNING **: Unrecognized parameter (u) passed to JPEG saver.
(GTKSample.py:9906): GdkPixbuf-WARNING **: Unrecognized parameter (a) passed to JPEG saver.
(GTKSample.py:9906): GdkPixbuf-WARNING **: Unrecognized parameter (l) passed to JPEG saver.
(GTKSample.py:9906): GdkPixbuf-WARNING **: Unrecognized parameter (i) passed to JPEG saver.

Etcetera. I would appreciate if someone would tell me the correct way to save a GdkPixbuf to a file in Python.

1 Answers1

4

By request, I'm posting the answer I found on my own in comments as "the answer".

The correct syntax to save a Gtk3 pixbuf as an image is, for example:

pixbuf.savev("frame.jpg", "jpeg", ["quality"], ["100"])
  • You can also accept your own answer to indicate the correct answer. – Vadim Oct 24 '15 at 17:00
  • Hi, I had walked around the internet, the docs and stackoverflow, but none of them talk about where the pixbuf.savev() saves the image by default. I was looking around my system and I did not find the name that I specified in that function. The log also doesn't indicate any errors. – fsevenm Jul 08 '20 at 04:01
  • @fsevenm, If you don't specify an absolute path ("frame.jpg"), then the image is saved relative to the directory from where you execute. In case of "../frame.jpg", the image would be saved one directory below (relative). – jcoppens Nov 05 '21 at 13:51