I have been investigating the way to save an image in python but so far I have not found anything that can be useful, what I need is to know that import
have and how to save the image in python, this image will keep it in a database in mongodb, but I still do not know how to save an image in python could you help me, the closest I've found is this:
I would thank you in advance for your help.
Update
Thanks to @EdgarAlejandro I managed to finish my code that I was looking for and I want to share them with you
#!/usr/bin/env python
import Image
import pymongo
import base64
from PIL import Image, ImageOps
from pymongo import MongoClient
con = MongoClient()
db = con.test
image = 'masexito.jpg'
img = Image.open(image)
#img.save('/home/santiago/Documents/Python/img/exito2.jpg')
#encoded = base64.b64encode(img)
with open(image, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
user = {
'nombre' : 'Saul',
'edad' : 38,
'localidad' : 'Monterrey',
'curp' : 'NDUBD88DND87',
'imagen' : encoded_string
}
use = db.users
use.insert_one(user)
print 'Insertado Correctamente' + str(use.inserted_id)
for row in use.find():
print row
P.D .: They must have installed the corresponding libraries