pygobject / pycairo

Python bindings for cairo
https://pycairo.readthedocs.io
Other
622 stars 85 forks source link

Support for write_to_jpg #280

Closed skybber closed 1 year ago

skybber commented 2 years ago

This PR implements write_to_jpg method, I'm not sure if it is suitable for pycairo, since it is not part of cairo interface, but it helps a lot in my project for which the performance of output to image format is cruicial - PNG is too slow.

lazka commented 2 years ago

As you have guessed this is out of scope for pycairo. Adding another dependency makes things more complicated and having a different api than cairo is confusing.

We can look into other ways to improve your use case maybe.

What are your requirements? Lots of images? small, large? in memory, saving to disk? auto-generating on client request?

skybber commented 2 years ago

Interactive charts, PNG is 10x slower:

https://www.czsky.cz/chart?ra=0.1452909172145668&dec=0.08127808535581996&fsz=100&splitview=true

it's running on pycairo+JPG (80-90% quality) now.

lazka commented 1 year ago

Please have a look at https://github.com/pygobject/pycairo/pull/281

In theory it should solve your problem without adding any new APIs, assuming you can use pillow in your project.

Feedback welcome.

lazka commented 1 year ago

This is now live here: https://pycairo.readthedocs.io/en/latest/integration.html#pillow-pil-cairo

skybber commented 1 year ago

Thanks for help! It is working for me.