Resize then save
This is a little script That will allow you to resize the images inside Blender’s Image editor. What’s cool about it, is that you can process then save multiple images very easily.
It’s useful for:
- Generating thumbnails from large images.
- Scaling down images, to be more RAM friendly.
- Deriving multiple resolutions (2K, 1K, …) from a set a images.
How to use it ?
It’s a Python script, so no need to install it, you will just need to open the file « resize_images.py » in the text editor then press the button Run Script.
A new panel will apear in the Image editor > Properties, named Resize.
Active image/All images : choose whether you want to resize the active image only or all the loaded images.
Width : scale the image to this width, the height is calculated automatically while preserving the same aspect ratio.
Overwrite : if checked, the active image (or all the images) will be replaced by the resized image(s), otherwise, new images will be created, and you have the ability to add a prefix to their names.
Save : if checked, the image(s) will be saved to the chosen output directory.
Cleanup : delete the image(s) if saved.
Resize : press this button to execute the chosen operations.
I think That’s all you need to know if you want to use this script
Are you curious how it was made ?
The image scaling is done using a built in function, but it’s not exposed in the UI.
To test it out, load an image in the Image Editor, then in the Python Console, type in:
bpy.data.images['My image.png'].scale(200, 100)
Replace ‘My image.png’ by the name of your image (or use the Autocomplete « Ctrl + Space »).
This Function takes two parameters : the first one is the width (200 in our example), and the second is the height.
To preserve the aspect ratio we can use some simple math to get the formula (presuming That the width is known).
New_height = New_width * Original_height / Original_width
But what if you want to preserve the original image, and create a copy of it with a different resolution ?
In this case we will use another function “copy()”, here is how to use it :
image = bpy.data.images['My image'].copy()
Note That we have assigned the result to a variable “image”, that way we can refer to it easily.
The name of the new image is “My image.001”, let’s change it.
image.name = "Low_res.jpg"
and to scale it:
Now, to save the image we have two options:
image.save(): the image will be saved to its source path, that means replacing the image.
image.save_render(filepath, scene=None): this one will save the image to a specefic path, and you can use a scene render settings.
Example of image.save_render():
import os image.save_render(os.path.join("D:\\My folder", image.name))
Let me know if you have any questions.