4
$\begingroup$

I'm writing an addon and I want to save two sizes of every rendered image. One is the original size which blender saves anyway. The other one is a scaled down version of that image.

How do I scale an image with the Python API (possibly with a specific interpolation filter like linear, cubic, ...)?

$\endgroup$
3
$\begingroup$

You can use the Python Image Library (PIL) for instance, there's a Python 3k port:
https://github.com/gpolo/pil-py3k and https://github.com/sloonz/pil-py3k

or Pillow, which is also a PIL fork:
https://pypi.python.org/pypi/Pillow/2.2.1

Example code (for original PIL though):
http://www.daniweb.com/software-development/python/code/216637/resize-an-image-python

As PIL supported differnt interpolation techniques, all of the above should offer the same (or more).

You could also try without any extra modules, by saving the image in blender to another file using Image.save_render(). Note that this method can be used on any image, it doesn't save the rendered image only (render stands for render settings, the render settings of the given scene will be used to save the file. It ignores the resolution settings however. To change scale, you needed to import the saved image again (so that .pixels isn't empty, which is the case for render results), then call Image.scale() and save again. But you can't specify an interpolation mode.

| improve this answer | |
$\endgroup$
0
$\begingroup$

One could also create a "File Output" node preceeded by a "Scale" node using scripting. This doesn't provide filter options either, though.

Of course this only works with nodes postprocessing turned on.

Blender Wiki Cookbook example

| improve this answer | |
$\endgroup$

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.