Sorry I don't show any piece of code here but I simply don't know how to start?
Ok I simply selected image cell and got file of bytearray:
"[bytearray(b'\xff\xd8\xff\xe1\x1a1Exif\x00\x00II*\x00\x08\x00\x00\x00\x10\x00\x00\x01\x03\x00\x01\x00\x00\x00\x08\x01\x00\ (...) etcetc )]"
But how to transform it and save as image?
Here's the answer:
from PIL import Image
import os,io
.....
image = Image.open(io.BytesIO(my_bytearray))
image.save(path_to_image)
PIL must be installed separately by
pip -m install pillow (I'm not certain if -m is necessary ;) )
Related
I wrote some code to generate qrcode in python but at run time it shows this error:
Import "qrcode" could not be resolved Pylance(reportMissingImports)
I am using the qrcode library but I am having some problems.
Installation is pretty straight forward via pip install. Run the following command to install python-qrcode and pillow.
pip install qrcode[pil]
Once you are done, continue installing OpenCV-Python with the following command:
pip install opencv-python
If you intend to detect multiple QR codes in a single image, make sure that the opencv-python version is at least 4.3.0. Older versions do not come with the multi detection functionalities.
Add the following import declaration at the top of your Python file.
import qrcode
from PIL import Image
For basic usage, you can simply run the make() function to generate a QR Code based on your input text:
img = qrcode.make('Your input text')
You can utilize the QRCode class, which comes with a lot more controls and properties.
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=4,
)
The next step is to call the add_data() function. Pass in the input text of your choice. Continue by appending the following code to generate a QR code with a white background and black fill.
qr.add_data('https://medium.com/#ngwaifoong92')
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white").convert('RGB')
You can save it in as an image file as follow:
img.save("sample.png")
Finally you can read this paper.
I am performing OCR on an imenter image description hereage, for that i installed pytesseract library, code i have used is requiring one more library "Image", what would be the cmd code in windows for installation that package. I have tried --> "pip install image" that's not working, or is this code right
code is this
import image
import pytesseract
print pytesseract.image_to_string(image.open('ocr.jpg'))
May be the error is appearing because you used lower case image.open while in documentation its Image.open
Try this:
import Image
import pytesseract
# Simple image to string
print(pytesseract.image_to_string(Image.open('ocr.jpg')))
I am using moviepy to try resize a video clip but every time I try I get this error. Can anyone explain how I can fix it? Thanks
My python code
Import everything needed to edit video clips
from moviepy.editor import *
# Load video clip
myclip = VideoFileClip("dog.mov")
myclip.resize( (460,720) ) # New resolution: (460,720)
myclip.write_videofile("resized_clip.mp4") #write new video file
The error
File "/usr/local/lib/python3.4/dist-packages/PIL/Image.py", line 699, in tostring
"Please call tobytes() instead.")
Exception: tostring() has been removed. Please call tobytes() instead.
Looks like you are using PIL, I would try using Pillow, a support fork that is maintained. MoviePY recommends you use Pillow in lieu of Pil in it's docs:
http://zulko.github.io/moviepy/install.html
For advanced image processing you will need one or several of these
packages. For instance using the method clip.resize requires that at
least one of Scipy, PIL, Pillow or OpenCV are installed.
The Python Imaging Library (PIL) or, better, its branch Pillow .
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
We have the following code:
img = Image.open(FileSystemStorage().path(relpath))
coords = [
cd['crop_start_x'],
cd['crop_start_y'],
cd['crop_end_x'],
cd['crop_end_y']
]
cropped_img = img.crop(coords)
cropped_path = "%s-cropped%s" % os.path.splitext(relpath)
tasks.delete_temporary_file.delay(fss.path(relpath))
cropped_img.save(fss.path(cropped_path))
When trying to save the cropped image, we get a strange "Not a valid number of quantization tables. Should be between 1 and 4." exception, just in one of our environments.
The strangest part is that the code might work sometimes even though the crop or the image doesn't change
Has anyone a lead on this?
We are using Pillow 2.8.1, python 2.7.6 and Ubuntu server 12.04
Basically, the problem originated on a conflicting PIL installation in one of the app servers. It was hard to find since they were hiding behind a load balancer, so the error would pop out sometimes
When we issued pip freeze on the console, we found out that in one of the servers we had both PIL and Pillow installed.
Upon removing both of them and reinstalling Pillow, we solved the issue.
Just to make it clear:
pip uninstall PIL
pip uninstall Pillow
pip install Pillow
And then, just restart the web server.
As others have stated, another possible cause is the use of:
import Image
That statement works only for PIL and should be avoided.
We should always use:
from PIL import Image