Save render to multiple resolutions / resize [Rhino Python]

Hi,

I am writing a Plug-in in Rhino Python. One of the functionalities is to trigger the rendering process and then save and close the render window. Now, I would like to save the rendered image at two resolutions:

- Full-res
- Resized to the web-acceptable size

Ideally, I would use PIL (pillow) module from Python to resize the image, but that’s not available in IronPython. I didn’t find anything useful in System. Drawing either. It is important, that the solution can be integrated into the plug-in to later be compiled into the .yak package.

The current code just uses the last RenderSettings and gets the image out.

    def render_viewport(render_path):
        Rhino.RhinoApp.RunScript("_Render",False)
        Rhino.RhinoApp.RunScript("_-SaveRenderWindowAs " + '"' + render_path + '"', True)
        Rhino.RhinoApp.RunScript("_-CloseRenderWindow ",True)

Does anyone have any idea?

Best,
WK

Hi @wojtek.karnowka,

below is a quick example which prompts for an image file in png, tif, bmp or jpg format and then saves a downscaled jpg from it in the same folder of the original file. The new file is saved with a suffix to the file name, you might adjust the suffix “web” and scale factor (0.25) from the calling function.

SaveDownscaledImageAsJpg.py (2.1 KB)

To use it in your code, just call the function with your render_path variable like this:

SaveDownscaledImageAsJpg(render_path, 0.25, "web")

_
c.

2 Likes

Awesome! Thank you!