ruby_spriter 0.6.7 → 0.7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +3 -3
  3. data/CHANGELOG.md +1035 -405
  4. data/Gemfile +17 -17
  5. data/LICENSE +21 -21
  6. data/README.md +183 -902
  7. data/bin/ruby_spriter +20 -20
  8. data/lib/ruby_spriter/background_sampler.rb +140 -0
  9. data/lib/ruby_spriter/batch_processor.rb +268 -212
  10. data/lib/ruby_spriter/cell_cleanup_config.rb +21 -0
  11. data/lib/ruby_spriter/cell_cleanup_gimp_script.rb +123 -0
  12. data/lib/ruby_spriter/cell_cleanup_processor.rb +230 -0
  13. data/lib/ruby_spriter/cli.rb +676 -612
  14. data/lib/ruby_spriter/compression_manager.rb +101 -101
  15. data/lib/ruby_spriter/consolidator.rb +179 -179
  16. data/lib/ruby_spriter/dependency_checker.rb +224 -174
  17. data/lib/ruby_spriter/ghost_edge_cleaner.rb +164 -0
  18. data/lib/ruby_spriter/gimp_processor.rb +1188 -667
  19. data/lib/ruby_spriter/metadata_manager.rb +117 -116
  20. data/lib/ruby_spriter/platform.rb +137 -82
  21. data/lib/ruby_spriter/processor.rb +1230 -886
  22. data/lib/ruby_spriter/smoke_detector.rb +223 -0
  23. data/lib/ruby_spriter/threshold_stepper.rb +227 -0
  24. data/lib/ruby_spriter/utils/file_helper.rb +82 -82
  25. data/lib/ruby_spriter/utils/image_helper.rb +16 -0
  26. data/lib/ruby_spriter/utils/output_formatter.rb +65 -65
  27. data/lib/ruby_spriter/utils/path_helper.rb +59 -59
  28. data/lib/ruby_spriter/utils/spritesheet_splitter.rb +86 -86
  29. data/lib/ruby_spriter/version.rb +6 -7
  30. data/lib/ruby_spriter/video_processor.rb +357 -139
  31. data/lib/ruby_spriter.rb +38 -34
  32. data/ruby_spriter.gemspec +44 -42
  33. data/spec/fixtures/centered_sprite_with_inner_bg.png +0 -0
  34. data/spec/fixtures/centered_sprite_with_inner_bg_inner_removed.png +0 -0
  35. data/spec/fixtures/centered_sprite_with_inner_bg_threshold_stepped.png +0 -0
  36. data/spec/fixtures/complex_background_sprite.png +0 -0
  37. data/spec/fixtures/death - bloodborne rekconing.mp4 +0 -0
  38. data/spec/fixtures/death - bloodborne rekconing_spritesheet-nobg-global.png +0 -0
  39. data/spec/fixtures/death - bloodborne rekconing_spritesheet.png +0 -0
  40. data/spec/fixtures/death - bloodborne rekconing_spritesheet_20251110_185027_431-nobg-global.png +0 -0
  41. data/spec/fixtures/death - bloodborne rekconing_spritesheet_20251110_185027_431.png +0 -0
  42. data/spec/fixtures/death - bloodborne rekconing_spritesheet_20251110_185125_738-nobg-global.png +0 -0
  43. data/spec/fixtures/death - bloodborne rekconing_spritesheet_20251110_185125_738.png +0 -0
  44. data/spec/fixtures/has_inner_bg.png +0 -0
  45. data/spec/fixtures/has_small_inner_bg.png +0 -0
  46. data/spec/fixtures/smoke_effect_sprite.png +0 -0
  47. data/spec/fixtures/spritesheet_with_metadata.png +0 -0
  48. data/spec/fixtures/test_sprite.png +0 -0
  49. data/spec/fixtures/test_sprite_smoke_processed.png +0 -0
  50. data/spec/fixtures/test_video_spritesheet.png +0 -0
  51. data/spec/fixtures/transparent_bg_sprite.png +0 -0
  52. data/spec/fixtures/walk_north_sprite-sheet.png +0 -0
  53. data/spec/integration/no_fuzzy_mode_spec.rb +100 -0
  54. data/spec/ruby_spriter/batch_processor_spec.rb +509 -200
  55. data/spec/ruby_spriter/cli_spec.rb +2026 -1892
  56. data/spec/ruby_spriter/compression_manager_spec.rb +157 -157
  57. data/spec/ruby_spriter/consolidator_spec.rb +538 -538
  58. data/spec/ruby_spriter/gimp_processor_spec.rb +523 -425
  59. data/spec/ruby_spriter/platform_spec.rb +92 -82
  60. data/spec/ruby_spriter/processor_spec.rb +911 -735
  61. data/spec/ruby_spriter/utils/file_helper_spec.rb +150 -150
  62. data/spec/ruby_spriter/utils/path_helper_spec.rb +78 -78
  63. data/spec/ruby_spriter/utils/spritesheet_splitter_spec.rb +104 -104
  64. data/spec/ruby_spriter/video_processor_spec.rb +346 -29
  65. data/spec/spec_helper.rb +41 -41
  66. data/spec/tmp/cli_test_output.png +0 -0
  67. data/spec/tmp/cli_test_output_20251105_114647_395.png +0 -0
  68. data/spec/tmp/combined_test.png +0 -0
  69. data/spec/tmp/compat_test.png +0 -0
  70. data/spec/tmp/compat_test_20251030_174233_361.png +0 -0
  71. data/spec/tmp/final_all_features.png +0 -0
  72. data/spec/tmp/final_test_all_features.png +0 -0
  73. data/spec/tmp/full_pipeline_test.png +0 -0
  74. data/spec/tmp/inner_test.png +0 -0
  75. data/spec/tmp/integration_test.png +0 -0
  76. data/spec/tmp/validation_test.png +0 -0
  77. data/spec/unit/background_sampler_spec.rb +132 -0
  78. data/spec/unit/cell_cleanup_config_spec.rb +32 -0
  79. data/spec/unit/cell_cleanup_gimp_script_spec.rb +59 -0
  80. data/spec/unit/cell_cleanup_processor_spec.rb +261 -0
  81. data/spec/unit/ghost_edge_cleaner_spec.rb +223 -0
  82. data/spec/unit/gimp_processor_single_point_selection_spec.rb +81 -0
  83. data/spec/unit/smoke_detector_spec.rb +246 -0
  84. data/spec/unit/threshold_stepper_spec.rb +195 -0
  85. metadata +56 -10
