From efbce943b65bb7084e1f0ef23f95c4569bb23a26 Mon Sep 17 00:00:00 2001 From: Akira Date: Sun, 10 Nov 2024 01:35:44 +0900 Subject: [PATCH] Fix goalimage scale --- SumasenLibs/excel_lib/sumaexcel/sumaexcel.py | 35 ++++++++++--------- docbase/~$certificate_template.xlsx | Bin 0 -> 165 bytes rog/.DS_Store | Bin 8196 -> 8196 bytes 3 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 docbase/~$certificate_template.xlsx diff --git a/SumasenLibs/excel_lib/sumaexcel/sumaexcel.py b/SumasenLibs/excel_lib/sumaexcel/sumaexcel.py index 6c8c1ca..3d2ca21 100644 --- a/SumasenLibs/excel_lib/sumaexcel/sumaexcel.py +++ b/SumasenLibs/excel_lib/sumaexcel/sumaexcel.py @@ -357,9 +357,24 @@ class SumasenExcel: elif re.search(r'\.(jpg|jpeg|png|gif|bmp|mpo)$', value, re.I): return os.path.join("/app/media/compressed", value) return None + + def get_image_scale(value): + if value.startswith('https://'): + scale=1.0 + return scale + elif value.startswith('checkin/'): + scale=1.0 + return scale + elif value.startswith('goals/'): + scale=4.0 + return scale + else: + scale=1.0 + return scale # 画像パスを取得 image_path = get_image_path(field_value) + scale = get_image_scale(field_value) if image_path and os.path.exists(image_path): try: @@ -379,7 +394,6 @@ class SumasenExcel: # ワークシートを取得 worksheet = cell.parent - logging.info('step-1') try: # 列の幅を取得(文字単位からピクセルに変換) column_letter = get_column_letter(cell.column) @@ -388,7 +402,6 @@ class SumasenExcel: except Exception: cell_width = 100 # デフォルト値 - logging.info('step-2') try: # 行の高さを取得(ポイント単位からピクセルに変換) row_height = worksheet.row_dimensions[cell.row].height @@ -396,7 +409,6 @@ class SumasenExcel: except Exception: cell_height = 20 # デフォルト値 - logging.info('step-3') # マージンの設定(ピクセル単位) margin_horizontal = 4 # 左右のマージン margin_vertical = 2 # 上下のマージン @@ -405,7 +417,6 @@ class SumasenExcel: effective_cell_width = cell_width - (margin_horizontal * 2) effective_cell_height = cell_height - (margin_vertical * 2) - logging.info('step-4') # 最小サイズを設定(マージンを考慮) effective_cell_width = max(effective_cell_width, 92) # 100 - (4 * 2) effective_cell_height = max(effective_cell_height, 16) # 20 - (2 * 2) @@ -416,23 +427,21 @@ class SumasenExcel: effective_cell_width = min(effective_cell_width, max_width) effective_cell_height = min(effective_cell_height, max_height) - logging.info('step-5') # アスペクト比を保持しながらリサイズ img_width, img_height = img.size img_aspect = img_width / img_height cell_aspect = effective_cell_width / effective_cell_height if img_aspect > cell_aspect: - width = effective_cell_width - height = int(width / img_aspect) + width = effective_cell_width*scale + height = int(width / img_aspect)*scale else: - height = effective_cell_height - width = int(height * img_aspect) + height = effective_cell_height*scale + width = int(height * img_aspect)*scale # 画像処理部分の修正 #from openpyxl.utils.units import pixels_to_EMU - logging.info('step-6') # 画像をリサイズ img_resized = img.resize((width, height), Image.BICUBIC) @@ -441,8 +450,6 @@ class SumasenExcel: img_resized.save(img_byte_arr, format='JPEG', quality=85, optimize=True) img_byte_arr.seek(0) - - logging.info('step-7') # OpenPyXLのImageオブジェクトを作成 excel_image = XLImage(img_byte_arr) @@ -454,7 +461,6 @@ class SumasenExcel: from openpyxl.drawing.spreadsheet_drawing import OneCellAnchor, AnchorMarker from openpyxl.drawing.xdr import XDRPositiveSize2D - logging.info('step-8') marker = AnchorMarker( col=cell.column - 1, colOff=pixels_to_EMU(margin_horizontal), @@ -471,13 +477,10 @@ class SumasenExcel: anchor = OneCellAnchor(_from=marker, ext=size) excel_image.anchor = anchor - - logging.info('step-9') # 画像をワークシートに追加 worksheet.add_image(excel_image) #cell.parent.add_image(excel_image) - logging.info('step-A') # メモリ解放 #img_byte_arr.close() diff --git a/docbase/~$certificate_template.xlsx b/docbase/~$certificate_template.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..52abcffbccd9a04a06f2b02e94aadf62824b7593 GIT binary patch literal 165 xcmd<_&8$o;NmOvm&MZn)AR6#6_%dWNR5BzolmM{;gCj#WkY5C5D**Y_g#Zl86LSCn literal 0 HcmV?d00001 diff --git a/rog/.DS_Store b/rog/.DS_Store index faa089c7d39e44268b3d457f00d9f4301a3aba17..2e99e30c833ae49d51c599175d13675f401180c4 100644 GIT binary patch delta 38 ucmZp1XmOa}&nUDpU^hRb&}JS1W5&$}A}^RWtMfcy-pnrXjb&p6J2L?73k(GS delta 808 zcmZ`%&ubGw6n-zQCaKYE(nOmULCi%cNX4EC(li!q5J_xGN$^M5ACt|{*_mZ_liFU^ zLvLQ}AE0-Sl4GwPym<5|{Rf145W$8cdi569xci0C-cy_vg`42q3YBnj<%^!7ql(sOPV&oN5}T zW@ay4PG_=nS8`Xc<+Va_zECQZ%hzu#lq-u%!D3IFH*|B)mSV`Qhk^-NXG8MLmegvy zx=Fd+@yRQ{O%F*=EB+Qd_5CiR0COg9K?^1ASS;dH1e zc-(qEvQ=qIlF+ic{zF}5puTGDad@jCxDx{nsxb&T?^c8}r9adp;tm&_WUIASOk^Pg z%di1YU>Ek_5RTy;e1H@94By}keqkClyp7AaiVtudx9}-$qZ!};DazO(g%j)W!KW5_ zDoK2FX5VX@!f|8qdGUWbM{I6R1}bwGzYf>leA