2

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.

4
  • The correct answer was: pixbuf.savev("frame.jpg", "jpg", ["quality"], ["100"]) Feb 2 '15 at 4:56
  • Post your own comment as the answer, and accept it, because it works and very useful! Don't forget to let me know in the comments when you do, and I will upvote it.
    – Vadim
    Oct 23 '15 at 23:45
  • The only problem I had was that you use "jpeg" not "jpg" as the type. It accepts "png" or "jpeg".
    – Vadim
    Oct 23 '15 at 23:45
  • Thanks, I posted this as the answer. Oct 24 '15 at 8:18
3

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"])
3
  • 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 8 '20 at 4: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 5 '21 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.