Forgive me if this is a real newbie question, but hey, as far as PIL goes, I'm a newbie. I'm trying to write a script that draws on an image, then splits the image into two copies and draws more on them independently. I can't seem to figure out how to do that second part. I've written up a sample script to demonstrate the issue. If working correctly, the output file snippet11a.png should contain a triangle, snippet11b.jpg should contain the triangle with a rectangle superimposed, and snippet11c.jpg should contain the triangle with a circle superimposed (but not the rectangle).<br>
<br>Can anyone suggest a path? If it helps, I'm running python 2.6.1 on Windows Vista (not my preferred environment).<br><br>import Image, aggdraw<br>size = 400, 300<br>cwhite = 255, 255, 255<br># 23-Aug-2009<br># This little program is an experiment in what it takes to make separate<br>
# images, which can be drawn on separately from each other. I have been<br># having a problem that drawing on any copy of an image ends up drawing on<br># the original image. The only way I found that creates a truly independent<br>
# image is to start from a separate Image.new() call.<br>Im2 = Image.new("RGBA", size, cwhite)<br>Im3 = Image.new("RGBA", size, cwhite) <br>draw2 = aggdraw.Draw(Im2)<br>color1 = (0,0,127)<br>opacity1 = 127<br>
brush1 = aggdraw.Brush(color1, opacity=opacity1)<br>draw2.polygon((100, 100, 300, 100, 200, 200), aggdraw.Pen("black"), brush1)<br>draw2.flush()<br>Im2.save("C:\Temp\snippet11a.png")<br># Im3 = Im2.copy # This command causes a "AttributeError: 'function' object<br>
# has no attribute 'mode'" error at the next draw on Im3 <br>draw2a = draw2 # Drawing on a copy of the draw object will draw on the same image<br>draw2a.rectangle((50, 50, 250, 250), aggdraw.Pen("black"), brush1)<br>
draw2a.flush()<br>Im2.save("C:\Temp\snippet11b.png")<br>draw3 = aggdraw.Draw(Im3)<br>draw3.ellipse((150, 50, 350, 250), aggdraw.Pen("black"), brush1)<br>draw3.flush()<br>Im3.save("C:\Temp\snippet11c.png")<br>
<br><br>