Solving my transparency problem

in #gradnium17 days ago

While the randomized picture generation was decently working, there was both a problem with the code and something that I really wanted to add. The first thing that I did was fix the transparency issue stated in the last post where the logos' transparent pixels overrode the background pixels because the code didn't recognize them as transparent. This problem was actually way easier than I thought as it is fixed by adding only one parameter, the Image.ANTIALIAS shown in the line below, which basically decodes the transparency of the image.

                    foreground = foreground.resize(size, Image.ANTIALIAS)

The second and final thing I wanted to do was to make sure there were no repeat images. The first thing I needed to do to achieve this was to create a while true loop so that the program is constantly running. I then imported a module that detects keyboard inputs than used it to constantly check if the letter "i" has been pressed. All this was made to start the main part of creating the random image. Most of the image creation is the same except that each background and logo gets a unique number and then combined to get a different unique number. This number is then checked to see if it has already been stored in an array created at the start of the code. If it is unique, then it is appended to the array that is checked and saved on the computer.

image.png

While this system could have been made numerous ways to complete the same objective, this way was chosen so that what has been created is stored in the code, not in the actual computer as a file. Overall it works as intended as shown in the image below. That image shows the background color, the color of the image created, and then the array of all of the image number, noting that the first two are placeholders because the code didn't like a 0-dimensional array. Some of these groups have just two numbers, but looking at what numbers these are, they are obviously copies of previous images which shows this code works. Something that I could not figure out how to program in is going back to automatically create another image if an image is detected to be a copy, but overall this is a huge success!

image.png