<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Gifsicle on foosel.net</title><link>https://foosel.net/tags/gifsicle/</link><description>Recent content in Gifsicle on foosel.net</description><generator>Hugo</generator><language>en-us</language><copyright>Gina Häußge (foosel)</copyright><lastBuildDate>Tue, 15 Oct 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://foosel.net/tags/gifsicle/feed.xml" rel="self" type="application/rss+xml"/><item><title>How to make transparent GIFs more easily sharable by adding a checkerboard background</title><link>https://foosel.net/til/how-to-make-transparent-gifs-easier-shareable-by-adding-a-checkerboard-background/</link><pubDate>Tue, 15 Oct 2024 00:00:00 +0000</pubDate><guid>https://foosel.net/til/how-to-make-transparent-gifs-easier-shareable-by-adding-a-checkerboard-background/</guid><description>&lt;p&gt;I&amp;rsquo;m currently taking part in the &lt;a href="https://social.horrorhub.club/@stina_marie/113220760493893634"&gt;&amp;quot;#hARToween&amp;quot; daily art challenge&lt;/a&gt;, as I want to
work on my pixelart skills and drawing a 128x128px pixel drawing each day&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt; for a month seemed
like a good idea. You can follow my posts &lt;a href="https://chaos.social/@foosel/113233763230193057"&gt;in this thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m using &lt;a href="https://aseprite.org/"&gt;Aseprite&lt;/a&gt;, and recently came across &lt;a href="https://sprngr.itch.io/aseprite-record"&gt;the &amp;ldquo;record for aseprite&amp;rdquo; script for it&lt;/a&gt;
that allows taking regular snapshots of what I&amp;rsquo;m currently drawing so a timelapse can be created from
that. And that works nicely, but I had to realize that the timelapse would come with transparency until
I came to the background during my drawing, which looked really weird when sharing the resulting GIF.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I&rsquo;m currently taking part in the <a href="https://social.horrorhub.club/@stina_marie/113220760493893634">&quot;#hARToween&quot; daily art challenge</a>, as I want to
work on my pixelart skills and drawing a 128x128px pixel drawing each day<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> for a month seemed
like a good idea. You can follow my posts <a href="https://chaos.social/@foosel/113233763230193057">in this thread</a>.</p>
<p>I&rsquo;m using <a href="https://aseprite.org/">Aseprite</a>, and recently came across <a href="https://sprngr.itch.io/aseprite-record">the &ldquo;record for aseprite&rdquo; script for it</a>
that allows taking regular snapshots of what I&rsquo;m currently drawing so a timelapse can be created from
that. And that works nicely, but I had to realize that the timelapse would come with transparency until
I came to the background during my drawing, which looked really weird when sharing the resulting GIF.</p>
<p>So I looked into adding the usual transparency checkerboard background to the GIF with a quick script,
and of course, <a href="https://imagemagick.org/">ImageMagick</a> once more to the rescue. Alas, the resulting GIF was quite large and ImageMagick&rsquo;s
optimization options caused glitches in the GIF. So I looked for another option to optimize the GIF and
came across <a href="https://www.lcdf.org/gifsicle/">gifsicle</a>.</p>
<p>The result is this bash script which will take a GIF and an optional background image to set,
add the background (or a freshly generated checkerboard pattern of the right size) to the GIF, then compress
the GIF:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>GIF<span style="color:#f92672">=</span>$1
</span></span><span style="display:flex;"><span>BG<span style="color:#f92672">=</span>$2
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>BASE<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>basename <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>GIF%.*<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>OUTPUT<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span>$BASE<span style="color:#e6db74">.bg.gif&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> -f <span style="color:#e6db74">&#34;</span>$BG<span style="color:#e6db74">&#34;</span> <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>    echo <span style="color:#e6db74">&#34;Adding background image </span>$BG<span style="color:#e6db74"> to all frames of </span>$GIF<span style="color:#e6db74">...&#34;</span>
</span></span><span style="display:flex;"><span>    magick <span style="color:#e6db74">&#34;</span>$GIF<span style="color:#e6db74">&#34;</span> -coalesce null: <span style="color:#e6db74">&#34;</span>$BG<span style="color:#e6db74">&#34;</span> -compose dstOver -layers composite <span style="color:#e6db74">&#34;</span>$OUTPUT<span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">else</span>
</span></span><span style="display:flex;"><span>    size<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>gifsicle --sinfo <span style="color:#e6db74">&#34;</span>$GIF<span style="color:#e6db74">&#34;</span> | grep <span style="color:#e6db74">&#34;logical screen&#34;</span> | xargs echo -n | cut -d<span style="color:#e6db74">&#34; &#34;</span> -f 3<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    echo <span style="color:#e6db74">&#34;Generating a </span>$size<span style="color:#e6db74"> checkerboard pattern and adding it as background to all frames of </span>$GIF<span style="color:#e6db74">...&#34;</span>
</span></span><span style="display:flex;"><span>    magick <span style="color:#e6db74">&#34;</span>$GIF<span style="color:#e6db74">&#34;</span> -coalesce null: <span style="color:#ae81ff">\(</span> -size $size tile:pattern:checkerboard <span style="color:#ae81ff">\)</span> -compose dstOver -layers composite <span style="color:#e6db74">&#34;</span>$OUTPUT<span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>echo <span style="color:#e6db74">&#34;Optimizing </span>$OUTPUT<span style="color:#e6db74">...&#34;</span>
</span></span><span style="display:flex;"><span>gifsicle --batch -O3 --lossy<span style="color:#f92672">=</span><span style="color:#ae81ff">35</span> <span style="color:#e6db74">&#34;</span>$OUTPUT<span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>echo <span style="color:#e6db74">&#34;...done!&#34;</span>
</span></span></code></pre></div><p>Example call:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-plain" data-lang="plain"><span style="display:flex;"><span>$ gif_bg 14.gif 
</span></span><span style="display:flex;"><span>Generating a 256x256 checkerboard pattern and adding it as background to all frames of 14.gif...
</span></span><span style="display:flex;"><span>Optimizing 14.bg.gif...
</span></span><span style="display:flex;"><span>...done!
</span></span></code></pre></div><p>I&rsquo;m quite happy with the result:</p>















        
        

        
            
            
        

        
            <blockquote class="toot-blockquote" cite="https://chaos.social@foosel/status/113306303596486838">
                <div class="toot-header">
                    <a class="toot-profile" href="https://chaos.social/@foosel" rel="noopener">
                        <img
                            src="https://assets.chaos.social/accounts/avatars/000/235/099/original/a2e381e9aab4a693.png"
                            alt="Mastodon avatar for @foosel@chaos.social"
                            loading="lazy"
                        />
                    </a>
                    <div class="toot-author">
                        <a class="toot-author-name" href="https://chaos.social/@foosel" rel="noopener">Gina Häußge</a>
                        <a class="toot-author-handle" href="https://chaos.social/@foosel" rel="noopener">@foosel@chaos.social</a>
                    </div>
                </div>
                <p>Now also with a creation timelapse (after I finally managed to get a proper workflow going for that)</p>
                
                    
                        
                    
                    <div class="toot-img-grid-0">
                    
                        
                    
                    </div>
                    
                    
                        
                        
                            
                            <style>
                                .img-f64237a660efa590d99cd4bd48022b22 {
                                    aspect-ratio: 256 / 256;
                                }
                            </style>
                            <div class="ctr toot-video-wrapper">
                                <video loop autoplay muted playsinline controls controlslist="nofullscreen" class="ctr toot-media-img img-f64237a660efa590d99cd4bd48022b22">
                                    <source src="https://assets.chaos.social/media_attachments/files/113/306/301/353/935/058/original/891b82c9cf56ffd5.mp4">
                                    <p class="legal ctr">(Your browser doesn&rsquo;t support the <code>video</code> tag.)</p>
                                </video></div>
                        
                    
                
                
                
                <div class="toot-footer">
                    <a href="https://chaos.social/@foosel/113306303596486838" class="toot-date" rel="noopener">October 14, 2024, 14:43</a>&nbsp;<span class="pokey">(UTC)</span>
                </div>
            </blockquote>
        
    
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>Well, almost, I was at MRMCD and then a bit under the weather after and thus missed some days that I&rsquo;m now trying to catch up on again.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded></item></channel></rss>