153 lines
4.1 KiB
Python
153 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script untuk generate placeholder images untuk aplikasi Wisata Lumajang AR.
|
|
Jalankan script ini di folder root project.
|
|
|
|
Requirements:
|
|
- pip install Pillow
|
|
|
|
Usage:
|
|
python generate_placeholders.py
|
|
"""
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
import os
|
|
|
|
# Definisi wisata dengan warna dan deskripsi
|
|
destinations = [
|
|
{
|
|
"filename": "gunung_lemongan",
|
|
"name": "Gunung Lemongan",
|
|
"color": "#A0826D",
|
|
"text_color": "white",
|
|
},
|
|
{
|
|
"filename": "gunung_semeru",
|
|
"name": "Gunung Semeru",
|
|
"color": "#704214",
|
|
"text_color": "white",
|
|
},
|
|
{
|
|
"filename": "pantai_watu_godeg",
|
|
"name": "Pantai Watu Godeg",
|
|
"color": "#4ECDC4",
|
|
"text_color": "white",
|
|
},
|
|
{
|
|
"filename": "pantai_watu_pecak",
|
|
"name": "Pantai Watu Pecak",
|
|
"color": "#00A99D",
|
|
"text_color": "white",
|
|
},
|
|
{
|
|
"filename": "puncak_b29",
|
|
"name": "Puncak B29",
|
|
"color": "#8B7D6B",
|
|
"text_color": "white",
|
|
},
|
|
{
|
|
"filename": "ranu_kumbolo",
|
|
"name": "Ranu Kumbolo",
|
|
"color": "#2196F3",
|
|
"text_color": "white",
|
|
},
|
|
{
|
|
"filename": "ranu_pani",
|
|
"name": "Ranu Pani",
|
|
"color": "#1565C0",
|
|
"text_color": "white",
|
|
},
|
|
{
|
|
"filename": "ranu_regulo",
|
|
"name": "Ranu Regulo",
|
|
"color": "#42A5F5",
|
|
"text_color": "white",
|
|
},
|
|
]
|
|
|
|
# Konfigurasi
|
|
OUTPUT_DIR = "android/wisata_app/assets/images"
|
|
IMAGE_WIDTH = 1080
|
|
IMAGE_HEIGHT = 720
|
|
QUALITY = 85
|
|
|
|
def create_placeholder_image(filename, name, color, text_color):
|
|
"""
|
|
Create a placeholder image with gradient background and text.
|
|
|
|
Args:
|
|
filename: Output filename without extension
|
|
name: Text to display on image
|
|
color: Hex color code for background
|
|
text_color: Text color
|
|
"""
|
|
# Convert hex to RGB
|
|
color_rgb = tuple(int(color.lstrip('#')[i:i+2], 16) for i in (0, 2, 4))
|
|
text_color_rgb = (255, 255, 255) if text_color == "white" else (0, 0, 0)
|
|
|
|
# Create base image with gradient
|
|
img = Image.new('RGB', (IMAGE_WIDTH, IMAGE_HEIGHT), color=color_rgb)
|
|
draw = ImageDraw.Draw(img, 'RGBA')
|
|
|
|
# Add gradient overlay (darker at bottom)
|
|
for y in range(IMAGE_HEIGHT):
|
|
alpha = int((y / IMAGE_HEIGHT) * 100)
|
|
dark_color = (*color_rgb, alpha)
|
|
draw.line([(0, y), (IMAGE_WIDTH, y)], fill=dark_color)
|
|
|
|
# Try to use a nice font, fallback to default
|
|
try:
|
|
font_size = 72
|
|
font = ImageFont.truetype("arial.ttf", font_size)
|
|
small_font = ImageFont.truetype("arial.ttf", 32)
|
|
except:
|
|
font = ImageFont.load_default()
|
|
small_font = ImageFont.load_default()
|
|
|
|
# Draw text in center
|
|
text_bbox = draw.textbbox((0, 0), name, font=font)
|
|
text_width = text_bbox[2] - text_bbox[0]
|
|
text_x = (IMAGE_WIDTH - text_width) // 2
|
|
text_y = (IMAGE_HEIGHT - 100) // 2
|
|
|
|
# Draw with shadow effect
|
|
draw.text((text_x + 2, text_y + 2), name, font=font, fill=(0, 0, 0, 128))
|
|
draw.text((text_x, text_y), name, font=font, fill=(*text_color_rgb, 255))
|
|
|
|
# Draw subtitle
|
|
subtitle = "Destinasi Wisata Lumajang"
|
|
draw.text(
|
|
(IMAGE_WIDTH // 2, IMAGE_HEIGHT - 80),
|
|
subtitle,
|
|
font=small_font,
|
|
fill=(*text_color_rgb, 200),
|
|
anchor="mm"
|
|
)
|
|
|
|
# Save image
|
|
output_path = os.path.join(OUTPUT_DIR, f"{filename}.jpg")
|
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
img.save(output_path, "JPEG", quality=QUALITY)
|
|
print(f"✓ Generated: {output_path}")
|
|
|
|
def main():
|
|
"""Generate all placeholder images."""
|
|
print(f"Generating {len(destinations)} placeholder images...")
|
|
print(f"Output directory: {OUTPUT_DIR}")
|
|
print()
|
|
|
|
for dest in destinations:
|
|
create_placeholder_image(
|
|
dest["filename"],
|
|
dest["name"],
|
|
dest["color"],
|
|
dest["text_color"]
|
|
)
|
|
|
|
print()
|
|
print("✓ All placeholder images generated successfully!")
|
|
print(f"✓ Total images: {len(destinations)}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|