I want to use a imageGrab in my application.
My laptop is a macbook with OSX.
When I use Pillow I got this error:
ImportError: ImageGrab is Windows only
Code:
import ImageGrab
im = PIL.ImageGrab.grab()
but in Pillow documentation says:
The current version works on OS X and Windows only.
Take a snapshot of the screen.
The pixels inside the bounding box are returned as an “RGB” image on Windows or “RGBA” on OS X.
If the bounding box is omitted, the entire screen is copied.
http://pillow.readthedocs.org/en/latest/reference/ImageGrab.html
When I use pyscreenshot I got this error:
IOError: cannot identify image file '/var/folders/wk/b1c839t15xvbz923wtfdsfw80000gn/T/pyscreenshot_imagemagick_Gsb0Pw.png'
Code:
import pyscreenshot as ImageGrab
im=ImageGrab.grab()
According to the commit history, OSX support was only added on 1st Aug 2015. However, the latest Pillow release (2.9.0) was made on 1st July 2015. So it would appear that the online documentation is not kept in sync with the current release.
You could compile a pre-release version from github to get the required functionality, but it would probably be much simpler to just copy the relevant ImageGrab code directly:
import os, tempfile, subprocess
from PIL import Image
def grab(bbox=None):
f, file = tempfile.mkstemp('.png')
os.close(f)
subprocess.call(['screencapture', '-x', file])
im = Image.open(file)
im.load()
os.unlink(file)
if bbox:
im = im.crop(bbox)
return im
The next Pillow release, 3.0.0, is due out on Thursday (1st Oct 2015) and ImageGrab will support both OS X and Windows.
The linked documentation is the latest, and is generated from the latest master branch.
The 2.9.0 docs says it's Windows only.
OS X support was added in Pillow 3.3.0.
Related
Similar to this question:
How to get detail (Title,Artist) from .mp3 files in python using eyed3
I'd like to get music artwork from a .m4a file (similar to `.mp3') into Tkinter Image for displaying on a label.
For some strange reason all the answers in the link use:
import eyed3
but I have to use
import eyeD3
to install I had to use:
sudo apt install python-eyed3
sudo apt install eyed3
I'm running Ubuntu 16.04.6 LTS until 2021 at the latest which means I'm using Python 2.7.12. I understand the syntax and naming conventions may have changed in eyeD3 or eyed3 Python 3.5 versions which is another option for Ubuntu 16.04.6 LTS. I'm also using Linux Kernel 4.14.188 LTS but I doubt that matters.
Note: I tried ffmpeg calls from Python this morning to convert .m4a file's artwork into a .jpg file but that was "complicated" and I was hoping eyed3 or eyeD3 would be simpler.
Use file.tag.images and iterate it,use i.image_data to get the bytes of the image.
For example:
import eyed3, io
from PIL import Image, ImageTk
import tkinter as tk
root = tk.Tk()
file = eyed3.load(r"music_path")
# if there contains many images
for i in file.tag.images:
img = ImageTk.PhotoImage(Image.open(io.BytesIO(i.image_data)))
tk.Label(root, image=img).pack()
# or if there only one image here:
# img = ImageTk.PhotoImage(Image.open(io.BytesIO(file.tag.images[0].image_data)))
# tk.Label(root, image=img).pack()
root.mainloop()
Works fine on my PC.
I'm really really beginning/nooby in this and i'm trying to detect the color green on my screen and when it shows up click the mouse button. im also using sublime text 2 but I also have idle.
import ImageGrab
import time
time.clock()
image = ImageGrab.grab()
for y in range(0, 100, 10):
for x in range(0, 100, 10):
color = image.getpixel((x, y))
print(time.clock())
i tried this but it just gives me this "ModuleNotFoundError: No module named 'ImageGrab'"
I have been scouring the internet for littarl hours and i just cant find any tutorials that help with installing pillow. this is ridiculously complicated and im about to give up
Instead of
import ImageGrab
use
from PIL import ImageGrab
You should have PIL already installed. PIL is the "Python Image Library" and can be downloaded from https://www.pythonware.com/products/pil/
Note that PIL is quite old and seems to be only available for Python 2.x (and even older).
You could also use the Python package Pillow instead, which is a fork of PIL. This can be installed using pip install Pillow in (recent versions of) Python 2 as well as 3.
Before you ask, I did try putting an image in it, and it didn't work like look at this.
import Image
Image = Image.open('clerky.jpeg')
Image.show()
and this code above comes up with this error below.
import Image
ImportError: No module named 'Image'
If you're using Pillow, the correct usage is
from PIL import Image
To install Pillow on Windows, start the Command Prompt application (or hit WinR and type cmd, then hit Enter). Type
pip install Pillow
hit Enter, and everything should install automatically.
I think you mean from PIL import Image
from PIL import Image
PIL (Python Image Library) has to be installed on your system, AKA "pil" and "Pillow" from time to time. effbot.org/imagingbook/pil-index.htm
I'm trying to write some programs using opencv and python. I installed opencv and the python libraries from the repositories. I'm using ubuntu 12.04. The folder /var/lib/python-support/python2.7 contains just 5 files :
cv2.so
cv.py
cv.pyc
simplegeneric-0.7.egg-info
simplegeneric.py
simplegeneric.pyc
From what reading I have done, I think there's supposed to be an opencv folder around here. I'm able to import cv library using
import cv
but
from opencv import cv
And I cannot load the highgui module. Any way to work around this? I would really really like to do something in opencv
You must have installed OpenCV >= 2.3.1. In OpenCV 2.3.1 and higher, Python bindings do not have highgui.
import cv2
import cv2.cv as cv
and you're good to go.
import cv2
img = cv2.imread("image name")
cv2.imshow("window name", img)
cv2.waitKey(0)
You can find more help on OpenCV docs and you could also look at some of the opwncv stuff that I have been doing here.
I hope this helps.
You will get the highgui file in OpenCV folder(installed folder) in include/opencv/highgui.h.
I just installed the 1.15 Python Image Library in the following folder:
C:\Python26\Lib\site-packages\
However, when I write
from PIL import Image, ImageOps, ImageDraw
I get a error saying unresolved import. Thanks for the help in advance!
The actual modules are just Image, ImageOps, ImageDraw; the PIL package is something one particular distro decided to tack on because they thought those module names were too generic, but they're not actually found in PIL.