Gopalag commited on
Commit
dd082a2
·
verified ·
1 Parent(s): b451a65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -55
app.py CHANGED
@@ -18,77 +18,77 @@ pipe = DiffusionPipeline.from_pretrained(
18
  MAX_SEED = np.iinfo(np.int32).max
19
  MAX_IMAGE_SIZE = 2048
20
 
21
- def create_tshirt_preview(design_image, tshirt_image_path="image.jpeg"):
22
- """
23
- Overlay the design onto a downloaded T-shirt template
24
- """
25
- # Load the T-shirt base image
26
- tshirt = Image.open(tshirt_image_path)
27
- tshirt_width, tshirt_height = tshirt.size # Get dimensions of the T-shirt image
28
-
29
- # Convert design to PIL Image if it's not already
30
- if not isinstance(design_image, Image.Image):
31
- design_image = Image.fromarray(design_image)
32
-
33
- # Resize design to fit nicely on the shirt (30% of shirt width)
34
- design_width = int(tshirt_width * 0.3)
35
- design_height = int(design_width * design_image.size[1] / design_image.size[0])
36
- design_image = design_image.resize((design_width, design_height), Image.Resampling.LANCZOS)
37
-
38
- # Calculate position to center the design on the shirt (top third of shirt)
39
- x = (tshirt_width - design_width) // 2
40
- y = int(tshirt_height * 0.25) # Position in the top third
41
-
42
- # If design has transparency (RGBA), create a mask
43
- if design_image.mode == 'RGBA':
44
- mask = design_image.split()[3]
45
- else:
46
- mask = None
47
-
48
- # Paste the design onto the shirt
49
- tshirt.paste(design_image, (x, y), mask)
50
-
51
- # Save the final preview
52
- tshirt.save("tshirt_preview.jpeg", format="JPEG")
53
- print("T-shirt preview saved as tshirt_preview.jpeg")
54
-
55
- return tshirt
56
-
57
- # def create_tshirt_preview(design_image, tshirt_color="white"):
58
  # """
59
- # Overlay the design onto a t-shirt template
60
  # """
61
- # # Create a base t-shirt shape
62
- # tshirt_width = 800
63
- # tshirt_height = 1000
64
-
65
- # # Create base t-shirt image
66
- # tshirt = Image.new('RGB', (tshirt_width, tshirt_height), tshirt_color)
67
-
68
  # # Convert design to PIL Image if it's not already
69
  # if not isinstance(design_image, Image.Image):
70
  # design_image = Image.fromarray(design_image)
71
-
72
- # # Resize design to fit nicely on shirt (30% of shirt width)
73
  # design_width = int(tshirt_width * 0.3)
74
  # design_height = int(design_width * design_image.size[1] / design_image.size[0])
75
  # design_image = design_image.resize((design_width, design_height), Image.Resampling.LANCZOS)
76
-
77
- # # Calculate position to center design on shirt (top third of shirt)
78
  # x = (tshirt_width - design_width) // 2
79
- # y = int(tshirt_height * 0.25) # Position in top third
80
-
81
- # # If design has transparency (RGBA), create mask
82
  # if design_image.mode == 'RGBA':
83
  # mask = design_image.split()[3]
84
  # else:
85
  # mask = None
86
-
87
- # # Paste design onto shirt
88
  # tshirt.paste(design_image, (x, y), mask)
89
-
 
 
 
 
90
  # return tshirt
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  def enhance_prompt_for_tshirt(prompt, style=None):
93
  """Add specific terms to ensure good t-shirt designs."""
94
  style_terms = {
 
18
  MAX_SEED = np.iinfo(np.int32).max
19
  MAX_IMAGE_SIZE = 2048
20
 
21
+ # def create_tshirt_preview(design_image, tshirt_image_path="image.jpeg"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  # """
23
+ # Overlay the design onto a downloaded T-shirt template
24
  # """
25
+ # # Load the T-shirt base image
26
+ # tshirt = Image.open(tshirt_image_path)
27
+ # tshirt_width, tshirt_height = tshirt.size # Get dimensions of the T-shirt image
28
+
 
 
 
29
  # # Convert design to PIL Image if it's not already
30
  # if not isinstance(design_image, Image.Image):
31
  # design_image = Image.fromarray(design_image)
32
+
33
+ # # Resize design to fit nicely on the shirt (30% of shirt width)
34
  # design_width = int(tshirt_width * 0.3)
35
  # design_height = int(design_width * design_image.size[1] / design_image.size[0])
36
  # design_image = design_image.resize((design_width, design_height), Image.Resampling.LANCZOS)
37
+
38
+ # # Calculate position to center the design on the shirt (top third of shirt)
39
  # x = (tshirt_width - design_width) // 2
40
+ # y = int(tshirt_height * 0.25) # Position in the top third
41
+
42
+ # # If design has transparency (RGBA), create a mask
43
  # if design_image.mode == 'RGBA':
44
  # mask = design_image.split()[3]
45
  # else:
46
  # mask = None
47
+
48
+ # # Paste the design onto the shirt
49
  # tshirt.paste(design_image, (x, y), mask)
50
+
51
+ # # Save the final preview
52
+ # tshirt.save("tshirt_preview.jpeg", format="JPEG")
53
+ # print("T-shirt preview saved as tshirt_preview.jpeg")
54
+
55
  # return tshirt
56
 
57
+ def create_tshirt_preview(design_image, tshirt_color="white"):
58
+ """
59
+ Overlay the design onto a t-shirt template
60
+ """
61
+ # Create a base t-shirt shape
62
+ tshirt_width = 800
63
+ tshirt_height = 1000
64
+
65
+ # Create base t-shirt image
66
+ tshirt = Image.new('RGB', (tshirt_width, tshirt_height), tshirt_color)
67
+
68
+ # Convert design to PIL Image if it's not already
69
+ if not isinstance(design_image, Image.Image):
70
+ design_image = Image.fromarray(design_image)
71
+
72
+ # Resize design to fit nicely on shirt (30% of shirt width)
73
+ design_width = int(tshirt_width * 0.3)
74
+ design_height = int(design_width * design_image.size[1] / design_image.size[0])
75
+ design_image = design_image.resize((design_width, design_height), Image.Resampling.LANCZOS)
76
+
77
+ # Calculate position to center design on shirt (top third of shirt)
78
+ x = (tshirt_width - design_width) // 2
79
+ y = int(tshirt_height * 0.25) # Position in top third
80
+
81
+ # If design has transparency (RGBA), create mask
82
+ if design_image.mode == 'RGBA':
83
+ mask = design_image.split()[3]
84
+ else:
85
+ mask = None
86
+
87
+ # Paste design onto shirt
88
+ tshirt.paste(design_image, (x, y), mask)
89
+
90
+ return tshirt
91
+
92
  def enhance_prompt_for_tshirt(prompt, style=None):
93
  """Add specific terms to ensure good t-shirt designs."""
94
  style_terms = {