Home > Blockchain >  How to create a 1 pixel white .gif from code only
How to create a 1 pixel white .gif from code only

Time:12-08

I'm new to programming, i won't become a developer but I like to learn a few stuff, since i'm a creative artist. I'm trying to solve an exercise I came up with.

I'm looking for guidelines to create a 1 pixel image from code. I want to try to create the most basic form of a white image, and I thought that a lossless 1 pixel gif of white (#FFFFFF or RGB 255, 255, 255) could be the simplest form, generating the smallest code possible.

Where would I even start?

I created two 1 pixel white .gifs, one in Paint and another in Photoshop, using 8bit Grayscale color mode. Gave both of them the same name, and when I hash them, both hashes are different, so they are not exactly the same. I also tried exporting from photoshop twice, to different directories, and this time hashes are the same.

My intention is to create the simplest and purest form of that white pixel.

Tips?

CodePudding user response:

In Python, you can use PIL to create an image. Here is the code for what you requested.

from PIL import Image # import library

img = Image.new(mode = "RGB", size = (1,1)) # creates a RGB image with the size of 1x1
pixels = img.load() # Creates the pixel map
pixels[0,0] = (255,255,255) # Set the colour of the first (and only) pixel to white

img.save(format='GIF', fp='./test.gif')
# Saves the image as a GIF in a file called test.gif in your current directory

CodePudding user response:

The purest, simplest form that is widely readable (GIMP, Photoshop, MS-Paint) is NetPBM IMHO.

Here is a single white pixel - no metadata, no copyright, no EXIF, no creation date, no palette, no checksum. You can create it with a text editor or code:

P1
1 1
0

Save it as white.pbm


The simplest Python to create a white single pixel GIF with PIL is probably:

from PIL import Image
Image.new('L', (1,1), 255).save('white.gif')
  • Related