(directory)
| 189 | |
| 190 | # 根据config配置裁剪图片 |
| 191 | def crop_iframe(directory): |
| 192 | display_cnt = utils.get_display_count() |
| 193 | display_info = utils.get_display_info() |
| 194 | display_all_full_size = display_info[0] |
| 195 | display_info = display_info[1:] |
| 196 | ocr_image_crop_URBL = config.ocr_image_crop_URBL |
| 197 | top_percent = [] |
| 198 | bottom_percent = [] |
| 199 | left_percent = [] |
| 200 | right_percent = [] |
| 201 | if len(ocr_image_crop_URBL) < display_cnt * 4: # 不足时补齐参数 slot |
| 202 | for i in range(display_cnt - (len(ocr_image_crop_URBL) // 4)): |
| 203 | ocr_image_crop_URBL.extend([6, 6, 6, 3]) |
| 204 | config.set_and_save_config("ocr_image_crop_URBL", ocr_image_crop_URBL) |
| 205 | for i in range(display_cnt): |
| 206 | top_percent.append(config.ocr_image_crop_URBL[i * 4 + 0] * 0.01) |
| 207 | bottom_percent.append(config.ocr_image_crop_URBL[i * 4 + 1] * 0.01) |
| 208 | left_percent.append(config.ocr_image_crop_URBL[i * 4 + 2] * 0.01) |
| 209 | right_percent.append(config.ocr_image_crop_URBL[i * 4 + 3] * 0.01) |
| 210 | |
| 211 | # 获取目录下所有图片文件 |
| 212 | image_files = [f for f in os.listdir(directory) if f.endswith((".jpg", ".jpeg", ".png"))] |
| 213 | |
| 214 | # 循环处理每个图片文件 |
| 215 | for file_name in image_files: |
| 216 | # 构建图片文件的完整路径 |
| 217 | file_path = os.path.join(directory, file_name) |
| 218 | if "_cropped" in file_name: |
| 219 | continue |
| 220 | |
| 221 | image = Image.open(file_path) |
| 222 | draw = ImageDraw.Draw(image) |
| 223 | |
| 224 | # 校验图片 |
| 225 | img_width, img_height = image.size |
| 226 | fallback_condition = False |
| 227 | display_index = -1 |
| 228 | if not config.record_single_display_index <= len(display_info): # 当记录的显示器索引不存在于所有显示器中时,当作一个完整显示器使用默认参数处理 |
| 229 | fallback_condition = True |
| 230 | elif config.multi_display_record_strategy == "single": |
| 231 | # 当图片分辨率符合其中某个显示器的完整尺寸时,对其单独处理 |
| 232 | for i in display_info: # 逐个检查显示器,是否与config index吻合 |
| 233 | if ( |
| 234 | abs(display_info[config.record_single_display_index - 1]["width"] - img_width) < 2 |
| 235 | and abs(display_info[config.record_single_display_index - 1]["height"] - img_height) < 2 |
| 236 | ): |
| 237 | monitors_info_process = [display_info[config.record_single_display_index - 1]] |
| 238 | display_index = config.record_single_display_index - 1 |
| 239 | fallback_condition = False |
| 240 | break |
| 241 | else: |
| 242 | fallback_condition = True |
| 243 | # 当显示器配置为录制所有显示器、但与图片不符时,执行fallback策略:当作一个显示器、使用默认涂黑范围处理 |
| 244 | elif config.multi_display_record_strategy == "all" and ( |
| 245 | abs(display_all_full_size["width"] - img_width) > 10 or abs(display_all_full_size["height"] - img_height) > 10 |
| 246 | ): |
| 247 | fallback_condition = True |
| 248 |
no test coverage detected