<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: zheng</title>
    <description>The latest articles on DEV Community by zheng (@zheng_9094a855fc59df623af).</description>
    <link>https://dev.to/zheng_9094a855fc59df623af</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4135817%2Fda29bc88-8506-4aa5-9949-00a01e9d9ee5.png</url>
      <title>DEV Community: zheng</title>
      <link>https://dev.to/zheng_9094a855fc59df623af</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zheng_9094a855fc59df623af"/>
    <language>en</language>
    <item>
      <title>GIF to sprite sheet: the pipeline I use for Phaser and Godot, and where it breaks</title>
      <dc:creator>zheng</dc:creator>
      <pubDate>Sat, 26 Sep 2026 11:30:55 +0000</pubDate>
      <link>https://dev.to/zheng_9094a855fc59df623af/gif-to-sprite-sheet-the-pipeline-i-use-for-phaser-and-godot-and-where-it-breaks-4mpm</link>
      <guid>https://dev.to/zheng_9094a855fc59df623af/gif-to-sprite-sheet-the-pipeline-i-use-for-phaser-and-godot-and-where-it-breaks-4mpm</guid>
      <description>&lt;p&gt;An animated GIF is the easiest way to &lt;em&gt;share&lt;/em&gt; a sprite animation and one of the worst ways to &lt;em&gt;ship&lt;/em&gt;&lt;br&gt;
one. It has no alpha channel worth the name, it re-renders every frame from a delta-encoded stream, and&lt;br&gt;
your engine can't index a frame in it. So the first thing I do with any GIF that contains animation I&lt;br&gt;
actually want in a game is convert it into a sprite sheet plus an atlas file.&lt;/p&gt;

&lt;p&gt;This is the pipeline I use, the parts that bit me, and the code for both Phaser and Godot.&lt;/p&gt;
&lt;h2&gt;
  
  
  What a GIF actually gives you
&lt;/h2&gt;

&lt;p&gt;"Just extract the frames" hides three problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Frame disposal.&lt;/strong&gt; Each frame is a delta against the previous one, with a disposal method saying what
to do with the previous frame's pixels (&lt;code&gt;keep&lt;/code&gt;, &lt;code&gt;restore to background&lt;/code&gt;, &lt;code&gt;restore to previous&lt;/code&gt;).
Extract frames by reading byte offsets naively and you get smeared, partially updated images. You need
a real decoder that composites each frame onto the running canvas — the browser gives you this for
free via &lt;code&gt;ImageDecoder&lt;/code&gt; or by drawing an &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; that points at the GIF and reading frames off a canvas.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1-bit transparency.&lt;/strong&gt; GIF pixels are either fully opaque or fully transparent. No partial alpha. So
anti-aliased edges that looked fine on a flat background turn into a hard fringe the moment you put the
sprite on a different background. If the source was a game animation, check whether the GIF was
exported &lt;em&gt;from&lt;/em&gt; a PNG sequence — the original PNGs are always better input than the GIF.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Palette quantization.&lt;/strong&gt; 256 colours per frame, usually with dithering. Your character's smooth
gradient is now noise. The sprite may be 2x the size as a sheet but that's a good trade.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Practical consequence: the GIF is fine as a source of &lt;strong&gt;frame order and timing&lt;/strong&gt;, and poor as a source of&lt;br&gt;
&lt;strong&gt;colour&lt;/strong&gt;. If you have the original frames, use those.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1 — get the frames out
&lt;/h2&gt;

&lt;p&gt;Command line, if you're already in a pipeline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# one PNG per GIF frame, keeping the composited result&lt;/span&gt;
ffmpeg &lt;span class="nt"&gt;-i&lt;/span&gt; run.gif &lt;span class="nt"&gt;-vsync&lt;/span&gt; 0 &lt;span class="nt"&gt;-f&lt;/span&gt; image2 frame_%04d.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-vsync 0&lt;/code&gt; matters: without it ffmpeg duplicates or drops frames to hit a constant rate and your walk&lt;br&gt;
cycle gains or loses a frame.&lt;/p&gt;

&lt;p&gt;In the browser, with no upload, the same job is a few lines against a canvas — decode the GIF, draw each&lt;br&gt;
frame, &lt;code&gt;toBlob()&lt;/code&gt; it. That's the path I use when the asset isn't mine to send to a server, and it's the&lt;br&gt;
reason the tool I maintain, &lt;a href="https://spritesheetbuilder.com/gif-to-sprite-sheet" rel="noopener noreferrer"&gt;GIF to sprite sheet&lt;/a&gt;,&lt;br&gt;
runs entirely client-side (&lt;code&gt;createImageBitmap&lt;/code&gt; per frame, pack, &lt;code&gt;canvas.toBlob&lt;/code&gt;, ZIP in memory).&lt;/p&gt;

