Images getting corrupted...help

Hey @Rohit_Haque the picture you posted came through and it looks like an image was sliced up but not reassembled correctly. But if you tried to type any text, it didn’t come through. So the community can’t see what you were trying to do so we can help fix it. After you get the explanation posted you might see some solutions.

I also face that problem when I try to annotate images which were uploaded. These images are corrupted, being both horizontal and vertical, so I can’t assign the exact position I want.

i found a solution
import os
from PIL import Image, ImageOps

CONFIGURATION

input_folder = r"E:\Study Material\CSE_KYAU\thesis work\DATASETV2"
output_folder = r"E:\Study Material\CSE_KYAU\thesis work\DATASETV2.1"

Create output folder if it doesn’t exist

if not os.path.exists(output_folder):
os.makedirs(output_folder)

print(f":rocket: Starting Image Sanitization…")

for filename in os.listdir(input_folder):
if filename.lower().endswith((‘.png’, ‘.jpg’, ‘.jpeg’, ‘.heic’)):
try:

1. Open the image

img_path = os.path.join(input_folder, filename)
img = Image.open(img_path)

        # 2. Fix the Orientation (Burn the EXIF rotation into pixels)
        # This is the step that fixes your Roboflow glitch
        img = ImageOps.exif_transpose(img)

        # 3. Strip Metadata (Create a new clean image object)
        data = list(img.getdata())
        clean_img = Image.new(img.mode, img.size)
        clean_img.putdata(data)

        # 4. Save to the clean folder
        # We convert to .jpg to ensure maximum compatibility
        clean_filename = os.path.splitext(filename)[0] + ".jpg"
        save_path = os.path.join(output_folder, clean_filename)
        
        clean_img.save(save_path, quality=95, optimize=True)
        print(f"✅ Fixed: {filename}")

    except Exception as e:
        print(f"❌ Error processing {filename}: {e}")

print(“:tada: Done! Upload the images from ‘clean_images’ to Roboflow.”)

For a few days, the uploaded images with EXIF rotations were being rotated twice in the platform, causing this strange behaviour.
This was fixed 7d ago, so it should not happen for new image uploads.

Nice workaround @Rohit_Haque

2 Likes

Thank You so much