Fermer les images PIL et borner le cache de cartes de localisation
This commit is contained in:
@ -660,8 +660,8 @@ def generate_thumbnail(src_path, thumb_path, max_size=256, mid_path=None,
|
|||||||
return source.resize((max(1, int(source.size[0] * scale)),
|
return source.resize((max(1, int(source.size[0] * scale)),
|
||||||
max(1, int(source.size[1] * scale))), resample)
|
max(1, int(source.size[1] * scale))), resample)
|
||||||
|
|
||||||
img = PILImage.open(str(src_path))
|
with PILImage.open(str(src_path)) as _src_img:
|
||||||
img = img.convert('RGB')
|
img = _src_img.convert('RGB')
|
||||||
Path(thumb_path).parent.mkdir(parents=True, exist_ok=True)
|
Path(thumb_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
if mid_path is not None:
|
if mid_path is not None:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -328,6 +328,10 @@ def _download_location_map(min_x, max_x, min_y, max_y):
|
|||||||
'min_y': context_min_y, 'max_y': context_max_y,
|
'min_y': context_min_y, 'max_y': context_max_y,
|
||||||
}
|
}
|
||||||
cached = (result, bounds)
|
cached = (result, bounds)
|
||||||
|
# Éviction FIFO : chaque entrée ~12 Mo (carte ~30 km au zoom 10) —
|
||||||
|
# un run long sur plusieurs zones ne doit pas empiler sans limite
|
||||||
|
while len(_location_map_cache) >= 4:
|
||||||
|
_location_map_cache.pop(next(iter(_location_map_cache)))
|
||||||
_location_map_cache[cache_key] = cached
|
_location_map_cache[cache_key] = cached
|
||||||
return cached
|
return cached
|
||||||
|
|
||||||
@ -942,7 +946,8 @@ def generate_pdf_report(basename, vis_dir, pdf_dir, resolution):
|
|||||||
|
|
||||||
for i, f in enumerate(situ_files):
|
for i, f in enumerate(situ_files):
|
||||||
ax = fig.add_subplot(gs[0, i])
|
ax = fig.add_subplot(gs[0, i])
|
||||||
img = np.array(PILImage.open(str(f)).convert('RGB'))
|
with PILImage.open(str(f)) as _pf:
|
||||||
|
img = np.array(_pf.convert('RGB'))
|
||||||
ax.imshow(img)
|
ax.imshow(img)
|
||||||
ax.axis('off')
|
ax.axis('off')
|
||||||
title = f.stem.replace(basename + '_', '').replace('_', ' ').title()
|
title = f.stem.replace(basename + '_', '').replace('_', ' ').title()
|
||||||
@ -966,7 +971,8 @@ def generate_pdf_report(basename, vis_dir, pdf_dir, resolution):
|
|||||||
|
|
||||||
for i, f in enumerate(page_files):
|
for i, f in enumerate(page_files):
|
||||||
ax = fig.add_subplot(gs[0, i])
|
ax = fig.add_subplot(gs[0, i])
|
||||||
img = np.array(PILImage.open(str(f)).convert('RGB'))
|
with PILImage.open(str(f)) as _pf:
|
||||||
|
img = np.array(_pf.convert('RGB'))
|
||||||
ax.imshow(img)
|
ax.imshow(img)
|
||||||
ax.axis('off')
|
ax.axis('off')
|
||||||
title = f.stem.replace(basename + '_', '').replace('_', ' ').title()
|
title = f.stem.replace(basename + '_', '').replace('_', ' ').title()
|
||||||
|
|||||||
Reference in New Issue
Block a user