Page MenuHome

Image scale is reset after rendering in background mode
Confirmed, NormalPublic

Description

System Information
Operating system: Windows 10

Blender Version
Broken: 2.91.2

Short description of error

I am starting Blender from command line in background mode (-b) and execute a Python script which does the following:

  • Load an image
  • Scale the image
  • Render with Cycles

After the rendering is done, it is as if the image scaling never happened. The image is back to its original size, and if I save it, it is identical to the original unscaled image.
So it looks like somewhere during bpy.ops.render.render(), the changes to the image are undone.

This only happens when Blender is started in background mode. If started without -b argument, the problem does not occur.

Exact steps for others to reproduce the error

Download this test image:

Run Blender from command line with the following command. Replace path to Blender executable and path to the test.jpg image with the correct paths for your machine, i.e. replace the following strings:

  • "C:\Program Files\Blender Foundation\Blender 2.91\blender.exe"
  • C:\Users\Simon\Downloads\test.jpg
"C:\Program Files\Blender Foundation\Blender 2.91\blender.exe" --factory-startup --addons "io_import_images_as_planes" -b --engine CYCLES --python-expr "import bpy; import bpy_extras; image = bpy_extras.image_utils.load_image(r'C:\Users\Simon\Downloads\test.jpg', check_existing=True, force_reload=False); print('original size:', image.size[:]); image.scale(99, 99); print('before render:', image.size[:]); bpy.ops.render.render(); print('after render:', image.size[:]);"

With -b flag

Blender will print a log like this:

"C:\Program Files\Blender Foundation\Blender 2.91\blender.exe" --factory-startup --addons "io_import_images_as_planes" -b --engine CYCLES --python-expr "import bpy; import bpy_extras; image = bpy_extras.image_utils.load_image(r'C:\Users\Simon\Downloads\test.jpg', check_existing=True, force_reload=False); print('original size:', image.size[:]); image.scale(99, 99); print('before render:', image.size[:]); bpy.ops.render.render(); print('after render:', image.size[:]);"
Blender 2.91.2 (hash 5be9ef417703 built 2021-01-19 16:25:50)
found bundled python: C:\Program Files\Blender Foundation\Blender 2.91\2.91\python
original size: (712, 400)
before render: (99, 99)
Fra:1 Mem:47.08M (Peak 47.15M) | Time:00:00.00 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Synchronizing object | Cube
Fra:1 Mem:47.09M (Peak 47.15M) | Time:00:00.00 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Initializing
Fra:1 Mem:46.97M (Peak 47.15M) | Time:00:00.00 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Waiting for render to start
Fra:1 Mem:47.00M (Peak 47.15M) | Time:00:00.00 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Loading render kernels (may take a few minutes the first time)

[... cut out unimportant output ...]

Fra:1 Mem:49.34M (Peak 50.97M) | Time:00:09.92 | Remaining:00:00.01 | Mem:2.09M, Peak:3.57M | Scene, View Layer | Rendered 505/510 Tiles
Fra:1 Mem:49.23M (Peak 50.97M) | Time:00:09.92 | Remaining:00:00.01 | Mem:1.98M, Peak:3.57M | Scene, View Layer | Rendered 506/510 Tiles
Fra:1 Mem:49.12M (Peak 50.97M) | Time:00:09.93 | Remaining:00:00.00 | Mem:1.87M, Peak:3.57M | Scene, View Layer | Rendered 507/510 Tiles
Fra:1 Mem:49.01M (Peak 50.97M) | Time:00:09.94 | Remaining:00:00.00 | Mem:1.76M, Peak:3.57M | Scene, View Layer | Rendered 508/510 Tiles
Fra:1 Mem:48.90M (Peak 50.97M) | Time:00:09.95 | Remaining:00:00.00 | Mem:1.65M, Peak:3.57M | Scene, View Layer | Rendered 509/510 Tiles, Sample 128/128
Fra:1 Mem:48.78M (Peak 50.97M) | Time:00:09.96 | Mem:1.53M, Peak:3.57M | Scene, View Layer | Rendered 510/510 Tiles
Fra:1 Mem:48.78M (Peak 50.97M) | Time:00:09.96 | Mem:1.53M, Peak:3.57M | Scene, View Layer | Finished
Fra:1 Mem:47.17M (Peak 50.97M) | Time:00:09.96 | Sce: Scene Ve:0 Fa:0 La:0
after render: (712, 400)

Blender quit

You can see that the image is loaded, the original size (712, 400) is printed, then after scaling and before rendering, the correct new size (99, 99) is printed, and then again after rendering, the old and now incorrect size (712, 400) is printed.

Without -b flag

When run without -b flag, we get the following output where Blender behaves correctly:

C:\Users\Simon>"C:\Program Files\Blender Foundation\Blender 2.91\blender.exe" --factory-startup --addons "io_import_images_as_planes" --engine CYCLES --python-expr "import bpy; import bpy_extras; image = bpy_extras.image_utils.load_image(r'C:\Users\Simon\Downloads\test.jpg', check_existing=True, force_reload=False); print('original size:', image.size[:]); image.scale(99, 99); print('before render:', image.size[:]); bpy.ops.render.render(); print('after render:', image.size[:]);"
found bundled python: C:\Program Files\Blender Foundation\Blender 2.91\2.91\python
original size: (712, 400)
before render: (99, 99)
after render: (99, 99)

The script in more legible form

Here's the script that is passed to --python-expr, expanded to be more legible:

import bpy
import bpy_extras

image = bpy_extras.image_utils.load_image(r'C:\Users\Simon\Downloads\test.jpg', check_existing=True, force_reload=False)
print('original size:', image.size[:])

image.scale(99, 99)

print('before render:', image.size[:])
bpy.ops.render.render()
print('after render:', image.size[:])

Event Timeline

Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.Thu, Feb 18, 7:03 PM

Can confirm.