Files
DTGAPK/create-icon-from-image.ps1

158 lines
4.7 KiB
PowerShell

# 이미지 파일에서 앱 아이콘 생성
param(
[Parameter(Mandatory=$false)]
[string]$ImagePath = "logo.png"
)
Write-Host "LS 타라유텍 앱 아이콘 생성 중..." -ForegroundColor Green
Write-Host ""
if (-not (Test-Path $ImagePath)) {
Write-Host "오류: 이미지 파일을 찾을 수 없습니다: $ImagePath" -ForegroundColor Red
Write-Host ""
Write-Host "사용법:" -ForegroundColor Yellow
Write-Host " 1. LS 로고 이미지를 'logo.png'로 저장" -ForegroundColor Cyan
Write-Host " 2. 이 스크립트 실행: .\create-icon-from-image.ps1" -ForegroundColor Cyan
Write-Host ""
Write-Host "또는 이미지 경로 지정:" -ForegroundColor Yellow
Write-Host " .\create-icon-from-image.ps1 -ImagePath 'path/to/image.png'" -ForegroundColor Cyan
exit 1
}
# Python 설치 확인
$python = Get-Command python -ErrorAction SilentlyContinue
if (-not $python) {
Write-Host "Python이 설치되지 않았습니다." -ForegroundColor Red
Write-Host "Python을 설치해주세요: https://www.python.org/downloads/" -ForegroundColor Yellow
exit 1
}
# Python 스크립트 생성
$pythonScript = @"
from PIL import Image
import os
import sys
#
image_path = sys.argv[1] if len(sys.argv) > 1 else 'logo.png'
if not os.path.exists(image_path):
print(f': : {image_path}')
sys.exit(1)
#
print(f' : {image_path}')
original = Image.open(image_path)
# RGBA
if original.mode != 'RGBA':
original = original.convert('RGBA')
print(f' : {original.size}')
#
sizes = {
'mdpi': 48,
'hdpi': 72,
'xhdpi': 96,
'xxhdpi': 144,
'xxxhdpi': 192
}
#
base_path = 'android/app/src/main/res'
for density in sizes.keys():
dir_path = f'{base_path}/mipmap-{density}'
os.makedirs(dir_path, exist_ok=True)
print('')
print(' ...')
# (LS )
width, height = original.size
# LS ( )
# 1/3
crop_width = int(width * 0.4) # LS
left = 0
top = 0
right = crop_width
bottom = height
#
cropped = original.crop((left, top, right, bottom))
# ( )
max_size = max(cropped.size)
square = Image.new('RGBA', (max_size, max_size), (255, 255, 255, 0))
#
paste_x = (max_size - cropped.size[0]) // 2
paste_y = (max_size - cropped.size[1]) // 2
square.paste(cropped, (paste_x, paste_y))
#
for density, size in sizes.items():
print(f' : mipmap-{density} ({size}x{size})')
# ()
resized = square.resize((size, size), Image.Resampling.LANCZOS)
#
resized.save(f'{base_path}/mipmap-{density}/ic_launcher.png', 'PNG')
#
#
mask = Image.new('L', (size, size), 0)
from PIL import ImageDraw
draw = ImageDraw.Draw(mask)
draw.ellipse([0, 0, size, size], fill=255)
#
round_icon = Image.new('RGBA', (size, size), (255, 255, 255, 0))
round_icon.paste(resized, (0, 0))
round_icon.putalpha(mask)
round_icon.save(f'{base_path}/mipmap-{density}/ic_launcher_round.png', 'PNG')
print('')
print(' !')
print('')
print(' :')
for density in sizes.keys():
print(f' - mipmap-{density}/ic_launcher.png')
print(f' - mipmap-{density}/ic_launcher_round.png')
"@
# Python 스크립트 저장
$pythonScript | Out-File -FilePath "create_icons_from_image.py" -Encoding UTF8
# Pillow 설치
Write-Host "Pillow 라이브러리 확인 중..." -ForegroundColor Cyan
python -m pip install --upgrade pip --quiet 2>$null
python -m pip install Pillow --quiet 2>$null
# 아이콘 생성 실행
Write-Host ""
Write-Host "아이콘 생성 실행 중..." -ForegroundColor Cyan
python create_icons_from_image.py $ImagePath
if ($LASTEXITCODE -eq 0) {
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host "✓ LS 타라유텍 아이콘 생성 완료!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host "다음 명령어로 APK를 빌드하세요:" -ForegroundColor Yellow
Write-Host " cd android" -ForegroundColor Cyan
Write-Host " .\gradlew.bat assembleDebug" -ForegroundColor Cyan
Write-Host ""
# 임시 파일 삭제
Remove-Item "create_icons_from_image.py" -ErrorAction SilentlyContinue
} else {
Write-Host ""
Write-Host "오류가 발생했습니다." -ForegroundColor Red
}