admin commited on
Commit
9ebdba1
·
1 Parent(s): 6c64dd2

update if none

Browse files
Files changed (2) hide show
  1. src/modules/app.py +6 -6
  2. src/modules/link.py +31 -26
src/modules/app.py CHANGED
@@ -12,22 +12,22 @@ For more information, see
12
  - https://app.bitly.com/settings/api
13
  '''
14
 
15
- def calculate_positions(image_count, card_size=(91, 55), page_size=(210, 297), padding=(14, 11)):
16
  positions = []
17
  x, y = 0, 0
18
  pos_px, pos_py = padding
19
 
20
  for i in range(image_count):
21
- if x + card_size[0] > page_size[0]: # Check for horizontal overflow
22
  x = 0
23
- y += card_size[1] + pos_py
24
 
25
- if y + card_size[1] > page_size[1]: # Check for vertical overflow
26
  x = 0
27
  y = 0
28
 
29
  positions.append((x, y, pos_px, pos_py))
30
- x += card_size[0] + pos_px
31
  print(positions)
32
  return positions
33
 
@@ -62,8 +62,8 @@ with gr.Blocks() as demo:
62
  pos_df = gr.Dataframe(headers=headers, label="Positions")
63
 
64
  cm_img_input.change(update_df, cm_img_input, pos_df)
 
65
 
66
- # positions = [(10, 10), (int(0.9 * s * 3.7795), int(0.9 * 55 * 3.7795))]
67
  with gr.Column():
68
  file_output = gr.File(label="Download ZIP")
69
  with gr.Accordion(open=True, label="Gallery"):
 
12
  - https://app.bitly.com/settings/api
13
  '''
14
 
15
+ def calculate_positions(image_count, item_size=(20, 20), page_size=(91, 55), padding=(10, 10)):
16
  positions = []
17
  x, y = 0, 0
18
  pos_px, pos_py = padding
19
 
20
  for i in range(image_count):
21
+ if x + item_size[0] > page_size[0]: # Check for horizontal overflow
22
  x = 0
23
+ y += item_size[1] + pos_py
24
 
25
+ if y + item_size[1] > page_size[1]: # Check for vertical overflow
26
  x = 0
27
  y = 0
28
 
29
  positions.append((x, y, pos_px, pos_py))
30
+ x += item_size[0] + pos_px
31
  print(positions)
32
  return positions
33
 
 
62
  pos_df = gr.Dataframe(headers=headers, label="Positions")
63
 
64
  cm_img_input.change(update_df, cm_img_input, pos_df)
65
+ idv_img_input.change(update_df, idv_img_input, pos_df)
66
 
 
67
  with gr.Column():
68
  file_output = gr.File(label="Download ZIP")
69
  with gr.Accordion(open=True, label="Gallery"):
src/modules/link.py CHANGED
@@ -166,41 +166,46 @@ class UrlProcessor:
166
  # encoded_string = base64.b64encode(image_file.read()).decode()
167
 
168
  os.makedirs(f'{tmpd}/img/cards', exist_ok=True)
169
- for idx, (qr, indv) in enumerate(itertools.product(qr_pngs, individual_images), start=1):
170
- try:
171
- i = int(idx) - 1
172
- print(i)
173
- pos_x = int(positions_df.loc[i, 'PosX'])
174
- pos_y = int(positions_df.loc[i, 'PosY'])
175
 
176
- size = (int(91 * 3.7795), int(55 * 3.7795))
 
 
177
 
178
- if common_images:
179
- for common_img in common_images:
180
- layer = processor.combine_images(layer, common_img, size, (pos_x, pos_y))
181
- if individual_images:
182
- layer = processor.combine_images(layer, indv, size, (pos_x, pos_y))
 
183
 
184
- if qr:
185
- qr_size = (int(size[0] * 0.1), int(size[1] * 0.1))
186
- qr_pos = (int(0.9 * pos_x * 3.7795), int(0.9 * pos_y * 3.7795))
187
- layer = processor.combine_images(layer, qr, qr_size, qr_pos)
188
 
 
 
 
 
 
189
 
190
- card_png_path = f'img/cards/CD{idx:05d}.png'
191
- card_path = os.path.join(tmpd, card_png_path)
 
 
192
 
193
- layer.save(card_path, format="PNG")
194
- card_pngs.append(card_path)
195
 
196
- with open(card_path, "rb") as image_file:
197
- encoded_string = base64.b64encode(image_file.read()).decode()
198
 
199
- card_html = f'<img src="data:image/png;base64,{encoded_string}" alt="Card"> '
200
- card_htmls.append(card_html)
201
 
202
- except Exception as e:
203
- raise Exception(f"Error combining images: {e}")
 
 
 
 
 
 
204
 
205
 
206
  try:
 
166
  # encoded_string = base64.b64encode(image_file.read()).decode()
167
 
168
  os.makedirs(f'{tmpd}/img/cards', exist_ok=True)
 
 
 
 
 
 
169
 
170
+ if qr_pngs is not None or individual_images is not None:
171
+ qr_pngs = qr_pngs if qr_pngs is not None else []
172
+ individual_images = individual_images if individual_images is not None else []
173
 
174
+ for idx, (qr, indv) in enumerate(itertools.product(qr_pngs, individual_images), start=1):
175
+ try:
176
+ i = int(idx) - 1
177
+ print(i)
178
+ pos_x = int(positions_df.loc[i, 'PosX'])
179
+ pos_y = int(positions_df.loc[i, 'PosY'])
180
 
181
+ size = (int(91 * 3.7795), int(55 * 3.7795))
 
 
 
182
 
183
+ if common_images:
184
+ for common_img in common_images:
185
+ layer = processor.combine_images(layer, common_img, size, (pos_x, pos_y))
186
+ if individual_images:
187
+ layer = processor.combine_images(layer, indv, size, (pos_x, pos_y))
188
 
189
+ if qr:
190
+ qr_size = (int(size[0] * 0.1), int(size[1] * 0.1))
191
+ qr_pos = (int(0.9 * pos_x * 3.7795), int(0.9 * pos_y * 3.7795))
192
+ layer = processor.combine_images(layer, qr, qr_size, qr_pos)
193
 
 
 
194
 
195
+ card_png_path = f'img/cards/CD{idx:05d}.png'
196
+ card_path = os.path.join(tmpd, card_png_path)
197
 
198
+ layer.save(card_path, format="PNG")
199
+ card_pngs.append(card_path)
200
 
201
+ with open(card_path, "rb") as image_file:
202
+ encoded_string = base64.b64encode(image_file.read()).decode()
203
+
204
+ card_html = f'<img src="data:image/png;base64,{encoded_string}" alt="Card"> '
205
+ card_htmls.append(card_html)
206
+
207
+ except Exception as e:
208
+ raise Exception(f"Error combining images: {e}")
209
 
210
 
211
  try: