-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gifs.py
More file actions
148 lines (122 loc) · 4.9 KB
/
test_gifs.py
File metadata and controls
148 lines (122 loc) · 4.9 KB
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
#!/usr/bin/env python3
"""
GIF Compatibility Test Script
Tests if created GIFs are properly formatted and compatible
"""
import os
import sys
from pathlib import Path
def test_gif_compatibility():
"""Test GIF files for compatibility"""
print("🧪 Testing GIF Compatibility")
print("=" * 40)
recordings_dir = Path("recordings")
if not recordings_dir.exists():
print("❌ No recordings directory found")
print("💡 Run: python demo.py --record --gif")
return
# Find all GIF files
gif_files = list(recordings_dir.glob("*.gif"))
if not gif_files:
print("❌ No GIF files found in recordings directory")
print("💡 Run: python demo.py --record --gif")
return
print(f"📊 Found {len(gif_files)} GIF files")
print()
all_passed = True
for gif_file in gif_files:
print(f"🔍 Testing: {gif_file.name}")
# Test 1: File exists and has size
if not gif_file.exists():
print(f"❌ File doesn't exist: {gif_file}")
all_passed = False
continue
file_size = gif_file.stat().st_size
if file_size == 0:
print(f"❌ File is empty: {gif_file}")
all_passed = False
continue
print(f" 📏 Size: {file_size / (1024*1024):.1f} MB")
# Test 2: Check file format with PIL
try:
from PIL import Image
with Image.open(gif_file) as img:
print(f" 🖼️ Format: {img.format}")
print(f" 📐 Dimensions: {img.size[0]}x{img.size[1]}")
print(f" 🎞️ Frames: {getattr(img, 'n_frames', 1)}")
# Test if it's animated
if hasattr(img, 'is_animated') and img.is_animated:
print(f" ✅ Animated GIF")
else:
print(f" ⚠️ Not animated (static image)")
# Test frame access
try:
img.seek(1) # Try to access second frame
print(f" ✅ Frame access works")
except EOFError:
print(f" ⚠️ Only one frame available")
except Exception as e:
print(f" ❌ Frame access error: {e}")
all_passed = False
except ImportError:
print(" ⚠️ PIL not available for detailed testing")
# Basic file test
import subprocess
try:
result = subprocess.run(['file', str(gif_file)],
capture_output=True, text=True)
if 'GIF' in result.stdout:
print(f" ✅ File format: {result.stdout.strip()}")
else:
print(f" ❌ Not a valid GIF: {result.stdout.strip()}")
all_passed = False
except:
print(" ⚠️ Could not verify file format")
except Exception as e:
print(f" ❌ PIL Error: {e}")
all_passed = False
# Test 3: Try to open with system default (macOS only)
if sys.platform == 'darwin':
try:
import subprocess
# Don't actually open, just test if the system recognizes it
result = subprocess.run(['file', str(gif_file)],
capture_output=True, text=True)
if 'GIF image data' in result.stdout:
print(f" ✅ System recognizes as GIF")
else:
print(f" ❌ System doesn't recognize format")
all_passed = False
except:
pass
print()
# Summary
print("=" * 40)
if all_passed:
print("🎉 All GIF tests passed!")
print("✅ Your GIFs should work in all applications")
print()
print("💡 Test opening in:")
print(" • Web browser (Chrome, Firefox, Safari)")
print(" • Image viewers (Preview, Photos, etc.)")
print(" • Social media platforms")
else:
print("⚠️ Some GIF tests failed")
print("🔧 Try fixing with: python fix_gifs.py --fix-all")
print("📖 See GIF_TROUBLESHOOTING.md for help")
print()
print("📁 GIF locations:")
for gif_file in gif_files:
print(f" {gif_file}")
def main():
"""Main function"""
if len(sys.argv) > 1 and sys.argv[1] in ['--help', '-h']:
print("GIF Compatibility Test Script")
print("Usage: python test_gifs.py")
print()
print("This script tests GIF files in the recordings directory")
print("for compatibility and proper formatting.")
return
test_gif_compatibility()
if __name__ == "__main__":
main()