python-imaging-library

Compressing image with python-opencv actually results more size

Compressing image with python-opencv actually results more size Question: I want to compress image in-memory using python. Using this code from answer https://stackoverflow.com/a/40768705 I expect that changing "quality param" (90) I will get less size of result image. encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90] result, enc_img = cv2.imencode(‘.jpg’, img_np, encode_param) My original plan was to decrease this …

Total answers: 1

How to make these PIL text centered properly

How to make these PIL text centered properly Question: For context, I’m trying to make a spinnergif. The text options here are just for show, by right i wish to make the number of options flexible. I’m trying to make the text centered nicely within each pieslice, but for some reason only some are centered …

Total answers: 1

Is double close in strace necessarily bad?

Is double close in strace necessarily bad? Question: I am training a neural network. Somewhere in my code base, I have a code snippet like the following: def foo(): d = {} with PIL.Image.open(img_path) as img: d["img"] = torchvision.transforms.functional.to_tensor(img) return d This code doesn’t cause any problems. However, when I run my program under strace, …

Total answers: 1

Python Tkinter Images Tearing On Scroll

Python Tkinter Images Tearing On Scroll Question: I’m working on a project to create a GUI application to display images as clickable buttons in Tkinter. I have the functionality completed where the images appear in a scroll-able grid on the GUI. However, when scrolling up or down there is terrible screen tearing with the images. …

Total answers: 3

what is the use-case of Python3 only `if` and `break` in `for`?

what is the use-case of Python3 only `if` and `break` in `for`? Question: I am learning python but https://github.com/python-pillow/Pillow/blob/main/src/PIL/JpegImagePlugin.py#L435-L437 https://github.com/python-pillow/Pillow/blob/31669013d420c2a532f5be6c5631827fe36e6f70/src/PIL/JpegImagePlugin.py#L435-L437 I am watching the code of PIL of python then I can not understand here. for s in [8, 4, 2, 1]: if scale >= s: break Is the PIL library wrong? I did: watch …

Total answers: 1

Filling a cloud 2D image into a continous map

Filling a cloud 2D image into a continous map Question: I have the following image: and I wish to obtain something close to (I didn’t do it perfectly): How can I do this with python? My initial image is a 2D numpy array of 0 and 255 values. Asked By: Learning from masters || Source …

Total answers: 2

Tkinter: App.on_select() missing 1 required positional argument: 'event'

Tkinter: App.on_select() missing 1 required positional argument: 'event' Question: I am trying to develop a Python application whose goal is to display a certain picture depending of the selected value in a ComboBox. Unluckily the script displays the following error: return self.func(*args) ^^^^^^^^^^^^^^^^ TypeError: RadianceGBA.on_select() missing 1 required positional argument: ‘event’ Here is the code …

Total answers: 1

Why do image size differ when vertical vs horizontal?

Why do image size differ when vertical vs horizontal? Question: Tried to create a random image with PIL as per the example: import numpy from PIL import image a = numpy.random.rand(48,84) img = Image.fromarray(a.astype(‘uint8’)).convert(‘1’) print(len(img.tobytes())) This particular code will output 528. Wen we flip the numbers of the numpy array: a = numpy.random.rand(84,48) The output …

Total answers: 1

How to update an image on a tkinter button after edditing it with PILLOW

How to update an image on a tkinter button after edditing it with PILLOW Question: I am trying to work on a tkinter application that takes uploaded images and add a watermark to them and I am facing challenge rendering the newly watermarked image. Here is my code, I am trying to get the ‘add_watermark()’ …

Total answers: 1