data/README.md CHANGED
@@ -1,902 +1,183 @@
1
- # Ruby Spriter v0.6.7
2
-
3
- [![Ruby](https://img.shields.io/badge/Ruby-2.7+-red.svg)](https://www.ruby-lang.org/)
4
- [![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5
- [![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey.svg)]()
6
-
7
- **Professional MP4 to Spritesheet Converter with Advanced Image Processing**
8
-
9
- A powerful cross-platform Ruby tool for creating high-quality spritesheets from video files and processing them with professional-grade image manipulation. Perfect for game development workflows, particularly with Godot Engine.
10
-
11
- ---
12
-
13
- ## ✨ Features
14
-
15
- ### Core Capabilities
16
- - 🎬 **Video to Spritesheet** - Extract frames from MP4 videos using FFmpeg
17
- - 🖼️ **Advanced Image Processing** - Scale, sharpen, and remove backgrounds with precision
18
- - 🎨 **Quality Enhancement** - 5 interpolation methods and configurable unsharp masking
19
- - 📐 **Spritesheet Consolidation** - Merge multiple spritesheets vertically (file list or directory)
20
- - 📊 **Metadata Management** - Embed, verify, and add grid information to PNG files
21
- - 🎯 **Frame Extraction** - Extract specific frames by number and create new spritesheets
22
- - 🏷️ **Metadata Addition** - Add spritesheet metadata to external images
23
- - 🔒 **Automatic File Protection** - Unique timestamped filenames prevent accidental overwrites (v0.6.6+)
24
- - 📦 **Batch Processing** - Process multiple MP4 files in a directory automatically (v0.6.7+)
25
- - 🗜️ **Maximum Compression** - Optimal PNG compression while preserving metadata (v0.6.7+)
26
- - 🌍 **Cross-Platform** - Works seamlessly on Windows, Linux, and macOS
27
- - 🧪 **Production Ready** - Comprehensive RSpec test coverage (365 tests)
28
-
29
- ### Image Processing Features
30
-
31
- #### **Scaling with Quality Control**
32
- - Percentage-based resizing
33
- - **5 Interpolation Methods:**
34
- - `none` - No interpolation (nearest neighbor)
35
- - `linear` - Fast bilinear interpolation
36
- - `cubic` - High-quality bicubic interpolation
37
- - `nohalo` - Advanced edge-preserving (default)
38
- - `lohalo` - Maximum quality, slower
39
-
40
- #### **Sharpening (Unsharp Mask)**
41
- - Restore edge definition after scaling
42
- - **Configurable Parameters:**
43
- - `radius` - Effect size in pixels (default: 2.0)
44
- - `gain` - Sharpening intensity (default: 0.5, range: 0.0-2.0+)
45
- - `threshold` - Minimum change threshold (default: 0.03, range: 0.0-1.0)
46
- - Powered by ImageMagick for consistent results
47
-
48
- #### **Background Removal**
49
- - **Fuzzy Select** - Contiguous color regions (default)
50
- - **Global Color Select** - All matching pixels across image
51
- - Adjustable selection growth and feathering
52
- - **Smart Operation Order** - Automatically optimizes quality
53
-
54
- #### **Operation Order Optimization**
55
- - `scale_first` (default) - Scale then remove background
56
- - `bg_first` - Remove background then scale (auto-enabled when both operations used)
57
- - Automatic optimization for best quality
58
-
59
- ---
60
-
61
- ## 📋 Requirements
62
-
63
- ### External Dependencies
64
-
65
- | Tool | Version | Purpose |
66
- |------|---------|---------|
67
- | **FFmpeg** | Latest | Video frame extraction |
68
- | **FFprobe** | Latest | Video analysis (included with FFmpeg) |
69
- | **ImageMagick** | 7.x+ | Metadata and sharpening |
70
- | **GIMP** | 3.x (or 2.10) | Scaling and background removal |
71
-
72
- ### Ruby Version
73
- - Ruby 2.7.0 or higher
74
- - No runtime gem dependencies (uses Ruby standard library)
75
-
76
- ### Supported File Formats
77
- - **Video Input**: MP4 only
78
- - **Image Input/Output**: PNG only
79
-
80
- ---
81
-
82
- ## 🚀 Installation
83
-
84
- ### Prerequisites (All Installation Methods)
85
-
86
- Ruby Spriter requires these external tools for video and image processing:
87
-
88
- | Tool | Purpose | Version |
89
- |------|---------|---------|
90
- | **FFmpeg** | Video frame extraction | Any recent version |
91
- | **ImageMagick** | Image manipulation & metadata | 7.x or 6.9+ |
92
- | **GIMP** | Advanced image processing | 3.x (or 2.10) |
93
-
94
- #### Installing Prerequisites
95
-
96
- **Windows (Chocolatey - Recommended)**
97
-
98
- Chocolatey is a package manager for Windows that simplifies software installation. If you don't have Chocolatey installed:
99
-
100
- 1. **Install Chocolatey** (run PowerShell as Administrator):
101
- ```powershell
102
- Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
103
- ```
104
-
105
- Verify installation:
106
- ```powershell
107
- choco --version
108
- ```
109
-
110
- 2. **Install Ruby** (if not already installed):
111
- ```powershell
112
- choco install ruby -y
113
- ```
114
-
115
- Close and reopen PowerShell, then verify:
116
- ```powershell
117
- ruby --version
118
- gem --version
119
- ```
120
-
121
- 3. **Install Ruby Spriter dependencies**:
122
- ```powershell
123
- choco install ffmpeg imagemagick gimp -y
124
- ```
125
-
126
- This installs all required tools:
127
- - **FFmpeg** - Video processing
128
- - **ImageMagick** - Image manipulation and metadata
129
- - **GIMP** - Advanced image processing
130
-
131
- 4. **Restart your terminal** to ensure all tools are in your PATH
132
-
133
- **Alternative: Manual Installation on Windows**
134
-
135
- If you prefer not to use Chocolatey:
136
- - **Ruby**: Download from [rubyinstaller.org](https://rubyinstaller.org/)
137
- - **FFmpeg**: Download from [ffmpeg.org](https://ffmpeg.org/download.html)
138
- - **ImageMagick**: Download from [imagemagick.org](https://imagemagick.org/script/download.php#windows)
139
- - **GIMP**: Download from [gimp.org](https://www.gimp.org/downloads/)
140
-
141
- **macOS (Homebrew)**
142
-
143
- ```bash
144
- # Install Homebrew if not already installed
145
- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
146
-
147
- # Install Ruby (if not already installed)
148
- brew install ruby
149
-
150
- # Install Ruby Spriter dependencies
151
- brew install ffmpeg imagemagick gimp
152
- ```
153
-
154
- **Linux (Ubuntu/Debian)**
155
-
156
- ```bash
157
- # Install Ruby (if not already installed)
158
- sudo apt update && sudo apt install ruby-full -y
159
-
160
- # Install Ruby Spriter dependencies
161
- sudo apt install ffmpeg imagemagick gimp -y
162
- ```
163
-
164
- **Linux (Fedora/RHEL)**
165
-
166
- ```bash
167
- # Install Ruby (if not already installed)
168
- sudo dnf install ruby -y
169
-
170
- # Install Ruby Spriter dependencies
171
- sudo dnf install ffmpeg imagemagick gimp -y
172
- ```
173
-
174
- ---
175
-
176
- ### Choose Your Installation Method
177
-
178
- #### 📦 **Option A: RubyGems (Recommended)**
179
-
180
- Install the published gem from RubyGems.org:
181
-
182
- ```bash
183
- gem install ruby_spriter
184
- ```
185
-
186
- **Requirements**: Ruby 2.7 or higher
187
- **Best for**: All platforms (Windows, macOS, Linux), automated workflows
188
-
189
- ---
190
-
191
- #### 🛠️ **Option B: From Source (Development)**
192
-
193
- Clone and build from source:
194
-
195
- ```bash
196
- # Clone repository
197
- git clone https://github.com/scooter-indie/ruby-spriter.git
198
- cd ruby-spriter
199
-
200
- # Install development dependencies
201
- bundle install
202
-
203
- # Build and install gem locally
204
- gem build ruby_spriter.gemspec
205
- gem install ruby_spriter-0.6.7.gem
206
- ```
207
-
208
- **Best for**: Contributors, developers wanting latest code
209
-
210
- ---
211
-
212
- ### Verify Installation
213
-
214
- After installing Ruby Spriter via any method:
215
-
216
- ```bash
217
- # Check Ruby Spriter version
218
- ruby_spriter --version
219
-
220
- # Verify all dependencies
221
- ruby_spriter --check-dependencies
222
- ```
223
-
224
- The `--check-dependencies` command checks all external tools:
225
- - ✅ **Tool found**: Shows version and path
226
- - ❌ **Tool missing**: Shows platform-specific installation commands
227
-
228
- Example output:
229
- ```
230
- Checking external dependencies...
231
-
232
- ✓ FFmpeg found: 6.0 (C:\ProgramData\chocolatey\bin\ffmpeg.exe)
233
- ✓ FFprobe found: 6.0 (C:\ProgramData\chocolatey\bin\ffprobe.exe)
234
- ✓ ImageMagick (convert) found: 7.1.1-15 (C:\Program Files\ImageMagick\convert.exe)
235
- ✓ ImageMagick (identify) found: 7.1.1-15 (C:\Program Files\ImageMagick\identify.exe)
236
- ✓ GIMP found: 2.99.16 (C:\Program Files\GIMP 3\bin\gimp-2.99.exe)
237
-
238
- All dependencies are installed!
239
- ```
240
-
241
- ---
242
-
243
- ## 🎯 Quick Start
244
-
245
- ### Basic Video to Spritesheet
246
- ```bash
247
- # Create 4x4 grid with 16 frames
248
- ruby_spriter --video input.mp4
249
-
250
- # Custom grid and frame count
251
- ruby_spriter --video input.mp4 --frames 32 --columns 8
252
- ```
253
-
254
- ### High-Quality Scaling
255
- ```bash
256
- # Scale to 50% with best quality interpolation
257
- ruby_spriter --video input.mp4 --scale 50 --interpolation nohalo
258
-
259
- # Scale and sharpen for crisp results
260
- ruby_spriter --video input.mp4 --scale 50 --sharpen
261
-
262
- # Custom sharpening for maximum detail
263
- ruby_spriter --video input.mp4 --scale 50 --sharpen \
264
- --sharpen-gain 1.5 --sharpen-radius 3.0
265
- ```
266
-
267
- ### Background Removal
268
- ```bash
269
- # Remove background (auto-optimized order)
270
- ruby_spriter --video input.mp4 --scale 50 --remove-bg
271
-
272
- # Process existing spritesheet
273
- ruby_spriter --image sprite.png --remove-bg --fuzzy
274
-
275
- # Fine-tune background removal
276
- ruby_spriter --image sprite.png --remove-bg \
277
- --threshold 1.5 --grow 2
278
- ```
279
-
280
- ### Batch Processing (v0.6.7+)
281
- ```bash
282
- # Process all videos in a directory
283
- ruby_spriter --batch --dir "videos/"
284
-
285
- # Batch process with scaling and compression
286
- ruby_spriter --batch --dir "videos/" --scale 50 --max-compress
287
-
288
- # Batch process with output to different directory
289
- ruby_spriter --batch --dir "videos/" --outputdir "output/"
290
-
291
- # Batch process and consolidate all results
292
- ruby_spriter --batch --dir "videos/" --batch-consolidate
293
- ```
294
-
295
- ### Consolidate Spritesheets
296
- ```bash
297
- # Consolidate specific files (comma-separated)
298
- ruby_spriter --consolidate file1.png,file2.png,file3.png
299
-
300
- # Consolidate all spritesheets in a directory (v0.6.7+)
301
- ruby_spriter --consolidate --dir "spritesheets/"
302
-
303
- # Consolidate with compression
304
- ruby_spriter --consolidate --dir "spritesheets/" --max-compress
305
- ```
306
-
307
- ### Frame Extraction (v0.6.8+)
308
- ```bash
309
- # Extract specific frames by number
310
- ruby_spriter --image sprite.png --extract 1,2,4,5,8 --columns 3
311
-
312
- # Extract with duplicates for animation loops
313
- ruby_spriter --image sprite.png --extract 1,1,2,2,3,3
314
-
315
- # Extract, process, and save frames
316
- ruby_spriter --image sprite.png --extract 1,3,5,7 \
317
- --scale 50 --sharpen --save-frames
318
-
319
- # Workflow: Add metadata then extract frames
320
- ruby_spriter --image external.png --add-meta 4:4
321
- ruby_spriter --image external.png --extract 1,5,9,13 --columns 2
322
- ```
323
-
324
- ### Metadata Management (v0.6.8+)
325
- ```bash
326
- # Add metadata to external spritesheet
327
- ruby_spriter --image sprite.png --add-meta 4:4
328
-
329
- # Add metadata with partial grid (14 frames in 4x4 grid)
330
- ruby_spriter --image sprite.png --add-meta 4:4 --frames 14
331
-
332
- # Replace existing metadata
333
- ruby_spriter --image existing.png --add-meta 8:8 --overwrite-meta
334
-
335
- # Add metadata and copy to new file
336
- ruby_spriter --image sprite.png --add-meta 4:4 --output sprite_meta.png
337
- ```
338
-
339
- ### Advanced Workflows
340
- ```bash
341
- # Complete processing pipeline with compression
342
- ruby_spriter --video input.mp4 \
343
- --frames 64 --columns 8 \
344
- --scale 50 --interpolation nohalo \
345
- --remove-bg \
346
- --sharpen --sharpen-gain 0.8 \
347
- --max-compress
348
-
349
- # Process existing image with quality enhancement
350
- ruby_spriter --image large_sprite.png \
351
- --scale 50 --interpolation lohalo \
352
- --sharpen --sharpen-gain 1.2
353
- ```
354
-
355
- ---
356
-
357
- ## 📚 Usage
358
-
359
- ### Command-Line Options
360
-
361
- #### **Input Options**
362
- ```bash
363
- -v, --video FILE Input video file (MP4 only)
364
- -i, --image FILE Input image file (PNG only)
365
- --batch Batch process mode (use with --dir)
366
- --dir DIRECTORY Directory for batch or consolidate operations
367
- --consolidate [FILES] Consolidate spritesheets (comma-separated files or use with --dir)
368
- --verify FILE Verify spritesheet metadata (PNG only)
369
- ```
370
-
371
- #### **Spritesheet Options**
372
- ```bash
373
- -o, --output FILE Output file path
374
- -f, --frames COUNT Number of frames to extract (default: 16)
375
- -c, --columns COUNT Grid columns (default: 4)
376
- -w, --width PIXELS Max frame width (default: 320)
377
- -b, --background COLOR Tile background: black, white (default: black)
378
- ```
379
-
380
- #### **Scaling Options**
381
- ```bash
382
- -s, --scale PERCENT Scale image by percentage
383
- --interpolation METHOD Interpolation: none, linear, cubic, nohalo, lohalo
384
- (default: nohalo)
385
- ```
386
-
387
- #### **Sharpening Options**
388
- ```bash
389
- --sharpen Apply unsharp mask after scaling
390
- --sharpen-radius VALUE Radius in pixels (default: 2.0)
391
- --sharpen-gain VALUE Gain/strength (default: 0.5, range: 0.0-2.0+)
392
- --sharpen-threshold VALUE Threshold fraction (default: 0.03, range: 0.0-1.0)
393
- ```
394
-
395
- #### **Background Removal Options**
396
- ```bash
397
- -r, --remove-bg Remove background using GIMP
398
- -t, --threshold VALUE Feather radius (default: 0.0)
399
- -g, --grow PIXELS Pixels to grow selection (default: 1)
400
- --fuzzy Use fuzzy select (contiguous) - DEFAULT
401
- --no-fuzzy Use global color select (all matching)
402
- --order ORDER Operation order: scale_first, bg_first
403
- ```
404
-
405
- #### **Preset Configurations**
406
- ```bash
407
- --preset thumbnail 3×? grid, 9 frames, 240px wide
408
- --preset preview 4×? grid, 16 frames, 400px wide
409
- --preset detailed 10×? grid, 50 frames, 320px wide
410
- --preset contact 8×? grid, 64 frames, 160px wide
411
- ```
412
-
413
- #### **Batch Processing Options (v0.6.7+)**
414
- ```bash
415
- --batch Enable batch processing mode
416
- --dir DIRECTORY Directory containing MP4 files to process
417
- --outputdir DIRECTORY Output directory for processed files
418
- --batch-consolidate Consolidate all resulting spritesheets
419
- ```
420
-
421
- #### **Compression Options (v0.6.7+)**
422
- ```bash
423
- --max-compress Apply maximum PNG compression (preserves metadata)
424
- ```
425
-
426
- #### **Frame Extraction Options (v0.6.8+)**
427
- ```bash
428
- --extract FRAMES Extract specific frames by number (e.g., 1,2,4,5,8)
429
- --columns NUM Output grid columns for extracted spritesheet (default: 4)
430
- --save-frames Keep individual extracted frames on disk
431
- --split R:C Split spritesheet into all individual frames (rows:columns)
432
- --override-md Override embedded metadata when using --split
433
- ```
434
-
435
- #### **Metadata Management Options (v0.6.8+)**
436
- ```bash
437
- --add-meta R:C Add spritesheet metadata (rows:columns, e.g., 4:4)
438
- --overwrite-meta Replace existing metadata
439
- ```
440
-
441
- #### **Other Options**
442
- ```bash
443
- --overwrite Overwrite existing output files (default: create unique filenames)
444
- --keep-temp Keep temporary files for debugging
445
- --debug Enable verbose output + keep temp files
446
- --check-dependencies Check if all required external tools are installed
447
- --version Show version information
448
- -h, --help Show help message
449
- ```
450
-
451
- ---
452
-
453
- ## 💡 Use Cases
454
-
455
- ### Game Development with Godot
456
-
457
- #### Character Animation Sprites
458
- ```bash
459
- # Export from Blender/animation software to MP4
460
- # Convert to optimized spritesheet with background removal
461
-
462
- ruby_spriter --video character_walk.mp4 \
463
- --frames 16 --columns 4 \
464
- --scale 50 --remove-bg \
465
- --sharpen
466
- ```
467
-
468
- #### VFX and Particle Effects
469
- ```bash
470
- # High frame count for smooth effects
471
- ruby_spriter --video explosion.mp4 \
472
- --frames 64 --columns 8 \
473
- --scale 75 --interpolation nohalo
474
- ```
475
-
476
- #### Multiple Character Directions
477
- ```bash
478
- # Consolidate walk cycles for 8 directions (file list)
479
- ruby_spriter --consolidate \
480
- walk_n.png,walk_ne.png,walk_e.png,walk_se.png,\
481
- walk_s.png,walk_sw.png,walk_w.png,walk_nw.png \
482
- --output character_walk_all.png
483
-
484
- # Or consolidate all spritesheets in a directory (v0.6.7+)
485
- ruby_spriter --consolidate --dir "walk_cycles/" \
486
- --output character_walk_all.png
487
- ```
488
-
489
- ### Batch Processing Workflows (v0.6.7+)
490
- ```bash
491
- # Process entire animation library
492
- ruby_spriter --batch --dir "raw_animations/" \
493
- --outputdir "game_assets/sprites/" \
494
- --scale 50 --remove-bg --sharpen --max-compress
495
-
496
- # Create and consolidate multiple character states
497
- ruby_spriter --batch --dir "character_states/" \
498
- --frames 8 --columns 4 \
499
- --batch-consolidate
500
- ```
501
-
502
- ### Quality Enhancement
503
- ```bash
504
- # Downscale high-res renders while maintaining sharpness
505
- ruby_spriter --image 4k_sprite.png \
506
- --scale 25 --interpolation lohalo \
507
- --sharpen --sharpen-gain 1.0 \
508
- --max-compress \
509
- --output hd_sprite.png
510
- ```
511
-
512
- ---
513
-
514
- ## 🔧 Advanced Features
515
-
516
- ### Batch Processing (v0.6.7+)
517
-
518
- Process entire directories of MP4 files with consistent settings:
519
-
520
- ```bash
521
- # Basic batch processing
522
- ruby_spriter --batch --dir "animations/"
523
- # Processes all MP4s with default 4x4 grid
524
-
525
- # Batch with processing options
526
- ruby_spriter --batch --dir "animations/" \
527
- --frames 32 --columns 8 \
528
- --scale 50 --remove-bg --sharpen \
529
- --max-compress
530
-
531
- # Batch with output directory
532
- ruby_spriter --batch --dir "raw_videos/" \
533
- --outputdir "game_assets/sprites/"
534
-
535
- # Batch and consolidate results
536
- ruby_spriter --batch --dir "character_states/" \
537
- --batch-consolidate \
538
- --output character_complete.png
539
- ```
540
-
541
- **Features:**
542
- - Automatically finds all MP4 files in directory
543
- - Applies consistent processing to all videos
544
- - Enforces unique output filenames (unless `--overwrite`)
545
- - Continues processing if one file fails
546
- - Optional consolidation of all results
547
- - Supports all video and image processing options
548
-
549
- ### Maximum Compression (v0.6.7+)
550
-
551
- Reduce file sizes while preserving metadata:
552
-
553
- ```bash
554
- # Compress during video processing
555
- ruby_spriter --video input.mp4 --max-compress
556
-
557
- # Compress during image processing
558
- ruby_spriter --image sprite.png --scale 50 --max-compress
559
-
560
- # Compress batch output
561
- ruby_spriter --batch --dir "videos/" --max-compress
562
-
563
- # Compress consolidated output
564
- ruby_spriter --consolidate --dir "sprites/" --max-compress
565
- ```
566
-
567
- **Compression Details:**
568
- - Uses ImageMagick optimal PNG compression settings
569
- - Compression level 9 (maximum zlib)
570
- - Paeth filter (compression filter 5)
571
- - Filtered strategy (compression strategy 1)
572
- - Quality 95
573
- - Preserves embedded spritesheet metadata
574
- - Displays size reduction statistics
575
-
576
- ### Directory-Based Consolidation (v0.6.7+)
577
-
578
- Consolidate all spritesheets in a directory automatically:
579
-
580
- ```bash
581
- # Scan directory and consolidate all spritesheets
582
- ruby_spriter --consolidate --dir "character_animations/"
583
-
584
- # With output directory
585
- ruby_spriter --consolidate --dir "sprites/" \
586
- --outputdir "final_assets/"
587
-
588
- # With compression
589
- ruby_spriter --consolidate --dir "sprites/" \
590
- --max-compress \
591
- --output character_complete.png
592
- ```
593
-
594
- **Directory Mode Features:**
595
- - Automatically scans for PNG files with metadata
596
- - Filters out non-spritesheet images
597
- - Sorts files alphabetically before consolidation
598
- - Requires at least 2 valid spritesheets
599
- - Cannot mix with comma-separated file list mode
600
-
601
- ### File Protection with Unique Filenames (v0.6.6+)
602
-
603
- By default, Ruby Spriter protects your existing files by generating unique timestamped filenames when output files already exist:
604
-
605
- ```bash
606
- # First run - creates new file
607
- ruby_spriter --image sprite.png --remove-bg
608
- # Output: sprite-nobg-fuzzy.png
609
-
610
- # Second run - creates unique file instead of overwriting
611
- ruby_spriter --image sprite.png --remove-bg
612
- # Output: sprite-nobg-fuzzy_20251023_170542_123.png
613
-
614
- # Third run - another unique file
615
- ruby_spriter --image sprite.png --remove-bg
616
- # Output: sprite-nobg-fuzzy_20251023_170545_456.png
617
- ```
618
-
619
- #### Overwrite Mode
620
-
621
- Use `--overwrite` to replace existing files instead:
622
-
623
- ```bash
624
- # Always overwrites sprite-nobg-fuzzy.png
625
- ruby_spriter --image sprite.png --remove-bg --overwrite
626
- ```
627
-
628
- #### Behavior by Mode
629
-
630
- | Mode | Default Filename | Unique on Collision |
631
- |------|------------------|---------------------|
632
- | `--video` | `input_spritesheet.png` | ✅ Yes |
633
- | `--image` (with processing) | `input-scaled-50pct.png` | ✅ Yes |
634
- | `--consolidate` | `consolidated_spritesheet.png` | ✅ Yes |
635
- | Any with `--output` | Your specified name | ✅ Yes (unless `--overwrite`) |
636
-
637
- ### Metadata Management
638
-
639
- Ruby Spriter embeds grid information directly into PNG files:
640
-
641
- ```bash
642
- # Metadata is automatically embedded during creation
643
- ruby_spriter --video input.mp4 --frames 32 --columns 8
644
-
645
- # Verify metadata in existing spritesheet
646
- ruby_spriter --verify spritesheet.png
647
-
648
- # Output:
649
- # Spritesheet Metadata Verification
650
- # ================================
651
- # File: spritesheet.png
652
- # Columns: 8
653
- # Frames: 32
654
- # Rows: 4 (calculated)
655
- ```
656
-
657
- ### Operation Order Optimization
658
-
659
- When both scaling and background removal are requested, Ruby Spriter automatically uses the optimal order:
660
-
661
- ```bash
662
- # This automatically removes background BEFORE scaling
663
- ruby_spriter --video input.mp4 --scale 50 --remove-bg
664
-
665
- # Why? Background removal works better at full resolution,
666
- # then scaling smooths any rough edges
667
- ```
668
-
669
- Override if needed:
670
- ```bash
671
- ruby_spriter --video input.mp4 --scale 50 --remove-bg --order scale_first
672
- ```
673
-
674
- ### Debug Mode
675
-
676
- ```bash
677
- # See exactly what's happening
678
- ruby_spriter --video input.mp4 --scale 50 --sharpen --debug
679
-
680
- # Output includes:
681
- # - Dependency check results
682
- # - Temp directory location
683
- # - GIMP script paths and logs
684
- # - ImageMagick commands
685
- # - Processing timestamps
686
- ```
687
-
688
- ---
689
-
690
- ## 🏗️ Architecture
691
-
692
- ### Five Processing Modes
693
-
694
- 1. **Video Mode** - MP4 → Spritesheet → Optional Processing
695
- 2. **Image Mode** - PNG → Processing → Enhanced PNG
696
- 3. **Consolidate Mode** - Multiple PNGs → Combined Spritesheet (file list or directory)
697
- 4. **Batch Mode** (v0.6.7+) - Directory of MP4s → Multiple Spritesheets → Optional Consolidation
698
- 5. **Verify Mode** - Read and display embedded metadata
699
-
700
- ### Processing Pipeline
701
-
702
- **Video Mode:**
703
- ```
704
- Input Video (MP4)
705
-
706
- [FFmpeg] Frame Extraction + Spritesheet Assembly
707
-
708
- [ImageMagick] Metadata Embedding
709
-
710
- [GIMP] Scale and/or Background Removal (optional)
711
-
712
- [ImageMagick] Sharpening (optional)
713
-
714
- Output PNG with Metadata
715
- ```
716
-
717
- **Image Mode:**
718
- ```
719
- Input Image (PNG)
720
-
721
- [GIMP] Scale and/or Background Removal (optional)
722
-
723
- [ImageMagick] Sharpening (optional)
724
-
725
- [ImageMagick] Metadata Preservation
726
-
727
- Output PNG with Metadata
728
- ```
729
-
730
- **Consolidate Mode:**
731
- ```
732
- Multiple Input PNGs (file list or directory scan)
733
-
734
- [Metadata Filter] Find PNGs with spritesheet metadata (directory mode)
735
-
736
- [ImageMagick] Read Metadata from Each
737
-
738
- [ImageMagick] Validate Column Compatibility
739
-
740
- [ImageMagick] Vertical Stacking (append)
741
-
742
- [ImageMagick] Embed Combined Metadata
743
-
744
- [ImageMagick] Optional Max Compression
745
-
746
- Output Consolidated PNG
747
- ```
748
-
749
- **Batch Mode (v0.6.7+):**
750
- ```
751
- Directory of MP4 Files
752
-
753
- [Scan] Find all MP4 files
754
-
755
- [Loop] For each MP4:
756
- ├─ [FFmpeg] Extract frames + create spritesheet
757
- ├─ [GIMP] Optional scaling/background removal
758
- ├─ [ImageMagick] Optional sharpening
759
- └─ [ImageMagick] Optional max compression
760
-
761
- [Optional] Consolidate all results with --batch-consolidate
762
-
763
- Multiple Output PNGs (or one consolidated PNG)
764
- ```
765
-
766
- ### Key Components
767
-
768
- - **Processor** - Main orchestration
769
- - **VideoProcessor** - FFmpeg integration
770
- - **GimpProcessor** - GIMP batch scripting
771
- - **Consolidator** - Multi-sheet merging (file list or directory)
772
- - **BatchProcessor** (v0.6.7+) - Directory batch processing
773
- - **CompressionManager** (v0.6.7+) - PNG compression with metadata preservation
774
- - **MetadataManager** - PNG metadata handling
775
- - **DependencyChecker** - Tool detection
776
- - **Platform** - Cross-platform abstraction
777
-
778
- ---
779
-
780
- ## 🧪 Development
781
-
782
- ### Setup Development Environment
783
-
784
- ```bash
785
- # Clone and setup
786
- git clone https://github.com/scooter-indie/ruby-spriter.git
787
- cd ruby-spriter
788
- bundle install
789
-
790
- # Run tests
791
- bundle exec rspec
792
-
793
- # Run specific test
794
- bundle exec rspec spec/ruby_spriter/processor_spec.rb
795
-
796
- # Check code coverage
797
- bundle exec rspec
798
- # Opens coverage/index.html
799
- ```
800
-
801
- ### Project Structure
802
-
803
- ```
804
- ruby-spriter/
805
- ├── bin/
806
- │ └── ruby_spriter # CLI executable
807
- ├── lib/
808
- │ └── ruby_spriter/
809
- │ ├── cli.rb # Command-line interface
810
- │ ├── processor.rb # Main orchestration
811
- │ ├── video_processor.rb
812
- │ ├── gimp_processor.rb
813
- │ ├── consolidator.rb
814
- │ ├── batch_processor.rb # v0.6.7+
815
- │ ├── compression_manager.rb # v0.6.7+
816
- │ ├── metadata_manager.rb
817
- │ ├── dependency_checker.rb
818
- │ ├── platform.rb
819
- │ └── utils/ # Helper modules
820
- ├── spec/ # RSpec tests (313 examples)
821
- ├── .claude/
822
- │ └── agents/ # Custom Claude Code agent config
823
- ├── CLAUDE.md # Developer documentation
824
- ├── CHANGELOG.md # Version history
825
- └── README.md # This file
826
- ```
827
-
828
- ### Running from Source
829
-
830
- ```bash
831
- # Without installing gem
832
- ruby -Ilib bin/ruby_spriter --video test.mp4
833
-
834
- # Or use bundle exec
835
- bundle exec ruby_spriter --video test.mp4
836
- ```
837
-
838
- ---
839
-
840
- ## 🤝 Contributing
841
-
842
- Contributions are welcome! This project follows strict **Test-Driven Development (TDD)** practices.
843
-
844
- ### Development Workflow
845
-
846
- 1. **Fork the repository**
847
- 2. **Create a feature branch** (`git checkout -b feature/amazing-feature`)
848
- 3. **Follow TDD Red-Green-Refactor cycle:**
849
- - ✅ **Red**: Write ONE test → Run it → Verify it FAILS
850
- - ✅ **Green**: Write minimal code → Run test → Verify it PASSES
851
- - ✅ **Refactor**: Clean up → Run all tests → Verify still passing
852
- - ✅ **Repeat** for each new test
853
- 4. **Ensure all tests pass** (`bundle exec rspec`)
854
- 5. **Update documentation** (README.md, CHANGELOG.md, CLAUDE.md)
855
- 6. **Commit your changes** (`git commit -m 'Add amazing feature'`)
856
- 7. **Push to the branch** (`git push origin feature/amazing-feature`)
857
- 8. **Open a Pull Request**
858
-
859
- ### Agent Configuration
860
-
861
- This project includes a custom Claude Code agent (`.claude/agents/ruby-spriter-architect.md`) that enforces:
862
- - Strict TDD (Red-Green-Refactor) workflow
863
- - Architecture consistency
864
- - Documentation maintenance
865
- - Cross-platform compatibility
866
- - Test coverage requirements
867
-
868
- The agent configuration is version-controlled and shared across the team.
869
-
870
- ---
871
-
872
- ## 📄 License
873
-
874
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
875
-
876
- ---
877
-
878
- ## 🔗 Links
879
-
880
- - **GitHub**: [https://github.com/scooter-indie/ruby-spriter](https://github.com/scooter-indie/ruby-spriter)
881
- - **Issues**: [https://github.com/scooter-indie/ruby-spriter/issues](https://github.com/scooter-indie/ruby-spriter/issues)
882
- - **Changelog**: [CHANGELOG.md](CHANGELOG.md)
883
-
884
- ---
885
-
886
- ## 🙏 Acknowledgments
887
-
888
- - **FFmpeg** - Video processing foundation
889
- - **GIMP** - Professional image manipulation
890
- - **ImageMagick** - Metadata and image operations
891
- - **Ruby Community** - Excellent standard library
892
-
893
- ---
894
-
895
- ## 📖 See Also
896
-
897
- - [CLAUDE.md](CLAUDE.md) - Detailed developer documentation and architecture guide
898
- - [CHANGELOG.md](CHANGELOG.md) - Version history and release notes
899
-
900
- ---
901
-
902
- **Made with ❤️ for game developers**
1
+ # Ruby Spriter v0.7.0.1
2
+
3
+ [![Ruby](https://img.shields.io/badge/Ruby-2.7+-red.svg)](https://www.ruby-lang.org/)
4
+ [![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5
+ [![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey.svg)]()
6
+
7
+ **Professional MP4 to Spritesheet Converter with Advanced Image Processing**
8
+
9
+ A powerful cross-platform Ruby tool for creating high-quality spritesheets from video files and processing them with professional-grade image manipulation. Perfect for game development workflows, particularly with Godot Engine.
10
+
11
+ ---
12
+
13
+ ## ✨ Key Features
14
+
15
+ - 🎬 **Video to Spritesheet** - Extract frames from MP4 videos using FFmpeg
16
+ - 🖼️ **Advanced Image Processing** - Scale, sharpen, and remove backgrounds with precision
17
+ - 🎨 **Quality Enhancement** - 5 interpolation methods and configurable unsharp masking
18
+ - 🎞️ **Frame-by-Frame Processing** - Process each video frame individually for varying backgrounds (v0.7.0.1+)
19
+ - 📐 **Spritesheet Consolidation** - Merge multiple spritesheets vertically
20
+ - 📊 **Metadata Management** - Embed, verify, and add grid information to PNG files
21
+ - 📦 **Batch Processing** - Process multiple MP4 files in a directory automatically (v0.6.7+)
22
+ - 🗜️ **Maximum Compression** - Optimal PNG compression while preserving metadata (v0.6.7+)
23
+ - 🌍 **Cross-Platform** - Works seamlessly on Windows, Linux, and macOS
24
+ - 🧪 **Production Ready** - Comprehensive RSpec test coverage (512+ tests)
25
+
26
+ ---
27
+
28
+ ## 🚀 Quick Start
29
+
30
+ ### Install
31
+
32
+ ```bash
33
+ gem install ruby_spriter
34
+ ```
35
+
36
+ ### Verify Installation
37
+
38
+ ```bash
39
+ ruby_spriter --check-dependencies
40
+ ```
41
+
42
+ ### Basic Usage
43
+
44
+ ```bash
45
+ # Create 4x4 grid with 16 frames
46
+ ruby_spriter --video input.mp4
47
+
48
+ # Remove background
49
+ ruby_spriter --video input.mp4 --remove-bg
50
+
51
+ # Scale and compress
52
+ ruby_spriter --video input.mp4 --scale 50 --max-compress
53
+
54
+ # Batch process entire directory
55
+ ruby_spriter --batch --dir "videos/" --remove-bg
56
+ ```
57
+
58
+ ---
59
+
60
+ ## 📚 Documentation
61
+
62
+ Complete documentation is organized into focused guides:
63
+
64
+ | Guide | Purpose |
65
+ |-------|---------|
66
+ | **[Installation Guide](docs/INSTALLATION.md)** | Prerequisites, installation methods, and verification |
67
+ | **[Usage Reference](docs/USAGE.md)** | Complete CLI options and command examples |
68
+ | **[Features Overview](docs/FEATURES.md)** | All capabilities and image processing features |
69
+ | **[Advanced Features](docs/ADVANCED.md)** | Batch processing, compression, consolidation, etc. |
70
+ | **[Architecture Guide](docs/ARCHITECTURE.md)** | System design, processing pipelines, components |
71
+ | **[Development Guide](docs/DEVELOPMENT.md)** | Contributing, testing, and development setup |
72
+ | **[Use Cases & Examples](docs/USE_CASES.md)** | Real-world scenarios and game development workflows |
73
+
74
+ ---
75
+
76
+ ## 📋 Requirements
77
+
78
+ ### External Dependencies
79
+
80
+ | Tool | Purpose |
81
+ |------|---------|
82
+ | **FFmpeg** | Video frame extraction |
83
+ | **ImageMagick** | Metadata and image processing |
84
+ | **GIMP** | Advanced scaling and background removal |
85
+ | **Xvfb** | Virtual display (Linux only) |
86
+
87
+ ### Ruby Version
88
+
89
+ - Ruby 2.7.0 or higher
90
+ - No runtime gem dependencies (uses Ruby standard library)
91
+
92
+ ### Supported Formats
93
+
94
+ - **Video Input**: MP4 only
95
+ - **Image Input/Output**: PNG only
96
+
97
+ ---
98
+
99
+ ## 💡 Common Workflows
100
+
101
+ ### Game Development
102
+
103
+ ```bash
104
+ # Character animation for Godot
105
+ ruby_spriter --video character_walk.mp4 \
106
+ --frames 16 --columns 4 \
107
+ --scale 50 --remove-bg --sharpen
108
+
109
+ # VFX effects with high frame count
110
+ ruby_spriter --video explosion.mp4 \
111
+ --frames 64 --columns 8 \
112
+ --scale 75 --interpolation nohalo
113
+
114
+ # Consolidate 8-directional walk cycles
115
+ ruby_spriter --consolidate --dir "walk_cycles/" \
116
+ --output character_walk_all.png
117
+ ```
118
+
119
+ ### Batch Processing
120
+
121
+ ```bash
122
+ # Process entire animation library
123
+ ruby_spriter --batch --dir "raw_animations/" \
124
+ --outputdir "game_assets/" \
125
+ --scale 50 --remove-bg --max-compress
126
+
127
+ # Batch with consolidation
128
+ ruby_spriter --batch --dir "states/" \
129
+ --batch-consolidate --output character_all.png
130
+ ```
131
+
132
+ ### Varying Backgrounds
133
+
134
+ ```bash
135
+ # Frame-by-frame for videos with changing backgrounds
136
+ ruby_spriter --video animation.mp4 \
137
+ --remove-bg --by-frame \
138
+ --frames 32 --columns 8
139
+
140
+ # Batch process with frame-by-frame
141
+ ruby_spriter --batch --dir "animations/" \
142
+ --remove-bg --by-frame --scale 50
143
+ ```
144
+
145
+ ---
146
+
147
+ ## 🔧 Advanced Features
148
+
149
+ - **Inner Background Removal** - Remove interior background regions (v0.7.0+)
150
+ - **Threshold Stepping** - Process with multiple thresholds for superior edges (v0.7.0+)
151
+ - **Ghost Edge Prevention** - Multi-pass cleanup of semi-transparent artifacts (v0.7.0+)
152
+ - **Smoke Detection** - Identify and remove transparency gradients (v0.7.0+)
153
+ - **Frame Extraction** - Extract specific frames by number (v0.7.0+)
154
+ - **Metadata Addition** - Add grid information to external spritesheets (v0.7.0+)
155
+ - **Cell-Based Cleanup** - Post-process residual backgrounds per-cell (v0.7.0.1+, experimental)
156
+
157
+ ---
158
+
159
+ ## 📄 License
160
+
161
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
162
+
163
+ ---
164
+
165
+ ## 🔗 Links
166
+
167
+ - **GitHub**: [https://github.com/scooter-indie/ruby-spriter](https://github.com/scooter-indie/ruby-spriter)
168
+ - **Issues**: [https://github.com/scooter-indie/ruby-spriter/issues](https://github.com/scooter-indie/ruby-spriter/issues)
169
+ - **Changelog**: [CHANGELOG.md](CHANGELOG.md)
170
+ - **Developer Docs**: [CLAUDE.md](CLAUDE.md)
171
+
172
+ ---
173
+
174
+ ## 🙏 Acknowledgments
175
+
176
+ - **FFmpeg** - Video processing foundation
177
+ - **GIMP** - Professional image manipulation
178
+ - **ImageMagick** - Metadata and image operations
179
+ - **Ruby Community** - Excellent standard library
180
+
181
+ ---
182
+
183
+ **Made with ❤️ for game developers**