Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Image_watermark_Adder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 🖋️ Image Watermarking Tool

A simple **Streamlit** app to add **text or logo watermarks** to images.

---

## 🚀 Features
- Upload image (JPG/PNG)
- Add **text** watermark with adjustable font size, position, and opacity
- Add **logo** watermark with adjustable size, position, and transparency
- Live preview before download
- Download final image as JPG

---

## 🧱 Tech Stack
- **Python 3**
- **Streamlit**
- **Pillow (PIL)**
53 changes: 53 additions & 0 deletions Image_watermark_Adder/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import streamlit as st
from PIL import Image
import os
from utils.watermark import add_text_watermark, add_logo_watermark

st.set_page_config(page_title=" Image Watermarking Tool", layout="wide")

st.title(" Image Watermarking Tool")
st.write("Upload an image, add a text or logo watermark, and download the result.")

os.makedirs("output", exist_ok=True)

uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])

if uploaded_file:
image = Image.open(uploaded_file).convert("RGB")
st.image(image, caption="Original Image", use_container_width=True)

st.sidebar.header(" Settings")
wm_type = st.sidebar.radio("Watermark Type", ["Text", "Logo"])

position = st.sidebar.selectbox("Position", ["Top-Left", "Top-Right", "Bottom-Left", "Bottom-Right", "Center"])
opacity = st.sidebar.slider("Opacity", 0.0, 1.0, 0.5)

if wm_type == "Text":
text = st.sidebar.text_input("Enter Watermark Text", "© MyBrand")
font_size = st.sidebar.slider("Font Size", 20, 100, 40)

if st.sidebar.button("Apply Text Watermark"):
result = add_text_watermark(image, text, position, opacity, font_size)
output_path = os.path.join("output", "watermarked_text.jpg")
result.save(output_path)
st.image(result, caption="Watermarked Image", use_container_width=True)
st.download_button("Download Image", data=open(output_path, "rb"), file_name="watermarked_text.jpg")

elif wm_type == "Logo":
logo_file = st.sidebar.file_uploader("Upload Logo (PNG preferred)", type=["png"])
scale = st.sidebar.slider("Logo Scale", 0.05, 0.5, 0.2)

if st.sidebar.button("Apply Logo Watermark"):
if logo_file:
logo_path = os.path.join("assets", "temp_logo.png")
os.makedirs("assets", exist_ok=True)
with open(logo_path, "wb") as f:
f.write(logo_file.getbuffer())

result = add_logo_watermark(image, logo_path, position, opacity, scale)
output_path = os.path.join("output", "watermarked_logo.jpg")
result.save(output_path)
st.image(result, caption="Watermarked Image", use_container_width=True)
st.download_button("Download Image", data=open(output_path, "rb"), file_name="watermarked_logo.jpg")
else:
st.warning("Please upload a logo image.")
2 changes: 2 additions & 0 deletions Image_watermark_Adder/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
streamlit
pillow
Empty file.
61 changes: 61 additions & 0 deletions Image_watermark_Adder/utils/watermark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
import os

def add_text_watermark(image, text, position, opacity=0.5, font_size=40):
watermark = image.copy()
drawable = ImageDraw.Draw(watermark)

try:
font = ImageFont.truetype("arial.ttf", font_size)
except:
font = ImageFont.load_default()

bbox = drawable.textbbox((0, 0), text, font=font)
textwidth = bbox[2] - bbox[0]
textheight = bbox[3] - bbox[1]

width, height = image.size
margin = 10
positions = {
"Top-Left": (margin, margin),
"Top-Right": (width - textwidth - margin, margin),
"Bottom-Left": (margin, height - textheight - margin),
"Bottom-Right": (width - textwidth - margin, height - textheight - margin),
"Center": ((width - textwidth) // 2, (height - textheight) // 2)
}
pos = positions.get(position, positions["Bottom-Right"])

# Draw text with opacity
drawable.text(pos, text, fill=(255, 255, 255, int(255 * opacity)), font=font)
return watermark



def add_logo_watermark(image, logo_path, position, opacity=0.5, scale=0.2):
"""
Add a logo watermark to the given image.
"""
base = image.convert("RGBA")
logo = Image.open(logo_path).convert("RGBA")
logo_width = int(base.width * scale)
aspect_ratio = logo.height / logo.width
logo_height = int(logo_width * aspect_ratio)
logo = logo.resize((logo_width, logo_height))


alpha = logo.split()[3]
alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
logo.putalpha(alpha)

margin = 10
positions = {
"Top-Left": (margin, margin),
"Top-Right": (base.width - logo_width - margin, margin),
"Bottom-Left": (margin, base.height - logo_height - margin),
"Bottom-Right": (base.width - logo_width - margin, base.height - logo_height - margin),
"Center": ((base.width - logo_width) // 2, (base.height - logo_height) // 2)
}
pos = positions.get(position, positions["Bottom-Right"])

base.paste(logo, pos, logo)
return base.convert("RGB")
Loading