Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Javier Fernández Aparicio
    @jfernandzjl_gitlab
    hi everybody, I'm trying to render a png image as 0s and 1s in the stdout, I wrote this script https://bpa.st/LD7Q
    but I'm not sure how to treat properly the bitstring in order to print something with sense
    sould I use ImageDraw to actually draw the initial opened image in a new image?
    I'm not sure if tobytes() method is returning actually what I need to render the image as a string
    Javier Fernández Aparicio
    @jfernandzjl_gitlab
    because I guess that bytes are some kind of RGB codification or something like that
    Andrew Murray
    @radarhere

    Hi. tobytes() is returning data from our "raw" encoder.

    I would convert the image to "1" mode first (black and white) and then loop over the pixels and print 0 or 1 accordingly.

    from PIL import Image
    
    with Image.open("logo.png") as im:
        (width, height) = (im.width // 300, im.height // 300)
        im_resized = im.resize((width, height))
    
        im_resized = im_resized.convert("1")
        px = im_resized.load()
        bitmap = [
            "".join([
                "1" if px[x, y] == 255 else "0"
                for x in range(im_resized.width)
            ])
            for y in range(im_resized.height)
        ]
    
        for i in bitmap:
            print(i)
    Mahas1
    @Mahas1
    image.png
    Hi all, I was trying to install Pillow on a jailbroken iPad, and it errored out because it was missing headers from the "jpeg" library. I had looked at the build instructions, and it says it has been tested with "libjpeg" and "libjpeg-turbo". Do I only need to install one, or do I need both?
    image.png
    Libjpeg-turbo has build instructions for iOS, and im guessing it shouldnt be too hard to make it work on the iPad Air
    Mahas1
    @Mahas1
    Also, the Pillow build instructions say that I can ignore libjpeg if I pass in the --disable-jpegflag. Where do I enter this flag?
    Mahas1
    @Mahas1

    Also, the Pillow build instructions say that I can ignore libjpeg if I pass in the --disable-jpegflag. Where do I enter this flag?

    nvm, i figured this one out. I just had to read the instructions further

    Andrew Murray
    @radarhere
    You only need one of libjpeg or libjpeg-turbo. libjpeg-turbo is an alternative to libjpeg
    Mahas1
    @Mahas1
    I see, thank you for the clarification
    #Wifi Got Minecraft
    @PokeyManatee4
    hey
    so when i try installing pillow with pip i get this Collecting pillow
    Using cached https://files.pythonhosted.org/packages/03/a3/f61a9a7ff7969cdef2a6e0383a346eb327495d20d25a2de5a088dbb543a6/Pillow-9.0.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-build-quk1khrj/pillow/setup.py", line 46
    f"Pillow {PILLOW_VERSION} does not support Python "
    ^
    SyntaxError: invalid syntax
    ----------------------------------------
    Andrew Murray
    @radarhere

    I expect you're using Python before 3.6. Pillow 9.0.1 only supports Python 3.7 and greater.

    For more information, see https://pillow.readthedocs.io/en/stable/installation.html#python-support

    If you would like to use Python 3.6, you should install Pillow 8.4 instead
    #Wifi Got Minecraft
    @PokeyManatee4
    Im Trying To Install Ursina
    and i am
    Golang is used in python
    Andrew Murray
    @radarhere
    I don't know why you've mentioned Golang, but if you're saying that your problem is that Pillow is failing to install as a dependency when you try to install Ursina, I suggest installing Pillow first as a separate command.
    pip install Pillow==8.4.0
    #Wifi Got Minecraft
    @PokeyManatee4
    no python itself uses golang
    Also Still Got The Error
    Pillow 8.4.0 does not support Python
    Andrew Murray
    @radarhere
    What version of Python are you using?
    #Wifi Got Minecraft
    @PokeyManatee4
    3.6
    wait no
    cabox@cpp-billions-scooter:~/workspace/termlife$ sudo python3 --version
    Python 3.5.2
    cabox@cpp-billions-scooter:~/workspace/termlife$
    wont let me install higher
    Andrew Murray
    @radarhere
    Ok then.
    pip install Pillow==7.2.0
    #Wifi Got Minecraft
    @PokeyManatee4
    My Chromebook says it has a Intel(R) Celeron(R) CPU N3060 @ 1.60GHz (2 threads, 2.48GHz)
    Andrew Murray
    @radarhere
    Did installing Pillow 7.2.0 work?
    #Wifi Got Minecraft
    @PokeyManatee4
    srry i destroyed my vm trying to install devkitpro
    also forgot to try
    Montana Wong
    @Montana_Wong_twitter
    Hey everyone, I'm getting a white border on my darker assets when layering images on top of each other using Pillow. Posted some examples here: https://stackoverflow.com/questions/71776129/white-outline-showing-on-dark-colored-layered-images-when-using-python-pillow
    anyone have any ideas on what the issue might be?
    Andrew Murray
    @radarhere
    The StackOverflow question was "voluntarily removed by its author", so I'm guessing you solved your problem
    Jan-Hendrik Müller
    @kolibril13
    I've written the function get_emoji("🐶") that returns images of open-source emojis OpenMoji:
    from PIL import Image
    import numpy as np
    import requests
    
    #get openmoji
    def get_emoji(emoji):
        emoji_code = "-".join(f"{ord(c):x}" for c in emoji)
        emoji_code = emoji_code.upper()
        url = f"https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/color/72x72/{emoji_code}.png"
        image_pil = Image.open(requests.get(url, stream=True).raw)
        image = np.array(image_pil.convert("RGBA"))
        return image
    
    get_emoji("🐶")
    image.png
    In case that you find this useful, should I sent a pull request to add this script at https://pillow.readthedocs.io/en/stable/handbook/tutorial.html#more-on-reading-images ?
    Andrew Murray
    @radarhere

    I can imagine people being interested in how to show emojis, but your example doesn't have all that much to do with Pillow. It demonstrates how to open an image from a URL, but apart from that, I think it would seem like a random advertisement for another library in the middle of the Pillow documentation.

    If you think the documentation should be updated to include an example of how to open an image from a URL, that would make sense to me. It's in the docs at the moment, but buried in release notes - https://pillow.readthedocs.io/en/stable/releasenotes/2.8.0.html#open-http-response-objects-with-image-open

    In case you are interested in an alternative method, in python-pillow/Pillow#3346, there's been discussion about showing emojis through a font.
    from PIL import Image, ImageDraw, ImageFont
    
    im = Image.new("RGBA", (130, 120))
    d = ImageDraw.Draw(im)
    font = ImageFont.truetype("NotoColorEmoji.ttf", 109)
    d.text((0, 0), "🐶", "#f00", font)
    im.save("out.png")
    out.png
    Jan-Hendrik Müller
    @kolibril13
    Thanks for pointing me to this discussion. I understand this function is only a bit pil related, should not go into the docs.
    What about this example for https://pillow.readthedocs.io/en/stable/handbook/tutorial.html#more-on-reading-images ?
    from urllib.request import urlopen
    from PIL import Image
    url = "https://raw.githubusercontent.com/python-pillow/pillow-logo/main/pillow-logo-248x250.png"
    img = Image.open(urlopen(url))
    Andrew Murray
    @radarhere
    Sounds reasonable to me, sure
    Jan-Hendrik Müller
    @kolibril13
    Nice, here it is: python-pillow/Pillow#6215
    zinob
    @zinob
    I have an issue with Image.tobytes(). I have a monochrome image (mode "1") which width is not evenly divisible by 8. When I do im.tobytes() I get each row padded to even bytes. Is there any way to avoid this? I couldn't find any documentation on the raw-decoder and skimming the source failed since my C++ is a bit to rusty ...
    zinob
    @zinob
    image.png
    zinob
    @zinob
    Oh, i found the documentation, alas it lookas as if I have to write my own decoder/encoder for this to work..