I know this can be done with matplotlib or PIL, but I need it to be done in blender, without installing any other package.

I searched and tried following code in blender, but only get a black image as output.

import bpy
import numpy as np

image_path = "src.jpg"
output_image_path = "output.jpg"
output_image_name = "output.jpg"

image = bpy.data.images.load(image_path)
np_array = np.asarray(image.pixels)

# create output image
output_image = bpy.data.images.new(output_image_name, width=image.size[0], height=image.size[1])
output_image.file_format = 'JPEG'
output_image.filepath = output_image_path

# convert np array back to image
output_image.pixels = np_array.ravel()


So, how to make this work? Thanks.

  • $\begingroup$ Hi! I tried the same above and it worked without any problems... Maybe check your paths and filenames carefully, make sure you are looking at the right output file ? $\endgroup$
    – ydvisual
    Feb 19, 2022 at 4:28

1 Answer 1


Well, After I re-open my blender and change source image to another path, everything works. No change on the code.

So I leave this question here for anyone who need this code.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .