def save_image(image, destination=None, filename=None, **options):
 if (destination is None):
  destination = BytesIO()
 filename = (filename or '')
 Image.init()
 format = Image.EXTENSION.get(os.path.splitext(filename)[1].lower(), 'JPEG')
 if (format in ('JPEG', 'WEBP')):
  options.setdefault('quality', 85)
 saved = False
 if (format == 'JPEG'):
  if (settings.THUMBNAIL_PROGRESSIVE and (max(image.size) >= settings.THUMBNAIL_PROGRESSIVE)):
   options['progressive'] = True
  try:
   image.save(destination, format=format, optimize=1, **options)
   saved = True
  except IOError:
   pass
 if (not saved):
  image.save(destination, format=format, **options)
 if hasattr(destination, 'seek'):
  destination.seek(0)
 return destination

def save_image ( image , destination = None , filename = None , ** options ) : if ( destination is None ) : destination = BytesIO ( ) filename = ( filename or '' ) Image . init ( ) format = Image . EXTENSION . get ( os . path . splitext ( filename ) [ 1 ] . lower ( ) , 'JPEG' ) if ( format in ( 'JPEG' , 'WEBP' ) ) : options . setdefault ( 'quality' , 85 ) saved = False if ( format == 'JPEG' ) : if ( settings . THUMBNAIL_PROGRESSIVE and ( max ( image . size ) >= settings . THUMBNAIL_PROGRESSIVE ) ) : options [ 'progressive' ] = True try : image . save ( destination , format = format , optimize = 1 , ** options ) saved = True except IOError : pass if ( not saved ) : image . save ( destination , format = format , ** options ) if hasattr ( destination , 'seek' ) : destination . seek ( 0 ) return destination
save image to the specified path .