admin commited on
Commit
f157c01
·
1 Parent(s): 09d63fd

add scale param

Browse files
Files changed (3) hide show
  1. src/modules/app.py +13 -13
  2. src/modules/link.py +34 -37
  3. style.css +2 -1
src/modules/app.py CHANGED
@@ -14,25 +14,24 @@ For more information, see
14
  - https://app.bitly.com/settings/api
15
  '''
16
 
17
- def calculate_layout(image_count, item_size=(40, 40), page_size=(91, 55), pos=(300, 200), position=(30, 67)):
18
  layout = []
19
- x, y = 0, 0
20
  pos_x, pos_y = pos
21
  pos_px, pos_py = position
22
  size_x, size_y = item_size
23
  size_px, size_py = item_size
24
 
25
  for i in range(image_count):
26
- if x + item_size[0] > page_size[0]: # Check for horizontal overflow
27
- x = 0
28
- y += item_size[1] + pos_py
29
 
30
- if y + item_size[1] > page_size[1]: # Check for vertical overflow
31
- x = 0
32
- y = 0
33
 
34
- layout.append((image_count, x, y, pos_px, pos_py, size_x, size_y, size_px, size_py))
35
- x += item_size[0] + pos_px
36
  return layout
37
 
38
  with gr.Blocks() as demo:
@@ -49,7 +48,7 @@ with gr.Blocks() as demo:
49
  if txt['files']:
50
  for f in txt['files']:
51
  with open(f) as f:
52
- text += f.read()
53
  if txt['text']:
54
  text += txt['text']
55
  urls = re.findall(r'http[s]?://\S+', text)
@@ -62,6 +61,7 @@ with gr.Blocks() as demo:
62
  with gr.Row():
63
  sx = gr.Number(label="Card Width", minimum=1, maximum=210, value=91, step=1)
64
  sy = gr.Number(label="Card Height", minimum=1, maximum=297, value=55, step=1)
 
65
 
66
  with gr.Row():
67
  clear_button = gr.ClearButton(txt_input)
@@ -106,8 +106,7 @@ with gr.Blocks() as demo:
106
  ['demo/demo.jpg'],
107
  ['demo/logo.png']
108
  ],
109
- # [{'files': ['demo/demo.md', 'demo/demo2.md']},
110
- [{'files': ['demo/demo.md']},
111
  ['demo/demo.jpg'],
112
  ['demo/img/number-1.png', 'demo/img/number-2.png', 'demo/img/number-3.png', 'demo/img/number-4.png', 'demo/img/number-5.png', ]
113
  ]
@@ -134,6 +133,7 @@ with gr.Blocks() as demo:
134
  idv_img_input,
135
  sx,
136
  sy,
 
137
  df
138
  ],
139
  outputs=[preview_output, gallery_output, file_output, json_output]
 
14
  - https://app.bitly.com/settings/api
15
  '''
16
 
17
+ def calculate_layout(image_count, item_size=(40, 40), page_size=(91, 55), pos=(280, 20), position=(30, 67)):
18
  layout = []
 
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
23
 
24
  for i in range(image_count):
25
+ if pos_x + item_size[0] > page_size[0]: # Check for horizontal overflow
26
+ pos_x = 0
27
+ pos_y += item_size[1] + pos_py
28
 
29
+ if pos_y + item_size[1] > page_size[1]: # Check for vertical overflow
30
+ pos_x = 0
31
+ pos_y = 0
32
 
33
+ layout.append((image_count, pos_x, pos_y, pos_px, pos_py, size_x, size_y, size_px, size_py))
34
+ pos_x += item_size[0] + pos_px
35
  return layout
36
 
37
  with gr.Blocks() as demo:
 
48
  if txt['files']:
49
  for f in txt['files']:
50
  with open(f) as f:
51
+ text += f.read() + '\n\n'
52
  if txt['text']:
53
  text += txt['text']
54
  urls = re.findall(r'http[s]?://\S+', text)
 
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
+ scale = gr.Number(label="Scale", minimum=1, maximum=10, step=0.1)
65
 
66
  with gr.Row():
67
  clear_button = gr.ClearButton(txt_input)
 
106
  ['demo/demo.jpg'],
107
  ['demo/logo.png']
108
  ],
109
+ [{'files': ['demo/demo.md', 'demo/demo2.md']},
 
110
  ['demo/demo.jpg'],
111
  ['demo/img/number-1.png', 'demo/img/number-2.png', 'demo/img/number-3.png', 'demo/img/number-4.png', 'demo/img/number-5.png', ]
112
  ]
 
