Jump to content

Use Python to remove images EXIF data!


  • Reply to this topic
  • Start new topic

Recommended Posts

[:heart:] PYTHON3 - Creating and Cleaning a Stylized Avatar (and Why EXIF Data Matters)

image.png

The script starts by building a simple but striking emblem: a hooded figure with glowing eyes, framed by a gradient border. It uses Pillow (PIL) to layer geometric shapes (triangles, rectangles, ellipses) on a dark background, then writes the username below the emblem.

 

But the more important part comes after the artwork is generated — making sure the output is safe to share.


Why remove EXIF metadata?

Whenever you save an image (especially with cameras or phones), it usually carries EXIF metadata:

  • Camera model, lens, GPS coordinates, timestamps

  • Even software that last edited it

That’s useful for photographers, but dangerous when publishing online — you might be leaking location or device info.

If we’re generating avatars, we want them to be clean PNGs with no personal data embedded.


Stripping EXIF with Pillow

Luckily, Pillow makes this very easy. After generating the image, you can “sanitize” it by re-saving without copying over any existing metadata:

from PIL import Image

def remove_exif(input_path, output_path):
    img = Image.open(input_path)
    data = list(img.getdata())  # raw pixel values
    clean_img = Image.new(img.mode, img.size)
    clean_img.putdata(data)
    clean_img.save(output_path)
    print(f"Saved EXIF-free image: {output_path}")
 

How it works:

  1. Open the original file.

  2. Extract only the pixel data.

  3. Rebuild a new image from scratch.

  4. Save it fresh — no metadata is carried over.

Now your avatar is guaranteed to be metadata-free.


The full pipeline

  1. Generate the hooded emblem (gradient ring + figure + glowing eyes + username).

  2. Save the raw PNG.

  3. Immediately run it through the remove_exif function.

End result: a stylized avatar that’s not only visually unique but also privacy-safe for use as a profile picture, game avatar, or social media icon.

 

Image Generation Python Script
 

import hashlib
from PIL import Image, ImageDraw, ImageFont

def generate_hood_emblem(username, size=512, output_path="emblem_avatar.png"):
    """
    Create a stylized hooded avatar emblem with username.
    username: string to seed colors and generate text.
    size: image size in pixels.
    output_path: filename for output image.
    """

    # Create a base image
    img = Image.new("RGBA", (size, size), (30, 30, 40, 255))
    draw = ImageDraw.Draw(img)

    # Generate a gradient circle border
    border_thickness = size // 20
    inner_radius = size // 2 - border_thickness
    center = size // 2

    # Color gradient (blue to magenta)
    def lerp(c1, c2, t): return tuple(int(c1[i] + (c2[i] - c1[i]) * t) for i in range(3))

    color_start, color_end = (0, 180, 255), (180, 0, 255)
    for i in range(border_thickness):
        t = i / (border_thickness - 1) if border_thickness > 1 else 0
        color = lerp(color_start, color_end, t)
        draw.ellipse(
            [center - inner_radius - i, center - inner_radius - i,
             center + inner_radius + i, center + inner_radius + i],
            outline=color + (255,)
        )

    # Draw a hooded cloak: simple triangle shapes
    hood_color = (10, 10, 15, 255)
    draw.polygon([
        (center * 0.6, center * 0.5),
        (center * 1.4, center * 0.5),
        (center, center * 1.3)
    ], fill=hood_color)
    draw.rectangle([
        (center * 0.7, center * 1.3),
        (center * 1.3, center * 1.6)
    ], fill=hood_color)

    # Add glowing "eyes"
    eye_color = (255, 30, 50, 255)
    eye_w, eye_h = size // 20, size // 40
    eye_y = center * 0.8
    eye_x_offset = size // 12
    draw.ellipse(
        [(center - eye_x_offset - eye_w, eye_y - eye_h),
         (center - eye_x_offset + eye_w, eye_y + eye_h)],
        fill=eye_color
    )
    draw.ellipse(
        [(center + eye_x_offset - eye_w, eye_y - eye_h),
         (center + eye_x_offset + eye_w, eye_y + eye_h)],
        fill=eye_color
    )

    # Render username text below emblem
    try:
        font = ImageFont.truetype("arial.ttf", size // 8)
    except IOError:
        font = ImageFont.load_default()

    text = username

    #  Works with new Pillow
    bbox = draw.textbbox((0, 0), text, font=font)
    text_width = bbox[2] - bbox[0]
    text_height = bbox[3] - bbox[1]

    text_position = ((size - text_width) / 2, size * 0.82 + eye_h)
    draw.text(text_position, text, font=font, fill=(180, 180, 220, 255))

    #  Save the image
    img.save(output_path)
    print(f"Emblem avatar saved to {output_path}")


if __name__ == "__main__":
    generate_hood_emblem("z3r0_dark_30", size=512, output_path="zd30.png")
 


Have Fun!

Your Dark Coder,
 
0DARK30

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...