admin commited on
Commit
b5e972d
·
1 Parent(s): 06232c2

add features: global size

Browse files
Files changed (3) hide show
  1. src/modules/app.py +10 -4
  2. src/modules/link.py +12 -11
  3. src/modules/main.py +5 -7
src/modules/app.py CHANGED
@@ -13,9 +13,10 @@ For more information, see
13
  - https://app.bitly.com/settings/api
14
  '''
15
 
16
- def calculate_layout(image_count, item_size=(40, 40), page_size=(91, 55), position=(30, 67)):
17
  layout = []
18
  x, y = 0, 0
 
19
  pos_px, pos_py = position
20
  size_x, size_y = item_size
21
  size_px, size_py = item_size
@@ -31,7 +32,6 @@ def calculate_layout(image_count, item_size=(40, 40), page_size=(91, 55), positi
31
 
32
  layout.append((image_count, x, y, pos_px, pos_py, size_x, size_y, size_px, size_py))
33
  x += item_size[0] + pos_px
34
- # print(layout)
35
  return layout
36
 
37
  with gr.Blocks() as demo:
@@ -57,6 +57,11 @@ with gr.Blocks() as demo:
57
  with gr.Row():
58
  shorten_checkbox = gr.Checkbox(label="Shorten URL", value=False)
59
  qr_checkbox = gr.Checkbox(label="Generate QR Code", value=True)
 
 
 
 
 
60
  with gr.Row():
61
  clear_button = gr.ClearButton(txt_input)
62
  submit_button = gr.Button("Process URLs", variant='primary')
@@ -112,7 +117,6 @@ with gr.Blocks() as demo:
112
  count_url.change(update_df, count_url, df)
113
  cm_img_input.change(update_df, cm_img_input, df)
114
  idv_img_input.change(update_df, idv_img_input, df)
115
-
116
  submit_button.click(
117
  UrlProcessor.shorten_and_generate_qr,
118
  inputs=[
@@ -123,7 +127,9 @@ with gr.Blocks() as demo:
123
  qr_checkbox,
124
  cm_img_input,
125
  idv_img_input,
126
- df,
 
 
127
  ],
128
  outputs=[preview_output, gallery_output, file_output, json_output]
129
  )
 
13
  - https://app.bitly.com/settings/api
14
  '''
15
 
16
+ def calculate_layout(image_count, item_size=(40, 40), page_size=(91, 55), pos=(300, 200), position=(30, 67)):
17
  layout = []
18
  x, y = 0, 0
19
+ pos_x, pos_y = pos
20
  pos_px, pos_py = position
21
  size_x, size_y = item_size
22
  size_px, size_py = item_size
 
32
 
33
  layout.append((image_count, x, y, pos_px, pos_py, size_x, size_y, size_px, size_py))
34
  x += item_size[0] + pos_px
 
35
  return layout
36
 
37
  with gr.Blocks() as demo:
 
57
  with gr.Row():
58
  shorten_checkbox = gr.Checkbox(label="Shorten URL", value=False)
59
  qr_checkbox = gr.Checkbox(label="Generate QR Code", value=True)
60
+
61
+ with gr.Row():
62
+ sx = gr.Number(label="Card Width", minimum=1, maximum=210, value=91, step=1)
63
+ sy = gr.Number(label="Card Height", minimum=1, maximum=297, value=55, step=1)
64
+
65
  with gr.Row():
66
  clear_button = gr.ClearButton(txt_input)
67
  submit_button = gr.Button("Process URLs", variant='primary')
 
117
  count_url.change(update_df, count_url, df)
118
  cm_img_input.change(update_df, cm_img_input, df)
119
  idv_img_input.change(update_df, idv_img_input, df)
 
120
  submit_button.click(
121
  UrlProcessor.shorten_and_generate_qr,
122
  inputs=[
 
127
  qr_checkbox,
128
  cm_img_input,
129
  idv_img_input,
130
+ sx,
131
+ sy,
132
+ df
133
  ],
134
  outputs=[preview_output, gallery_output, file_output, json_output]
135
  )
src/modules/link.py CHANGED
@@ -93,7 +93,7 @@ class UrlProcessor:
93
  return None, None, {"error": str(e)}
94
 
95
 
96
- def shorten_and_generate_qr(access_token, api_url, text, shorten, generate_qr, common_images, individual_images, positions_df):
97
  bitly = UrlProcessor(access_token, api_url)
