-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
working together with pillow? #57
Comments
As far as I know, you can load the image into memory, then read and write the image from memory: # Load the image into memory
import io
buf = io.BytesIO()
with open('1.jpg', 'rb') as f:
buf.write(f.read())
# Open the image in pillow
from PIL import Image
with Image.open(buf) as img:
img.load()[0, 0]
# Open the image in pyexiv2
import pyexiv2
buf.seek(0)
with pyexiv2.ImageData(buf.read()) as pyexiv2_img:
pyexiv2_img.read_exif()
# Omit the write operation...
buf.close() In addition, I found that Pillow lost metadata when it saved the image, for example by executing the following code: with Image.open('1.jpg') as img:
img.save('1.jpg', format="JPEG", quality=95) To avoid losing metadata, you should back up the metadata before Pillow opens the image, and write the metadata after Pillow saves the image. |
saved_buf = io.BytesIO()
with Image.open(buf) as img:
img.save(saved_buf, format="JPEG", quality=95) |
I was wrong, buf.truncate(0)
buf.seek(0) |
Thank you!
…On Sat, Mar 13, 2021 at 9:44 AM LeoHsiao ***@***.***> wrote:
I was wrong, io.BytesIO supports modification, just truncate it:
buf.truncate(0)buf.seek(0)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#57 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACDG5B3RWDT7N6XF6IK2E3TDMQV7ANCNFSM4YWR3XTA>
.
|
This issue has been automatically closed because there has been no activity for a month. |
Hi Leo,
thanks for a wonderful module and maintaining it!
Is there a way that I can open an image from pillow directly without writing it to the disk first?
Thanks!
The text was updated successfully, but these errors were encountered: