# How to merge images into a single strip

I would like to merge a few images into a single strip with the images next to each other. Using compositor didn't work out as I expected. Thinking a bit more about it, I would prefer not to use compositor.

And use python for this now I am wondering if the python part of blender could join images like that. Blender is not PIL, so I'm not sure if this is possible. The strip can be either horizontal or vertical.

* UPDATE * My alternative option, is to break open the pgn or jpg codec, read images as RGB data, and output a final RGB string basedupon multiple images. while possible i wonder if there are easier methods using Blender python API, can blender python do memory based like image manipulation, like addressing pixels directly to set their values ?

• so what's "PIL"? – cegaton Dec 13 '14 at 0:08
• I understand what you wish to accomplish, but to be able to provide an answer I need to know the greater context and workflow. Where do the images come from, and what are you wanting as the larger final result of the process of which this is one of the steps? – brasshat Dec 13 '14 at 3:59
• @cegaton, I bet he's referring to the Python Imaging Library: pythonware.com/products/pil – ajwood Dec 14 '14 at 14:50
• Yup, Pil stands for Pytohn Image Library, as library full of functions for creating and manipulating images. – user613326 Dec 14 '14 at 19:56
• Oh I see now, you want to do automation of this with python, Ill update my answer in the morning with some python coding.. – Jaroslav Jerryno Novotny Dec 14 '14 at 21:11

Using the Import Images as Planes addon you can import several images and align them.

Select the images, set the offset value and materials for the plane.

Blender will then create an plane for each image and line them up on the x axis.

To line up the planes in a different axis there is a modified script that you can find here

The blenderartists.or thread for this script is here

Then just set up an orthographic camera to frame your images and set your render size to your needs.

• I know this method, While indeed this does show an image strip, its not realy handy in terms of making the final image, in the way i like to include it in python script. – user613326 Dec 14 '14 at 19:57

You can create an empty texture of size of the resulting image strip and alpha over all of your images over it in compositor and translate them with translate node into positions and render it:

With python:

• load in you image textures:

import bpy

try:
except:
raise NameError("Cannot load image %s" % filepath)

image_names = ['first.png', 'second.jpg', 'third.bmp']
images = []
for name in image_names:
real_path = bpy.abspath('//' + name)

• Get image dimension:

images[0].size[0]    # resolution x
images[0].size[1]    # resolution y

• Create empty image of desired resolution for example 1024x256:

bg = bpy.ops.image.new(name="bg", width=1024, height=256, alpha=False)

• How to create nodes in compositor and link them:

Controling compositor by python

• Render:

render = bpy.context.scene.render
# set this
render.resolution_x = 1024
render.resolution_y = 256
# render image
render.render()
# use File_Output node or specify render.filepath to also save the result


Getting low level with manipulating image pixels:

# you get float values for each pixel like this:
# in png they are stored nicely in rgba order
image = bpy.data.images['SOME_NAME.PNG']
for i in range(0, len(image.pixels), 4):
rgba = image.pixels[i:i+4]
# this is also writable ofc


There are couple things to keep in mind though:

• Blender uses opengl internally so the origin is in the lower left corner of the image (with the y-axis pointing upwards).
• Some image programs might not save the transparency pixels
• The image might have alpha premultiplied, but this shouldn't be a concern. In that case the values are in form of [r * a, g * a, b * a, a]
• i understand this workflow, but it seams a bit how to say complex road, for just image manipulation, doesnt blender have some api for some straight image manipulation ? (as i prefer not to change composer setups) – user613326 Dec 15 '14 at 14:31
• Ok I added some image pixel manipulation – Jaroslav Jerryno Novotny Dec 15 '14 at 16:19
• yes i think something along that way. for exampl img1 [r,g,b,a] + img2 [r,g,b,a] = new[r,g,b,a] thinking about it, numpy is part of blender ? numpy should be ablee to do this – user613326 Dec 16 '14 at 14:32
• Yes numpy module is shipped with blender. from numpy import * will work – Jaroslav Jerryno Novotny Dec 16 '14 at 14:38
• I had no idea numpy was in Blender. There are actually questions on this site of people asking how to install it. I'll try using numpy for image manipulation, because it should be possible, and it should be much much much faster. – Chris Conlan Nov 15 '18 at 21:19