I'm currently writing a script to map an image onto a mug for mock-up purposes.
The whole idea is to take away dependence on Photoshop so we can bulk automate this process. However, due to the shape of a mug, the images have to be warped to look correct.
I had a quick look online, and I found this article on the subject, and it really isn't too learner-friendly. I've gotten all the co-ordinates I think I need for this to work, I'm just not too sure on how to input the data.
I laid out my code in this way to make it easier for me to access (in my mind at least) and modify on a whim. However, I can't seem to work out how to actually use the Shepards Distortion via ImageMagick. I've tried to import a short list of ImageMagick and MagickWand variants, but they all return "ImportError: No Module named x", which is the first problem. Once I get past that point, I'm not even sure that the code I have will actually work. If anyone can point me in the right direction, I would really really appreciate it.
MUG_SIDE = [[428,615,1221,1609],[".../mug-side.png"],[[0,0,499,44],[2100,0,2098,390],[4200,0,3784,175],[0,4800,606,3911],[2100,4800,2112,4347],[4200,4800,3720,4095]]]
MUG_FRONT = [[574,397,1557,1518],[".../mug-front.png"],[[0,0,37,62],[4200,0,3642,28],[0,4800,30,4744],[4200,4800,3670,4686]]]
MUG_MAIN = [[968,1052,968,1716],[".../mug-main.png"],[[0,0,360,774],[4200,0,2720,0],[0,4800,605,4539],[4200,4800,2860,3494]]]
MUGS = [MUG_SIDE,MUG_FRONT,MUG_MAIN]
i = 0
for item in MUGS:
coor = []
for coor_set in item[2]:
for item in coor_set:
coor += item
print coor
file = cStringIO.StringIO(urllib.urlopen(item[1]).read())
mug_overlay = Image.open(item[1]).convert("RGBA")
canvas = Image.new('RGB', (2000,2000), (255,255,255))
ShepardsDistortion = DistortImageMethod(14)
MagickWandGenesis()
wand = NewMagickWand()
MagickReadImage(wand,file)
MagickDistortImage(wand,ShepardsDistortion, len(coor), coor, False)
#RESIZE IMAGE HERE, PRE-SAVING
MagickWriteImage(wand,location+"mug_warp_temp.png")
design_warped = Image.open(location+"mug_warp_temp.png").convert("RGBA")
width = item[0][2] - item[0][0]
height = item[0][3] - item[0][1]
design_warped = design_warped.resize( (width,height), Image.ANTIALIAS)
#replace later
canvas.paste(design_warped, (item[0][0],item[0][1]), mask=design_warped)
canvas.paste(mug_overlay, mask=mug_overlay)
if item[1][-8:] == "main.png":
print "paste corner art"
canvas.save(location+"mugtest_"+i+".png")
i=i+1
Needless to say, if there's an easier way to bend an image around a cylinder via a Python script, that would be cool too. :p