Python Forum
[Basic] How to convert images to 8-bit pixel art using Python.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Basic] How to convert images to 8-bit pixel art using Python.
#1
I created a small Python tutorial that explains how you can convert images to 8-bit Pixel art. The tutorial covers three different methods which use three different modules to do the task.

Python modules which we have covered:
- OpenCV
- Super Pyxelate
- Pixelate


Any feedbacks are welcome.

Thank You
Larz60+ write Dec-01-2023, 09:12 AM:
link removed
Reply
#2
(Apr-26-2021, 03:18 AM)srivastavavyom1991 Wrote: I created a small Python tutorial that explains how you can convert images to 8-bit Pixel art. The tutorial covers three different methods which use three different modules to do the task.

Python modules which we have covered:
- OpenCV
- Super Pyxelate
- Pixelate

Here's the link to the Tutorial: https://geekyhumans.com/convert-images-t...ng-python/

Any feedbacks are welcome.

Thank You
There are a lot of Python modules available for image manipulation but since our focus is only on 8-bit image conversion, we’ll focus only on few of them.
Reply
#3
Converting images to 8-bit pixel art using Python involves reducing the color palette of the image and mapping the colors to a limited set of values. One popular library for this task is the Python Imaging Library (PIL), which has been succeeded by the Pillow library. Here's a basic example using Pillow:

First, you'll need to install Pillow if you haven't already:

Output:
pip install Pillow
Now, you can use the following Python script to convert an image to 8-bit pixel art:

from PIL import Image

def convert_to_pixel_art(input_path, output_path, pixel_size):
    # Open the image
    img = Image.open(input_path)

    # Resize the image to make pixels more prominent
    img = img.resize(
        (img.width // pixel_size, img.height // pixel_size),
        resample=Image.NEAREST
    )

    # Convert the image to 8-bit mode
    img = img.convert("P", palette=Image.ADAPTIVE, colors=256)

    # Save the result
    img.save(output_path)

# Example usage
input_image_path = "path/to/your/image.jpg"
output_image_path = "path/to/your/pixel_art_output.png"
pixel_size = 10  # Adjust this based on your preference

convert_to_pixel_art(input_image_path, output_image_path, pixel_size)
In this script:

- Image.NEAREST is used to ensure that the resizing is done without interpolation, maintaining a pixelated look.
- Image.ADAPTIVE is used for the palette to automatically adapt to the image's color distribution.
- colors=256 limits the palette to 256 colors, which is the maximum for an 8-bit image.

You can adjust the pixel_size variable to control the size of the pixels in the output image. Experiment with different values to achieve the desired level of pixelation.

Save this script, and replace the input_image_path and output_image_path variables with the paths to your input and desired output images. Run the script, and it should create an 8-bit pixel art version of your input image.

Keep in mind that the quality of the pixel art may vary depending on the original image's complexity and the chosen pixel size.
buran write Nov-30-2023, 05:33 PM:
spam link removed
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Pytesseract To Convert Images Into An HTML Site armaiz 0 3,716 Mar-07-2020, 10:41 PM
Last Post: armaiz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020