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 0000000..52abcff Binary files /dev/null and b/docbase/~$certificate_template.xlsx differ diff --git a/rog/.DS_Store b/rog/.DS_Store index faa089c..2e99e30 100644 Binary files a/rog/.DS_Store and b/rog/.DS_Store differ