98
 
99
  txt = ''
@@ -179,8 +179,10 @@ class UrlProcessor:
179
  except Exception as e:
180
  results.append((str(e), url))
181
 
 
 
 
182
 
183
- processor = ImageProcessor()
184
  layer = processor.create_layer()
185
 
186
  os.makedirs(f'{tmpd}/img/cards', exist_ok=True)
@@ -215,17 +217,16 @@ class UrlProcessor:
215
 
216
  if qr or indv:
217
  try:
218
- pos_x = int(positions_df.loc[idx, 'PosX'])
219
- pos_y = int(positions_df.loc[idx, 'PosY'])
220
- pos_px = int(positions_df.loc[idx, 'PosPx'])
221
- pos_py = int(positions_df.loc[idx, 'PosPy'])
222
 
223
- size_x = int(positions_df.loc[idx, 'SizeX'])
224
- size_y = int(positions_df.loc[idx, 'SizeY'])
225
- size_px = int(positions_df.loc[idx, 'SizePx'])
226
- size_py = int(positions_df.loc[idx, 'SizePy'])
227
 
228
- size = (int(91 * 3.7795), int(55 * 3.7795))
229
  if common_images:
230
  for common_img in common_images:
231
  layer = processor.combine_images(layer, common_img, size, (0, 0))
 
93
  return None, None, {"error": str(e)}
94
 
95
 
96
+ def shorten_and_generate_qr(access_token, api_url, text, shorten, generate_qr, common_images, individual_images, sx, sy, df):
97
  bitly = UrlProcessor(access_token, api_url)
98
 
99
  txt = ''
 
179
  except Exception as e:
180
  results.append((str(e), url))
181
 
182
+ size = (int(sx * 3.7795), int(sy * 3.7795))
183
+
184
+ processor = ImageProcessor(size)
185
 
 
186
  layer = processor.create_layer()
187
 
188
  os.makedirs(f'{tmpd}/img/cards', exist_ok=True)
 
217
 
218
  if qr or indv:
219
  try:
220
+ pos_x = int(df.loc[idx, 'PosX'])
221
+ pos_y = int(df.loc[idx, 'PosY'])
222
+ pos_px = int(df.loc[idx, 'PosPx'])
223
+ pos_py = int(df.loc[idx, 'PosPy'])
224
 
225
+ size_x = int(df.loc[idx, 'SizeX'])
226
+ size_y = int(df.loc[idx, 'SizeY'])
227
+ size_px = int(df.loc[idx, 'SizePx'])
228
+ size_py = int(df.loc[idx, 'SizePy'])
229
 
 
230
  if common_images:
231
  for common_img in common_images:
232
  layer = processor.combine_images(layer, common_img, size, (0, 0))
src/modules/main.py CHANGED
@@ -11,18 +11,16 @@ class TextProcessor:
11
 
12
 
13
  class ImageProcessor:
14
- def __init__(self):
15
  _, self.temp_dir = Utils.get_tempdir()
 
16
 
17
- def create_layer(layout='horizontal', size=(91 * 3.7795, 55 * 3.7795)):
18
  ts, temp_dir = Utils.get_tempdir()
19
- size = (int(size[0]), int(size[1])) # Convert to integers
20
  img = Image.new('RGBA', size, (255, 255, 255, 0))
21
  draw = ImageDraw.Draw(img)
22
- if layout == 'vertical':
23
- draw.rectangle([(0, 0), (size[0], size[1])], outline="lightgray")
24
- elif layout == 'horizontal':
25
- draw.rectangle([(0, 0), (size[0], size[1])], outline="lightgray")
26
 
27
  return img
28
 
 
11
 
12
 
13
  class ImageProcessor:
14
+ def __init__(self, size):
15
  _, self.temp_dir = Utils.get_tempdir()
16
+ self.size = size
17
 
18
+ def create_layer(self, layout='horizontal'):
19
  ts, temp_dir = Utils.get_tempdir()
20
+ size = (int(self.size[0]), int(self.size[1])) # Convert to integers
21
  img = Image.new('RGBA', size, (255, 255, 255, 0))
22
  draw = ImageDraw.Draw(img)
23
+ draw.rectangle([(0, 0), (self.size[0], self.size[1])], outline="lightgray")
 
 
 
24
 
25
  return img
26