Hey guys! I'm working on a program in python with Tkinter that allows you to enter in a bunch of number and such, and generate an image. So, I have PIL creating a blank PNG image and saving it, it all works...

Now I want to add stuff to the image. Is it possible to use Image.new("RGB",(256,256)) and then add content to it?

Also how do I add, say, four 128 images inside the 256 image (tiled)

Thanks!!

Recommended Answers

All 7 Replies

See if this helps you.

Dan08.

Here is an example how to do something like this with PIL:

# create an empty image with PIL and put pixels inside

from PIL import Image

# use a (r, g, b) tuple to represent colors
red = (255,0,0)
white = (255,255,255)

# create a new 256x256 pixel image surface
# make the background white (default bg=black)
img = Image.new("RGB", [256,256], white)

# keep y fixed to create a horizontal line
y = 10
for x in range(10, 100):
    # put a red pixel at point (x, y)
    img.putpixel((x, y), red)

# save the image
img.save("test1.png")

# optionally look at the image you have created
img.show()

Is there a way to use a similar method with images instead of pixels? I know about all of that, but I need to load multiple images into PIL and tile them in a square...

Is it possible?

Is there a way to use a similar method with images instead of pixels? I know about all of that, but I need to load multiple images into PIL and tile them in a square...

Is it possible?

Looks like Sneekula wasted his time on you then.
I assume you also know all about img.getdata(), then you can put it together with img.putpixel().

OOOOOH, putpixel places an image? Or does it draw a dot?

I guess it's time to experiment...

OOOOOH, putpixel places an image? Or does it draw a dot?

I guess it's time to experiment...

An image is made up of dots.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.