133
  idv_img_input,
134
  sx,
135
  sy,
136
+ scale,
137
  df
138
  ],
139
  outputs=[preview_output, gallery_output, file_output, json_output]
src/modules/link.py CHANGED
@@ -93,32 +93,30 @@ 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, sx, sy, df):
97
  bitly = UrlProcessor(access_token, api_url)
 
 
 
 
 
 
 
 
 
 
98
 
 
99
  txt = ''
100
  if text['files']:
101
  for f in text['files']:
102
  with open(f) as f:
103
- txt += f.read()
104
  if text['text']:
105
  txt += text['text']
106
 
107
  urls = re.findall(r'http[s]?://\S+', txt)
108
-
109
- results = []
110
- ts, tmpd = Utils.get_tempdir()
111
-
112
- anno_txt = 'test'
113
  markdown_links = txt
114
- all_json_responses = []
115
- qr_svgs = []
116
- qr_pngs = []
117
- card_htmls = []
118
- card_pngs = []
119
- layer_output_paths = []
120
- index_path = 'index.html'
121
- css_path = 'style.css'
122
 
123
  if urls is not None:
124
  urls = urls if urls is not None else []
@@ -180,7 +178,7 @@ class UrlProcessor:
180
  except Exception as e:
181
  results.append((str(e), url))
182
 
183
- size = (int(sx * 3.7795), int(sy * 3.7795))
184
 
185
  processor = ImageProcessor(size)
186
 
@@ -197,7 +195,6 @@ class UrlProcessor:
197
  else:
198
  num_iterations = 1
199
 
200
-
201
  # -------------------content start --------------------------------
202
  index_html = f'<html><head><link rel="stylesheet" type="text/css" href="{css_path}"></head><body>\n'
203
 
@@ -218,40 +215,40 @@ class UrlProcessor:
218
 
219
  if qr or indv:
220
  try:
221
- pos_x = int(df.loc[idx, 'PosX'])
222
- pos_y = int(df.loc[idx, 'PosY'])
223
- pos_px = int(df.loc[idx, 'PosPx'])
224
- pos_py = int(df.loc[idx, 'PosPy'])
225
 
226
- size_x = int(df.loc[idx, 'SizeX'])
227
- size_y = int(df.loc[idx, 'SizeY'])
228
- size_px = int(df.loc[idx, 'SizePx'])
229
- size_py = int(df.loc[idx, 'SizePy'])
230
 
231
  if common_images:
232
- os.makedirs(f'{tmpd}/img/layer/common', exist_ok=True)
233
  for common_img in common_images:
234
  layer = processor.combine_images(layer, common_img, size, (0, 0))
235
- layer_path = os.path.join(tmpd, f'img/layer/common/CM{idx:05d}.png')
236
- layer.save(layer_path, format="PNG")
237
- layer_output_paths.append(layer_path)
238
 
239
  if indv:
240
- os.makedirs(f'{tmpd}/img/layer/individual', exist_ok=True)
241
  layer = processor.combine_images(layer, indv, (size_x, size_y), (pos_x, pos_y))
242
- layer_path = os.path.join(tmpd, f'img/layer/individual/ID{idx:05d}.png')
243
- layer.save(layer_path, format="PNG")
244
- layer_output_paths.append(layer_path)
245
 
246
  # if anno_txt:
247
  # layer = processor.combine_txt(layer, anno_txt, (size_px, size_py), (pos_px, pos_py))
248
 
249
  if qr:
250
- os.makedirs(f'{tmpd}/img/layer/qr', exist_ok=True)
251
  layer = processor.combine_images(layer, qr, (size_px, size_py), (pos_px, pos_py))
252
- layer_path = os.path.join(tmpd, f'img/layer/qr/QR{idx:05d}.png')
253
- layer.save(layer_path, format="PNG")
254
- layer_output_paths.append(layer_path)
255
 
256
  card_png_path = f'img/cards/CD{idx:05d}.png'
257
  card_path = os.path.join(tmpd, card_png_path)
 
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, scale, df):
97
  bitly = UrlProcessor(access_token, api_url)
98
+ index_path = 'index.html'
99
+ css_path = 'style.css'
100
+ results = []
101
+ ts, tmpd = Utils.get_tempdir()
102
+ all_json_responses = []
103
+ qr_svgs = []
104
+ qr_pngs = []
105
+ card_htmls = []
106
+ card_pngs = []
107
+ layer_output_paths = []
108
 