&lt;p&gt;Either way, &lt;strong&gt;name the frames after the action&lt;/strong&gt;, not after the index you happened to extract them in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;idle0001.png  idle0002.png  idle0003.png  idle0004.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Four digits, zero-padded, action name first. This is not cosmetic — the FNF/Flixel family derives the&lt;br&gt;
animation from the name prefix, and your own importer will thank you when &lt;code&gt;walk&lt;/code&gt; and &lt;code&gt;walk_back&lt;/code&gt; both&lt;br&gt;
exist.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2 — pack them
&lt;/h2&gt;

&lt;p&gt;Two layouts, and picking wrong costs you either bytes or correctness:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Grid&lt;/strong&gt; — every cell the same size, frame N at &lt;code&gt;(col, row)&lt;/code&gt;. Simple, and the metadata is tiny. Right
for an animation whose frames are all the same canvas (most character animations). Wastes space when
frames vary in size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auto-pack&lt;/strong&gt; — tight rows around differently sized rectangles. Saves texture space, but frame positions
are now irregular, so &lt;strong&gt;the atlas metadata stops being optional&lt;/strong&gt;. If you ever see a sheet in the wild
with no JSON next to it, that's a grid.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two settings that are not optional in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Padding&lt;/strong&gt; — empty pixels around the &lt;em&gt;whole&lt;/em&gt; sheet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spacing&lt;/strong&gt; — empty pixels &lt;em&gt;between&lt;/em&gt; frames.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both exist to stop &lt;strong&gt;texture bleeding&lt;/strong&gt;: when the GPU samples a sprite with linear filtering or mipmaps at&lt;br&gt;
a non-integer position, it reads a fraction of the neighbouring texel. On a tightly packed sheet that&lt;br&gt;
fraction is the next frame's elbow. A 2 px gutter makes the artifact disappear. If your sprites still&lt;br&gt;
show a one-pixel bright edge after adding spacing, you're probably seeing premultiplied-alpha rounding,&lt;br&gt;
not bleeding — export as PNG-32 and draw at integer coordinates.&lt;/p&gt;

&lt;p&gt;One thing worth knowing when you compare tools: &lt;strong&gt;rotated frames&lt;/strong&gt;. Some packers rotate frames 90° to save&lt;br&gt;
space. That's fine for a generic engine but breaks frame-name/atlas conventions that assume unrotated&lt;br&gt;
frames. If the pipeline feeds an engine with a naming convention, keep rotation off.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3 — wire it into the engine
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Phaser 3
&lt;/h3&gt;

&lt;p&gt;The atlas JSON is TexturePacker-shaped, so the built-in loader takes it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;preload&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// sheet.png + sheet.json produced from the GIF&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;load&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;atlas&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hero&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;assets/hero.png&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;assets/hero.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// frame names came from the extraction step: idle0001, idle0002, ...&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;frames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textures&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hero&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;getFrameNames&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;       &lt;span class="c1"&gt;// ["idle0001", ...]&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;idle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;frames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;anims&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;frames&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;idle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hero&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;frame&lt;/span&gt; &lt;span class="p"&gt;})),&lt;/span&gt;
    &lt;span class="na"&gt;frameRate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sprite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;160&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hero&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;play&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;idle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The frames array must be sorted explicitly — the loader hands them back in atlas order, which for an&lt;br&gt;
auto-packed sheet is whatever order the packer placed them in, not animation order. This is the single&lt;br&gt;
most common bug I hit: the animation plays, the poses are correct, and they arrive shuffled.&lt;/p&gt;
&lt;h3&gt;
  
  
  Godot 4
&lt;/h3&gt;

&lt;p&gt;Godot wants a &lt;code&gt;SpriteFrames&lt;/code&gt; resource. Either import the atlas with an editor plugin, or build the&lt;br&gt;
resource directly — a &lt;code&gt;.tres&lt;/code&gt; with one animation per action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sf&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SpriteFrames&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;sf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remove_animation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_animation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"idle"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;set_animation_speed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"idle"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;12.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;set_animation_loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"idle"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sheet&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"res://assets/hero.png"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;Texture2D&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;                     &lt;span class="c1"&gt;# 4 columns of a grid sheet&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AtlasTexture&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;atlas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sheet&lt;/span&gt;
    &lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;region&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Rect2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;sf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_frame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"idle"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;AtlasTexture.region&lt;/code&gt; is exact pixels — no trimming, no rotation. That's why the grid layout is the&lt;br&gt;
friendlier one for hand-written import code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Unity
&lt;/h3&gt;

