Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

save image to database using pillow django

# The crop function looks like this:

from PIL import Image

from django.core.files.base import ContentFile

def cropper(original_image, crop_coords):
      img_io = StringIO.StringIO()
      original_image = Image.open(original_image)
      cropped_img = original_image.crop((0, 0, 165, 165))
      cropped_img.save(img_io, format='JPEG', quality=100)
      img_content = ContentFile(img_io.getvalue(), 'img5.jpg')
      return img_content
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #save #image #database #pillow #django
ADD COMMENT
Topic
Name
7+3 =