diff options
| author | Adam Soltys <[email protected]> | 2026-11-18 22:38:42 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-11-18 22:38:42 -0700 |
| commit | 01c03a199f8aafacfcdbaac30af074dd1d56fc53 (patch) | |
| tree | eef880f8046077edc6d902acb74f90448f8830ef /tools/gif-loop-test.js | |
| parent | cb5826cec34bd6933f1d8d3f1d76629b15ba44a1 (diff) | |
| download | coinosv3-01c03a199f8aafacfcdbaac30af074dd1d56fc53.tar.gz coinosv3-01c03a199f8aafacfcdbaac30af074dd1d56fc53.zip | |
GIFs loop, even ones made to play once. "My gif reply isn't looping" (Adam, 2026-11-19). The GIF from the picker (gifs.nostr.build/5d6fa840….gif, 23 frames) has no loop instruction (the NETSCAPE2.0 extension), so every browser plays it once and stops on its last frame. When the feed makes its copy of a picture, a GIF without the extension now gets "loop forever" written in after its global colour table. That copy, up to 4 MB, is what the post paints, kept on disk like the other copies. A GIF stored before this change is fetched and looped again; one that already loops, and any other picture, is untouched. Patched, that GIF reads as loop 0 with all 23 frames. New gif-loop-test passes; feed-picture-pager-test now checks that a non-looping GIF is painted from a copy that loops. feed-media-cache, gif-picker, feed-media-views and features-smoke pass.HEADmaster
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VMan6TV6sjEZSpqqBen9T5
Diffstat (limited to 'tools/gif-loop-test.js')
| -rw-r--r-- | tools/gif-loop-test.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/gif-loop-test.js b/tools/gif-loop-test.js new file mode 100644 index 0000000..a135e36 --- /dev/null +++ b/tools/gif-loop-test.js @@ -0,0 +1,21 @@ +// A GIF made without a loop instruction plays once in every browser; the +// copy the feed paints from gets "loop forever" added. One that loops +// already, or isn't a GIF, is left alone. +// Run: bun tools/gif-loop-test.js +import { loopGif } from '../src/image-thumbnails.js'; +let ok = true; +const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; }; +const make = (args) => Bun.spawnSync(['ffmpeg', '-loglevel', 'error', '-f', 'lavfi', '-i', 'testsrc=size=64x48:rate=5:duration=1', ...args, '-f', 'gif', 'pipe:1']).stdout; +const once = new Uint8Array(make(['-loop', '-1'])), looping = new Uint8Array(make(['-loop', '0'])); +const has = (b) => Buffer.from(b).includes('NETSCAPE2.0'); +check('ffmpeg made one GIF without a loop and one with', !has(once) && has(looping)); +const fixed = loopGif(once); +check('the one-shot GIF gets the loop extension', !!fixed && has(fixed)); +const i = Buffer.from(fixed).indexOf('NETSCAPE2.0'); +check('…loop forever (count 0), right after the colour table', fixed[i + 11] === 3 && fixed[i + 12] === 1 && fixed[i + 13] === 0 && fixed[i + 14] === 0 && fixed[i + 15] === 0 && fixed[i - 3] === 0x21 && fixed[i - 2] === 0xff); +const probe = Bun.spawnSync(['ffprobe', '-v', 'error', '-count_frames', '-show_entries', 'stream=nb_read_frames', '-of', 'csv=p=0', '-i', 'pipe:0'], { stdin: fixed }).stdout.toString().trim(); +check('the patched GIF still decodes, every frame', probe === '5', probe); +check('a GIF that loops already is left alone', loopGif(looping) === null); +check('not a GIF: left alone', loopGif(new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])) === null); +console.log(ok ? '\n✅ GIFs loop' : '\n❌ failed'); +process.exit(ok ? 0 : 1); |
