File size: 4,741 Bytes
d15f07c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Media Generation Scripts

Scripts for generating images, banners, and visual assets for topics, causes, and content.

## πŸ“Έ generate_topic_images.py

Generate professional banner images (1200x600) and square thumbnails (400x400) for trending topics and causes using Google Gemini AI.

### Features

- **AI-Powered Color Schemes**: Uses Gemini to suggest professional, thematic color palettes
- **Banner Images**: 1200x600px hero images for featured stories
- **Square Thumbnails**: 400x400px images for topic tiles and cards
- **Gradient Backgrounds**: Professional gradient effects
- **Smart Text Wrapping**: Automatically wraps long topic names
- **Batch Processing**: Generate images for multiple topics at once

### Setup

1. **Get a Gemini API Key**:
   - Visit: https://makersuite.google.com/app/apikey
   - Create a new API key

2. **Add to .env file**:
   ```bash
   GEMINI_API_KEY=your_api_key_here
   ```

3. **Install dependencies** (automatic):
   ```bash
   # The script will auto-install if needed:
   # - google-generativeai
   # - pillow
   # - requests
   ```

### Usage

**Generate for a single topic:**
```bash
python scripts/media/generate_topic_images.py --topic "World Press Freedom Day"
```

**Generate for multiple topics from a file:**
```bash
# Create topics.txt with one topic per line
echo "Artificial Intelligence" > topics.txt
echo "Health & Medicine" >> topics.txt
echo "Climate Action" >> topics.txt

python scripts/media/generate_topic_images.py --topics-file topics.txt
```

**Generate default trending topics:**
```bash
# No arguments = generates default set of 10 trending topics
python scripts/media/generate_topic_images.py
```

**Custom output directory:**
```bash
python scripts/media/generate_topic_images.py \
  --topic "Education Reform" \
  --output-dir frontend/public/images/topics
```

### Output

For each topic, generates:

1. **Banner**: `{topic_slug}_banner.png` (1200x600)
   - Hero image for featured stories
   - Professional gradient background
   - Large centered text with shadow

2. **Square**: `{topic_slug}_square.png` (400x400)
   - Thumbnail for topic cards
   - Circular gradient effect
   - Wrapped text for long names

3. **Metadata**: `metadata.json`
   - Color schemes used
   - File paths
   - Topic information

### Example Output

```
data/media/topics/
β”œβ”€β”€ world_press_freedom_day_banner.png
β”œβ”€β”€ world_press_freedom_day_square.png
β”œβ”€β”€ artificial_intelligence_banner.png
β”œβ”€β”€ artificial_intelligence_square.png
β”œβ”€β”€ health_and_medicine_banner.png
β”œβ”€β”€ health_and_medicine_square.png
└── metadata.json
```

### Default Topics

The script generates images for these topics by default:
- World Press Freedom Day
- Business & Markets
- Artificial Intelligence
- Health & Medicine
- Social Media
- Civic Engagement
- Climate Action
- Education Reform
- Housing Policy
- Transportation

### Color Scheme Examples

Gemini generates contextual color schemes:
- **Politics**: Professional blues and reds
- **Health**: Calming greens and blues
- **Technology**: Modern purples and blues
- **Sports**: Energetic oranges and reds
- **Environment**: Earth tones and greens

### Integration with Homepage

The generated images can be used in the homepage:

```typescript
// Update TOP_STORIES in Home.tsx
const TOP_STORIES = [
  {
    title: 'AI Policy Tracking',
    topic: 'Artificial Intelligence',
    image: '/images/topics/artificial_intelligence_square.png', // Use generated image
    link: '/search?q=artificial+intelligence'
  },
  // ...
]
```

### Troubleshooting

**"GEMINI_API_KEY not found"**
- Add your API key to `.env` file
- Or pass with `--api-key` flag

**Font errors**
- Script will fallback to default fonts
- On Linux: `sudo apt-get install fonts-dejavu`

**Low quality images**
- Images are saved at 95% quality
- For higher quality, edit the `quality` parameter in the script

### Future Enhancements

- [ ] Support for Imagen 2 (when available in Gemini API)
- [ ] Custom icon/emoji overlays
- [ ] Animation support (GIF/WebP)
- [ ] Social media sized variants (Twitter, Facebook, etc.)
- [ ] Watermark support
- [ ] Bulk export to CDN

## 🎨 Color Scheme Philosophy

The generator uses AI to create professional, accessible color schemes:

1. **High Contrast**: Ensures text readability (WCAG AA compliant)
2. **Thematic Relevance**: Colors match topic context
3. **Brand Consistency**: Works with Open Navigator's primary colors
4. **Professional Look**: News/media-appropriate palettes

## πŸ“ Notes

- Images are generated programmatically (no API image generation yet)
- Gemini is used for intelligent color scheme selection
- All images are optimized for web use
- Supports batch generation for efficiency