snackshell commited on
Commit
460870c
·
verified ·
1 Parent(s): f28dd0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -33
app.py CHANGED
@@ -18,50 +18,33 @@ EXECUTOR = ThreadPoolExecutor(max_workers=2) # Handle concurrent requests
18
 
19
  # ===== WATERMARK FUNCTION =====
20
  def add_watermark(image_bytes):
21
- """Add professional watermark with fallback fonts"""
22
  try:
23
  image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
24
  draw = ImageDraw.Draw(image)
25
 
26
- # Try multiple font options
27
- font = None
28
- for font_path in [
29
- "Roboto-Bold.ttf", # Our Dockerfile installs this
30
- "DejaVuSans-Bold.ttf",
31
- "FreeSansBold.ttf",
32
- None # Final fallback to default
33
- ]:
34
- try:
35
- size = min(image.width // 15, 40) # Responsive sizing
36
- font = ImageFont.truetype(font_path, size) if font_path else ImageFont.load_default(size)
37
- break
38
- except:
39
- continue
40
 
41
- # Calculate dynamic position
42
- bbox = draw.textbbox((0, 0), WATERMARK_TEXT, font=font)
43
- text_w, text_h = bbox[2] - bbox[0], bbox[3] - bbox[1]
44
- margin = image.width // 50
45
- position = (image.width - text_w - margin, image.height - text_h - margin)
46
 
47
- # Draw with outline effect
48
- for offset in [(-1,-1), (1,1)]: # Shadow positions
49
- draw.text(
50
- (position[0]+offset[0], position[1]+offset[1]),
51
- WATERMARK_TEXT,
52
- font=font,
53
- fill=(0, 0, 0, 180)) # Semi-transparent black
54
 
55
- draw.text(
56
- position,
57
- WATERMARK_TEXT,
58
- font=font,
59
- fill=(255, 255, 255, 200)) # Semi-transparent white
60
 
61
  return image
62
  except Exception as e:
63
  print(f"Watermark error: {str(e)}")
64
- return Image.open(io.BytesIO(image_bytes)) # Fallback to original
65
 
66
  # ===== IMAGE GENERATION =====
67
  def generate_image(prompt):
 
18
 
19
  # ===== WATERMARK FUNCTION =====
20
  def add_watermark(image_bytes):
21
+ """Add watermark with smaller text and simplified positioning"""
22
  try:
23
  image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
24
  draw = ImageDraw.Draw(image)
25
 
26
+ # Smaller font size (24 instead of 40)
27
+ font_size = 24
28
+ try:
29
+ font = ImageFont.truetype("Roboto-Bold.ttf", font_size)
30
+ except:
31
+ font = ImageFont.load_default(font_size)
 
 
 
 
 
 
 
 
32
 
33
+ text = "SelamGPT"
34
+ margin = 10 # Reduced from 20
 
 
 
35
 
36
+ # Calculate position using textlength
37
+ text_width = draw.textlength(text, font=font)
38
+ x = image.width - text_width - margin
39
+ y = image.height - 30 # Fixed vertical position
 
 
 
40
 
41
+ # Simpler white text without transparency
42
+ draw.text((x, y), text, font=font, fill=(255, 255, 255))
 
 
 
43
 
44
  return image
45
  except Exception as e:
46
  print(f"Watermark error: {str(e)}")
47
+ return Image.open(io.BytesIO(image_bytes))
48
 
49
  # ===== IMAGE GENERATION =====
50
  def generate_image(prompt):