copy image script

when editing images in blender, I often miss the posibility to duplicate an image.
here you go - very simple. It duplicates the image which is assigned to the selected mesh.

#!BPY

""" Registration info for Blender menus
Name: 'copy image'
Blender: 243
Group: 'Misc'
Tip: 'copy image'
"""

import Blender as B
from Blender import Window,Image, Object, Scene, Material,Texture,Draw,Mathutils,Mesh
from Blender.Draw import *
from Blender.Mathutils import *

scn= B.Scene.GetCurrent()
scn_objects = scn.objects
ob= scn_objects.active
mesh=ob.getData()


origimage=mesh.faces[0].image
width,height=origimage.getMaxXY()

newimage=B.Image.New(origimage.name+'_copy',width,height,32)
    
    
for x in range(0,width):
    for y in range(0,height):
        newp=origimage.getPixelF(x,y)
        newimage.setPixelF(x,y,newp)


Why not simply use something like the code below, instead of copying the image pixel per pixel, which can take some time (I just know that with PIL it does…):

if os.name=='nt': os.sys('copy <i>[OrigImagePath] [DestImagePath]</i>')
elif os.name=='posix':os.sys('cp <i>[OrigImagePath] [DestImagePath]</i>')

You’ll just need to import os, which is now -I believe- in the built-in Blender’s Python

N.tox - this is per pixel, but still takes just 2 seconds or so(on my machine and with 1024x image). And I did it for work with images inside blender - I make a project, paint textures, then want to make another variation of the same object, so duplicate it, and if I would want to use your method, I’d have to unpack the image to disk, copy there and then load it back to blender. It really would be better performancewise, I definitely get your point. It’s more a quickie for somebody who does this stuff inside blender…

Hmmmm ok… I see… interesting informations,thanks :slight_smile: