1

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.

Here is the sample 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"(?<!\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'
Pokemon
  • 63
  • 11
  • You can add exif by adding exif parameter in img.save function. https://stackoverflow.com/questions/17042602/preserve-exif-data-of-image-with-pil-when-resizecreate-thumbnail – jellycsc Apr 30 '20 at 13:49
  • Yea, the issue is, I'm not able to fetch exif from s3. how can I get the exif from an s3 object.? @jellycsc – Pokemon Apr 30 '20 at 13:56
  • If the exif data is not present in the image, then it's not s3's fault. Check where those images come from. – jellycsc Apr 30 '20 at 13:59
  • if I download the same file from s3 and try to access it from local drive, I'm getting the exif details. then why I'm not getting it from s3? – Pokemon Apr 30 '20 at 14:04

0 Answers0