# How to get the truly width and height of frame when rendering? (It would be good if I can render without saving images)

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

# 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

# Render and save image
bpy.ops.render.render()

# get width and height
width_of_render = bpy.data.images['Viewer Node'].size[0]
height_of_render = bpy.data.images['Viewer Node'].size[1]
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[0] and bpy.data.images['Viewer Node'].size[1] 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)

You can get the Python expressions needed by enabling Python Tooltips in the User Preferences, "Interface" tab. Then you can just hover over the resolution settings in the render panel, and see you can use bpy.data.scene["Scene"].render.resolution_x. It's better, though, to use the currently active scene, rather than hard-coding the scene name. Also you'll want to multiply with the resolution scale percentage. This leads you to:
render = bpy.context.scene.render