&lt;p&gt;Sprite Atlas with multiple sprites, or the texture's Sprite Mode set to &lt;em&gt;Multiple&lt;/em&gt; with the atlas JSON&lt;br&gt;
imported as sprite metadata. Unity's convention is &lt;code&gt;{x, y, width, height}&lt;/code&gt; while Phaser's frame records&lt;br&gt;
use &lt;code&gt;{x, y, w, h}&lt;/code&gt; — a copy-paste of a loader between the two silently produces zero-sized frames&lt;br&gt;
rather than an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  The gotchas, in one list
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sort frames by name before building the animation.&lt;/strong&gt; Atlas order ≠ animation order.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spacing ≥ 2 px&lt;/strong&gt; if you use linear filtering or mipmaps; 0 is fine only for nearest-neighbour pixel
art drawn at integer positions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep rotation off&lt;/strong&gt; when a naming convention is involved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch the sheet size limit.&lt;/strong&gt; 4096×4096 is the common engine/GPU ceiling; a long GIF will blow past it
and you want the packer to tell you, not the driver.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GIF in, PNG out.&lt;/strong&gt; Never ship the GIF itself: no alpha, no mipmaps, no atlas.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Triple-check the transparent background.&lt;/strong&gt; If the GIF was recorded against a checkerboard, that
checkerboard is now part of your sprite.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sanity check before you export
&lt;/h2&gt;

&lt;p&gt;Play the sheet back at the intended frame rate &lt;em&gt;before&lt;/em&gt; it reaches the engine. A missing pose, a reversed&lt;br&gt;
frame or a duplicated one is instant to spot in a preview and annoying to debug inside a game loop. Any&lt;br&gt;
decent packer has a preview for exactly this reason; the &lt;a href="https://spritesheetbuilder.com/engines" rel="noopener noreferrer"&gt;engine guides&lt;/a&gt;&lt;br&gt;
section covers the per-engine import steps in more detail.&lt;/p&gt;

&lt;p&gt;If you want to try the pipeline above without installing anything, the GIF → sheet step is a browser tool:&lt;br&gt;
drop the GIF in, it decodes the frames locally, you reorder if needed, and you get a PNG plus JSON or XML&lt;br&gt;
out. Nothing is uploaded, and the free path needs no account.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Shipping a polyphonic audio-to-MIDI converter that runs entirely in the browser</title>
      <dc:creator>zheng</dc:creator>
      <pubDate>Mon, 21 Sep 2026 13:17:54 +0000</pubDate>
      <link>https://dev.to/zheng_9094a855fc59df623af/shipping-a-polyphonic-audio-to-midi-converter-that-runs-entirely-in-the-browser-2dim</link>
      <guid>https://dev.to/zheng_9094a855fc59df623af/shipping-a-polyphonic-audio-to-midi-converter-that-runs-entirely-in-the-browser-2dim</guid>
      <description>&lt;p&gt;Almost every "audio to MIDI" tool follows the same shape: upload the file, wait, download a &lt;code&gt;.mid&lt;/code&gt;. That is&lt;br&gt;
fine until you notice what you just handed over — a demo, an unfinished song, a client's reference track.&lt;/p&gt;

&lt;p&gt;So the constraint I set for Tonera was: &lt;strong&gt;the standard conversion must never upload the audio.&lt;/strong&gt; Everything&lt;br&gt;
below is what that constraint costs, and what I got for paying it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually runs in the page
&lt;/h2&gt;

&lt;p&gt;The transcription model is Spotify's &lt;a href="https://github.com/spotify/basic-pitch" rel="noopener noreferrer"&gt;Basic Pitch&lt;/a&gt; — an open-source&lt;br&gt;
polyphonic pitch-detection model. It does not need a GPU cluster; it needs a fixed input shape and a bounded&lt;br&gt;
amount of memory, which makes it a candidate for running client-side instead of behind an API.&lt;/p&gt;

&lt;p&gt;The pipeline in the browser is deliberately boring:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;decode the file the user dropped (AudioContext / WebAudio),&lt;/li&gt;
&lt;li&gt;downmix to &lt;strong&gt;22.05 kHz mono&lt;/strong&gt; — the sample rate the model expects,&lt;/li&gt;
&lt;li&gt;run the model, which returns pitch/onset/contour estimates,&lt;/li&gt;
&lt;li&gt;turn those estimates into notes the user can inspect and edit,&lt;/li&gt;
&lt;li&gt;export.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Steps 1, 2, 4 and 5 are ordinary deterministic code. Only step 3 is a model. Keeping that line sharp matters:&lt;br&gt;
it means the &lt;em&gt;editable&lt;/em&gt; part of the result (note boundaries, quantisation, notation) can be recomputed&lt;br&gt;
instantly and reproducibly, while the model runs exactly once per file.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ceiling nobody advertises: memory
&lt;/h2&gt;

