import Blender
from Blender import *
from Blender import Image as BImage
import os
		
# Change to the directory where the .blend is located
os.chdir(Blender.sys.expandpath('//'))
	
scn = Blender.Scene.GetCurrent()

# Name of the image to load
imagename = 'Whatever.jpg'

objctname = 'Plane'	

# Create a plane for the material, of size 1.0
me = Blender.Mesh.Primitives.Plane(1.0)
ob = scn.objects.new(me,objctname)
		
matname = 'Thing'

# Create the material
mat=Blender.Material.New(matname)

# Set colours, make it shadeless and enable transparency			
mat.rgbCol = 1.0,1.0,1.0
mat.mode |= Material.Modes.SHADELESS
mat.mode |= Material.Modes.ZTRANSP
# Make it be semi-transparent
mat.alpha = 0.5

	
# Create an image texture. Load the specified image file.
tex=Texture.New(matname)
tex.setType('Image')
tex.setImageFlags()
img=BImage.Load(imagename)
tex.image = img

# Make the texture affect colour and transparency. Use texture slot 0.
mat.setTexture(0,tex, Texture.TexCo["ORCO"], Texture.MapTo["COL"] | Texture.MapTo["ALPHA"])

# Get the texture and set it to mix with the material settings		
textures = mat.getTextures()
mtex = textures[0]
mtex.blendmode = Texture.BlendModes.MIX


# Enable the texture
mat.enabledTextures = [0]

# Assogm the material to the mesh
me = Blender.Mesh.Get(ob.data.name)
me.materials = [mat]

Blender.Redraw()
		