title: AWS S3 bucket image gets rotated when processing with PIL. How to fix the orientation change?
body: <p>I want to create a copy of the image in AWS S3 bucket and perform some operation with PIL, and want to save to another bucket. The processed image gets rotated. Seems like its missing the exif details.</p>
  
  <p><strong>Here is the sample code:</strong></p>
  
  <pre><code>s3c = boto3.client('s3')
  file_byte_string = s3c.get_object(Bucket=s3BucketName, Key=documentName)['Body'].read()
  
  img = Image.open(BytesIO(file_byte_string)).convert('RGB')
  width, height = img.size 
  
  if(doc.pages):
      page = doc.pages[0]
  
      #Regular expression for identifying secure data
      regex = r"(?&lt;!\S)(?:\$\s*(?:\d+(?:\,\d+)?)|(?:[@+] ?)?(\d+(?:[ -]\d+)+\.?|(?:\+ ?)?\d{6,}))(?!\S)" 
  
      .
      ..
      ..
      ...
      .
      .
      .
  
  buffer = BytesIO()
  if(extension.lower() in ".png"):
      img.save(buffer, "PNG")
  elif extension.lower() in ".jpg" or extension.lower() in ".jpeg":
      img.save(buffer, "JPEG")
      .
      ..
      .
  s3r = boto3.resource("s3")
  buffer.seek(0) 
  
  response = s3r.Bucket(s3BucketName).put_object(Key=prefix, Body=buffer.read(), ContentType='image/png'
  </code></pre>