KBNLresearch / image2ascii

Generate ASCII art from images
Apache License 2.0
0 stars 0 forks source link

Adjust contrast #2

Open bitsgalore opened 4 hours ago

bitsgalore commented 4 hours ago

Via Pillow?

bitsgalore commented 4 hours ago

Perhaps like this:

https://stackoverflow.com/a/42045524/1209004

Probably easiest to use this directly on the output of the the ASCII conversion (my_art), which already uses Pillow. See:

https://github.com/LeandroBarone/python-ascii_magic?tab=readme-ov-file#the-class-asciiart

This way don't have to mess with the source image files (incl reloading and possible resulting caching issues).

Quick test:

from PIL import Image, ImageEnhance

imageIn = 'eddy.jpg'
with Image.open(imageIn) as im:
    im.load()
    for i in [1.0, 1.5, 2.0, 3.0]:
        scale_value=i
        im2 = ImageEnhance.Contrast(im).enhance(scale_value)
        fNameOut = "eddy" + str(int(10*i)) + ".jpg"
        im2.save(fNameOut)

ALSO: for printing would be useful if characters are in black and background white. Might be possible with some CSS? See:

https://github.com/LeandroBarone/python-ascii_magic?tab=readme-ov-file#to_html_file