쯔꾸르 같이 내부에 PNG 이미지 에셋을 사용하는 경우, 이미지가 많으면 이것도 용량이 만만찮잖아?
그래서 복호화한 PNG들을 포토샵 자체 느리게 저장 옵션을 통해 일괄처리 매크로로 용량을 좀 줄여 봤음.
일반적으론 용량이 꽤 많이 줄어들지만 일부 이미지들(대체로 작은 RGBA 파일)은 용량 차이가 별로 없거나 0.X ~ X kb 늘어나는 경우도 있지만,
전체적으로 대략 10% 조금 넘는 정도 이미지 에셋의 용량 감소가 보임.
자기전에 일괄로 걸어두고, 출근 가기 전에 일괄로 두고 하루에 2 ~ 300 mb 줄이는 게 의미가 있는가 모르겠네.
아래는 용량 감소된 파일 교체용 파이썬 코드.
import os
import shutil
import sys
# =========================
# 폴더 위치: 작업물(A) / 대상(B) 폴더
# =========================
src_dir = r"Z:\Temp"
dst_dir = r"D:\Temp"
# 로그 파일
missing_log_file = "missing_files.txt"
# =========================
# 실행 전 확인
# =========================
print("\n========== 실행 확인 ==========")
print(f"A 폴더 (작업물): {src_dir}")
print(f"B 폴더 (대상): {dst_dir}")
print("================================")
answer = input("\n덮어쓰기를 진행하시겠습니까? (Y/N): ").strip().lower()
if answer != "y":
print("\n작업이 취소되었습니다.")
sys.exit()
print("\n작업을 시작합니다...\n")
# =========================
# 통계 변수
# =========================
overwrite_count = 0
skip_count = 0
not_found_count = 0
total_old_size = 0
total_new_size = 0
missing_files = []
# =========================
# 파일 처리
# =========================
for root, dirs, files in os.walk(src_dir):
rel_path = os.path.relpath(root, src_dir)
target_root = os.path.join(dst_dir, rel_path)
for file in files:
src_file = os.path.join(root, file)
dst_file = os.path.join(target_root, file)
# 대상 파일이 없는 경우
if not os.path.exists(dst_file):
not_found_count += 1
relative_file = os.path.relpath(src_file, src_dir)
missing_files.append(relative_file)
continue
src_size = os.path.getsize(src_file)
dst_size = os.path.getsize(dst_file)
# A가 더 작을 때만 덮어쓰기
if src_size < dst_size:
total_old_size += dst_size
total_new_size += src_size
os.remove(dst_file)
shutil.move(src_file, dst_file)
overwrite_count += 1
else:
skip_count += 1
# =========================
# 결과 요약
# =========================
saved_size = total_old_size - total_new_size
reduction_percent = (
(saved_size / total_old_size) * 100
if total_old_size > 0 else 0
)
def format_size(size):
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
if size < 1024:
return f"{size:.2f} {unit}"
size /= 1024
summary = f"""
========== 작업 완료 ==========
덮어쓰기 파일 수 : {overwrite_count}
건너뛴 파일 수 : {skip_count}
대상 파일 없음 수 : {not_found_count}
기존(B) 총 용량 : {format_size(total_old_size)}
새(A) 총 용량 : {format_size(total_new_size)}
절감된 용량 : {format_size(saved_size)}
총 감소율 : {reduction_percent:.2f}%
================================
"""
print(summary)
# 요약 로그 저장
with open("summary_log.txt", "w", encoding="utf-8") as f:
f.write(summary)
# 대상 없는 파일 목록 저장
with open(missing_log_file, "w", encoding="utf-8") as f:
for item in missing_files:
f.write(item + "\n")
print(f"대상 없는 파일 목록 저장 완료: {missing_log_file}")
input("\n엔터를 누르면 종료됩니다...")
이건 작업물을 원본 PNG와 비교해서 용량이 감소된 것만 덮어쓰기 할 수 있는 코드.
'# 폴더 위치: 작업물(A) / 대상(B) 폴더'에 폴더 위치 수정한 다음 py를 돌리면,
폴더 위치를 잘못 적어도 B에 A 파일들이 없거나 A폴더내 파일과 이름이 다르면 이동되지 않고, 대상 파일 없음 수로 카운트 되고,
A 폴더내 파일들이 B폴더 파일보다 용량이 크면 덮어쓰지 않고, 건너띈 파일 수로 카운트 됨.
