I am creating a program that requires a background image in Python Turtle.
I know how to add the image (bgpic("")) but I need to resize it. I can't use photoshop because I can't then add the file (says that it has no data in the file!).
So how do I resize it through code?
With Pillow you can easily do it :)
here is the doc of the library and the resize function
http://pillow.readthedocs.org/en/3.0.x/reference/Image.html?highlight=resize#PIL.Image.Image.resize
Related
I am trying to make a game in python 3 which requires a background image. I already have the image. The problem here is my image looks small compared to the big screen. I don't want to change the size of the screen because then I would have to redo all the coordinates of the other objects on the screen. Is there any way I can increase the size of the background image?
Ps. I'm using Python 3 and on VS code.
Thanks in advance!
This is the picture of what the small picture looks like.enter image description here
In order to increase the size of the image, you would need too increase the resolution.
Assuming that you are using windows, open the png with Microsoft Photos, and click on the three horizontal dots at the top right.
A dropdown menu will open, press the third option from the top labeled "Resize"
After this, press on "Define custom dimensions" and you may manipulate the dimensions of the image as you like.
Then, simply save the resized image, and use it in your project.
you can also do this using CV2 library
import cv2
image=cv2.imread("image.png")
scale_percent=1.5
width=int(image.shape[1]*scale_percent)
height=int(image.shape[0]*scale_percent)
dimension=(width,height)
resized = cv2.resize(image,dimension, interpolation = cv2.INTER_AREA)
print(resized.shape)
cv2.imwrite("output.png",resized)
OR you can use PIL library as well
from PIL import Image
image = Image.open("image.png")
image.save("output.png", dpi=(image.size[0]*1.5,image.size[1]*1.5))
I'm trying to make a GUI in tkinter that uses one image as an overlay on top of another, but when I place the image over the lower one, the transparent area of the image appears as grey.
I've searched for solutions to this, but all the results that I've found have pointed towards using PIL.
Is it possible for me to use transparent, or partially transparent images in the python tkinter module without using PIL?
You could use some basic photoshop tools like the magic wand tool to remove the background, but keep in mind, some PNG format images have a faint background. This is either in the from of a watermark, or the image background was rendered with a lower opacity than the rest of the image. Your GUI may also have a layer placed above the images by default. Does it appear on each image seperatly when loaded into the GUI?
guys,
I am trying to find a python GUI library that can show and process 16bit greyscale image easily. I need to modify pixels. I have tried wxpython. It can show the images. But when I tried to convert a numpy array with single channel 16bit data to a string and loaded it in wxImage, it showed me that invalid buffer size. What's more, I have tried to decode the first element of data string in a wxImage instance that load the same image directly. Its value wasn't equal to the pixel (0,0) in numpy array.
Could someone tell me how wxPython format its data string or introduce a better GUI library that can fix this? I know wxImage normally formats its pixel data with RGB. But I just need grey image. And I need to create a sophisticated UI. I think opencv can't meet my need.
You can use pyqt or pyside, but I would recommend pyqtgraph which is excellent for this sort of thing. You can build your ui in pyside and use pyqtgraph to manage image output
Tried looking in the PIL module but couldn't find this covered.
I have an image, and I need to take a cropped piece of the image and move it to a different area within the same image. Simple enough, but I will need to do this for thousands of images, so I will do batch image processing.
PIL seems too basic for this, any other libraries?
Actually, PIL looks like it can do it very well, if you want to copy and paste rectangular areas.
Check the documentation on the crop and paste methods on image, on the documentation here:
http://effbot.org/imagingbook/image.htm
If you need non-rectangular areas, though, you will have to resort to more sophisticated handling, but that does not preclude you from doing it with PIL.
Yes, check OpenCV.
How to crop images with opencv in python
The Python wrapper for the GD library should do what you need:
copyTo(image[, (dx,dy)[, (sx,sy)[, (w,h)]]])
copy from (sx,sy), width sw and height sh to destination image (dx,dy)
I'm trying to load this PSD image with Python Imaging Library.
http://www.2shared.com/photo/JjSY7dN-/BG1.html
I'm not very familiar with layered images. Can someone check to see what's the issue? The image appears to be completely transparent. Opening it in my image editor I noticed that the only layer in the image was hidden, I could unhide it to see the colors.
When I load the image with PIL, I get the same issue, but it seems that PIL consolidates the layers into one and I can't do the same as in my image editor. Or maybe there's something I don't know.
PIL provides only very rudimentary hooks into the PSD format. It doesn't support writing or much in the way of manipulation. Your image layer is not shown, so it results in a transparent image. You'll need something more advanced to modify the PSD.
Here's all there is about the PSD format in PIL: http://www.pythonware.com/library/pil/handbook/format-psd.htm
Soon to be available here: http://effbot.org/imagingbook/format-psd.htm