0

Expectations: I want to create a png/jpeg file based on the user input in in tkinter but I would need to use pillow to create the images. I want to create a png and jpg and of a certain size.

If I plainly create the file using:

with open('filename. jpg #for this example', 'x'):
    pass

Some Extra Info: It saves with 0kb which I have expected but I have no way to set the size of the image. If I create a png and jpg in Paint 3d they do take up some I am guessing from the size.

Needs: I would need to create a png/jpg file using Pillow with a set width and height, and also fill in the background of the image with any color, let just say as red

Dodu
  • 109
  • 2
  • 8
  • 2
    You can use `Image` module in `pillow` package. You might find `Image.new` (https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.new) interesting, define `size` as you want it to be and then use `Image.save` to save the image. – Bijay Regmi Apr 07 '22 at 11:11
  • thanks alot I couldn't find any info about setting the size – Dodu Apr 08 '22 at 12:27
  • 1
    `my_image = Image.new(mode="RGB", size=(1000,1000), color="red")` creates a new `Image` object of size `1000x1000` with background color red and you can save it using `my_image.save("myimage.png")` – Bijay Regmi Apr 08 '22 at 18:33
  • ok thanks for sharing the code 2 – Dodu Apr 09 '22 at 07:19

0 Answers0