109
+ # TODO: Rotate Text follows each files?
110
  txt = ''
111
  if text['files']:
112
  for f in text['files']:
113
  with open(f) as f:
114
+ txt += f.read() + '\n\n'
115
  if text['text']:
116
  txt += text['text']
117
 
118
  urls = re.findall(r'http[s]?://\S+', txt)
 
 
 
 
 
119
  markdown_links = txt
 
 
 
 
 
 
 
 
120
 
121
  if urls is not None:
122
  urls = urls if urls is not None else []
 
178
  except Exception as e:
179
  results.append((str(e), url))
180
 
181
+ size = (int(sx * 3.7795 * scale), int(sy * 3.7795 * scale))
182
 
183
  processor = ImageProcessor(size)
184
 
 
195
  else:
196
  num_iterations = 1
197
 
 
198
  # -------------------content start --------------------------------
199
  index_html = f'<html><head><link rel="stylesheet" type="text/css" href="{css_path}"></head><body>\n'
200
 
 
215
 
216
  if qr or indv:
217
  try:
218
+ pos_x = int(int(df.loc[idx, 'PosX']) * scale)
219
+ pos_y = int(int(df.loc[idx, 'PosY']) * scale)
220
+ pos_px = int(int(df.loc[idx, 'PosPx']) * scale)
221
+ pos_py = int(int(df.loc[idx, 'PosPy']) * scale)
222
 
223
+ size_x = int(int(df.loc[idx, 'SizeX']) * scale)
224
+ size_y = int(int(df.loc[idx, 'SizeY']) * scale)
225
+ size_px = int(int(df.loc[idx, 'SizePx']) * scale)
226
+ size_py = int(int(df.loc[idx, 'SizePy']) * scale)
227
 
228
  if common_images:
229
+ # os.makedirs(f'{tmpd}/img/layer/common', exist_ok=True)
230
  for common_img in common_images:
231
  layer = processor.combine_images(layer, common_img, size, (0, 0))
232
+ # layer_path = os.path.join(tmpd, f'img/layer/common/CM{idx:05d}.png')
233
+ # layer.save(layer_path, format="PNG")
234
+ # layer_output_paths.append(layer_path)
235
 
236
  if indv:
237
+ # os.makedirs(f'{tmpd}/img/layer/individual', exist_ok=True)
238
  layer = processor.combine_images(layer, indv, (size_x, size_y), (pos_x, pos_y))
239
+ # layer_path = os.path.join(tmpd, f'img/layer/individual/ID{idx:05d}.png')
240
+ # layer.save(layer_path, format="PNG")
241
+ # layer_output_paths.append(layer_path)
242
 
243
  # if anno_txt:
244
  # layer = processor.combine_txt(layer, anno_txt, (size_px, size_py), (pos_px, pos_py))
245
 
246
  if qr:
247
+ # os.makedirs(f'{tmpd}/img/layer/qr', exist_ok=True)
248
  layer = processor.combine_images(layer, qr, (size_px, size_py), (pos_px, pos_py))
249
+ # layer_path = os.path.join(tmpd, f'img/layer/qr/QR{idx:05d}.png')
250
+ # layer.save(layer_path, format="PNG")
251
+ # layer_output_paths.append(layer_path)
252
 
253
  card_png_path = f'img/cards/CD{idx:05d}.png'
254
  card_path = os.path.join(tmpd, card_png_path)
style.css CHANGED
@@ -17,6 +17,7 @@
17
 
18
  body {
19
  font-size: 10pt;
 
20
  font-family: Alegreya, "Times New Roman", "游明朝", YuMincho, "Hiragino Mincho ProN", "MS PMincho", "Crimson Text", serif;
21
  display: grid;
22
  grid-template-columns: repeat(auto-fit, minmax(var(--card-width), 1fr));
@@ -33,7 +34,7 @@ p {
33
  }
34
 
35
  img {
36
- opacity: 0.1;
37
  }
38
 
39
  .card {
 
17
 
18
  body {
19
  font-size: 10pt;
20
+ color: #666;
21
  font-family: Alegreya, "Times New Roman", "游明朝", YuMincho, "Hiragino Mincho ProN", "MS PMincho", "Crimson Text", serif;
22
  display: grid;
23
  grid-template-columns: repeat(auto-fit, minmax(var(--card-width), 1fr));
 
34
  }
35
 
36
  img {
37
+ opacity: 1;
38
  }
39
 
40
  .card {