&lt;p&gt;The honest reason there is a ten-minute cap is RAM, not licensing. Decoded 22.05 kHz mono audio plus the&lt;br&gt;
model's intermediate tensors have to fit in a browser tab; a phone and a desktop are very different budgets.&lt;br&gt;
Instead of silently failing on a long rehearsal recording, the limit is stated up front.&lt;/p&gt;

&lt;p&gt;The practical workaround is the same one audio engineers already use: &lt;strong&gt;split around musical sections and&lt;br&gt;
convert the passage you actually need.&lt;/strong&gt; You rarely want MIDI for the four minutes of tuning and talking at&lt;br&gt;
the start of a rehearsal take.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where transcription actually goes wrong
&lt;/h2&gt;

&lt;p&gt;Not where people assume. It is not "MP3 bad, WAV good" — converting an MP3 to WAV before uploading changes&lt;br&gt;
the container and restores nothing that the encoder already discarded.&lt;/p&gt;

&lt;p&gt;What breaks transcription is &lt;em&gt;evidence&lt;/em&gt;, not bitrate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;compression artefacts&lt;/strong&gt; — short, blurred attacks in the high end look like note onsets;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;reverb and room sound&lt;/strong&gt; — tails smear note boundaries;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;overlapping harmonics&lt;/strong&gt; — a dense mix asks the model to separate instruments it was never told to separate;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;quiet grace notes&lt;/strong&gt; — the first thing an encoder spends fewer bits on.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is why the result view is not a download button. It is a note map plus five controls: onset threshold,&lt;br&gt;
frame threshold, minimum note length, and a low/high frequency range — with the discarded candidates still&lt;br&gt;
visible, so raising a threshold is a decision you can see rather than trust.&lt;/p&gt;

&lt;p&gt;Post-processing does the rest of the cleanup: quantise to a grid at the detected tempo, split into left/right&lt;br&gt;
hand, smooth velocities, transpose. All of it re-runs instantly and free, because none of it touches the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exports are where the tool earns its place in a workflow
&lt;/h2&gt;

&lt;p&gt;One detection pass, several outputs, because the next step differs by person:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MIDI&lt;/strong&gt; — straight into a DAW;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MusicXML&lt;/strong&gt; — into notation software with real engraving;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PDF&lt;/strong&gt; — for reading, printing, handing to a player;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ABC notation&lt;/strong&gt; — for text-based / folk workflows;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;chord chart&lt;/strong&gt; — for the "I just need the changes" case.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MusicXML→MIDI, MIDI preview and WAV synthesis are deterministic converts, not generative: if you ask for the&lt;br&gt;
same file twice you get byte-comparable behaviour, not a new opinion.&lt;/p&gt;

&lt;h2&gt;
  
  
  When server-side work is justified
&lt;/h2&gt;

&lt;p&gt;Dense mixes are a genuine hard case, and pretending otherwise would be dishonest. So there is an optional&lt;br&gt;
high-precision mode that runs &lt;strong&gt;HTDemucs&lt;/strong&gt; stem separation before transcription — the audio &lt;em&gt;is&lt;/em&gt; uploaded for&lt;br&gt;
that path, it is labelled before it happens, and it costs credits because it consumes real compute.&lt;/p&gt;

&lt;p&gt;Retention is stated rather than implied: temporary source objects are covered by a one-day lifecycle rule and&lt;br&gt;
generated stems by a seven-day rule. If a workflow does not need that mode, nothing leaves the device at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four things I would tell anyone building this
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Do not promise one accuracy number.&lt;/strong&gt; Results depend on instrumentation, room, compression and overlap.
Publish the limits next to the tool; it is the difference between a demo and something a musician trusts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test on real material&lt;/strong&gt; — phone memos, 128 kbps downloads, full mixes. A clean studio solo makes every
model look good.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expose the uncertainty.&lt;/strong&gt; Discarded notes are as informative as kept ones; a threshold without visible
consequences is just a slider.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the model at one end of the pipeline.&lt;/strong&gt; The moment transcription output is frozen into notes, the
rest should be cheap, fast and reversible.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tonera is where I put this together — it runs in the browser, the standard conversion is free and needs no&lt;br&gt;
account, and the accuracy trade-offs are documented rather than buried:&lt;br&gt;
&lt;strong&gt;&lt;a href="https://tonera.app" rel="noopener noreferrer"&gt;https://tonera.app&lt;/a&gt;&lt;/strong&gt; · method and limits: &lt;a href="https://tonera.app/blog/basic-pitch-accuracy-guide" rel="noopener noreferrer"&gt;https://tonera.app/blog/basic-pitch-accuracy-guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you try it on something and the result is bad, that is useful information — the failure modes above are&lt;br&gt;
exactly what I want to hear about.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>audio</category>
      <category>midi</category>
    </item>
  </channel>
</rss>
