fire-eggs / pyTagger

Utility to view / modify image metadata tags
MIT License
0 stars 0 forks source link

Thumbnail watermark #7

Open fire-eggs opened 1 year ago

fire-eggs commented 1 year ago

Add a watermark to thumbnails as per these states:

  1. Image has tags
  2. Image doesn't support tags (e.g. GIF)
  3. Image in error state, preventing tags from working
# embed image watermark

with Image.open("arya.jpg") as img:
    # Get the width and height of the image  
    width, height = img.size

    # Get the image watermark that already prepared
    logo = Image.open("thumb.jpg")

    # Resizing the watermark into desired size
    size = (100, 100)
    logo.thumbnail(size)

    # Set the watermark position, if 0, it will set into top left of image
    x = 0
    y = 0

    # Set the watermark position, if written as below, it will set into bottom right of image
    x = width - 100 
    y = height - 100

    # Integrate the image watermark into the watermark position 
    img.paste(logo, (x, y))

    # Show the image
    img.show()
fire-eggs commented 1 year ago

The following script is used to generate the embedded bytes for the water mark images. Ideally this should become some sort of build step?

import base64
import io
from PIL import Image

img = Image.open("errorMarker.png")
output = io.BytesIO()
img.save(output, format="png")
image_as_string = base64.b64encode(output.getvalue())
print(image_as_string)