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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -47
app.py CHANGED
@@ -18,65 +18,26 @@ 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':
@@ -89,6 +50,41 @@ def create_tshirt_preview(design_image, tshirt_color="white"):
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_color="white"):
22
  """
23
+ Overlay the design onto the existing t-shirt template
24
  """
25
+ # Load the template t-shirt image
26
+ tshirt = Image.open('image.jpeg')
27
+ tshirt_width, tshirt_height = tshirt.size
 
 
 
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 shirt (40% of shirt width)
34
+ design_width = int(tshirt_width * 0.4) # Adjust this percentage as needed
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 design on shirt
39
  x = (tshirt_width - design_width) // 2
40
+ y = int(tshirt_height * 0.3) # Adjust this value based on your template
41
 
42
  # If design has transparency (RGBA), create mask
43
  if design_image.mode == 'RGBA':
 
50
 
51
  return tshirt
52
 
53
+ # def create_tshirt_preview(design_image, tshirt_color="white"):
54
+ # """
55
+ # Overlay the design onto a t-shirt template
56
+ # """
57
+ # # Create a base t-shirt shape
58
+ # tshirt_width = 800
59
+ # tshirt_height = 1000
60
+
61
+ # # Create base t-shirt image
62
+ # tshirt = Image.new('RGB', (tshirt_width, tshirt_height), tshirt_color)
63
+
64
+ # # Convert design to PIL Image if it's not already
65
+ # if not isinstance(design_image, Image.Image):
66
+ # design_image = Image.fromarray(design_image)
67
+
68
+ # # Resize design to fit nicely on shirt (30% of shirt width)
69
+ # design_width = int(tshirt_width * 0.3)
70
+ # design_height = int(design_width * design_image.size[1] / design_image.size[0])
71
+ # design_image = design_image.resize((design_width, design_height), Image.Resampling.LANCZOS)
72
+
73
+ # # Calculate position to center design on shirt (top third of shirt)
74
+ # x = (tshirt_width - design_width) // 2
75
+ # y = int(tshirt_height * 0.25) # Position in top third
76
+
77
+ # # If design has transparency (RGBA), create mask
78
+ # if design_image.mode == 'RGBA':
79
+ # mask = design_image.split()[3]
80
+ # else:
81
+ # mask = None
82
+
83
+ # # Paste design onto shirt
84
+ # tshirt.paste(design_image, (x, y), mask)
85
+
86
+ # return tshirt
87
+
88
  def enhance_prompt_for_tshirt(prompt, style=None):
89
  """Add specific terms to ensure good t-shirt designs."""
90
  style_terms = {