I would like to know the width and height of frame when rendering.
And I found that someone has ask the familiar question, "How to access Render Result pixels from python script? "(see here)
So, I added some codes in the codes answered by wsfax (see original codes) , like this script(*).
import bpy path_name = '' file_name = 'test_2017' file_path_name = path_name + file_name + '.blend' bpy.ops.wm.open_mainfile(filepath = file_path_name) # switch on nodes bpy.context.scene.use_nodes = True tree = bpy.context.scene.node_tree links = tree.links # clear default nodes for n in tree.nodes: tree.nodes.remove(n) # create input render layer node rl = tree.nodes.new('CompositorNodeRLayers') rl.location = 185,285 # create output node v = tree.nodes.new('CompositorNodeViewer') v.location = 750,210 v.use_alpha = False # Links links.new(rl.outputs, v.inputs) # link Image output to Viewer input # Render and save image bpy.ops.render.render() # get width and height width_of_render = bpy.data.images['Viewer Node'].size height_of_render = bpy.data.images['Viewer Node'].size print("width: ", width_of_render, "height: ", height_of_render) # get viewer pixels pixels = bpy.data.images['Viewer Node'].pixels print(len(pixels)) # size is always width * height * 4 (rgba)
What I mainly did is using
bpy.data.images['Viewer Node'].size and
bpy.data.images['Viewer Node'].size to get the width and height.
I tested a simple blender file (test_2017.blend) only containing a cube and executed it in command line, and got 262144(pixels), width = 256(pixels), and height = 256(pixels) in command line.
However, When I opened blender file (test_2017.blend) and executed script(*)(without line 3 to line 6) in blender, I got 2073600(pixels), width = 960(pixels), and height = 540(pixels) in console window.
I have no idea why they are different?
And then I saved image when rendering, the width and the height of the image were 960(pixels) and 540(pixels).
How can I get the truly width and height? (It would be good if I can render without saving images)