<?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: Sunny Radadiya</title>
    <description>The latest articles on DEV Community by Sunny Radadiya (@sunnyradadiya).</description>
    <link>https://dev.to/sunnyradadiya</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%2F4220475%2Fa626bc94-e118-46b9-a388-f7b807f9b1e6.jpg</url>
      <title>DEV Community: Sunny Radadiya</title>
      <link>https://dev.to/sunnyradadiya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sunnyradadiya"/>
    <language>en</language>
    <item>
      <title>How to share a photo as a link (full quality, no app needed)</title>
      <dc:creator>Sunny Radadiya</dc:creator>
      <pubDate>Sun, 22 Nov 2026 15:59:43 +0000</pubDate>
      <link>https://dev.to/sunnyradadiya/how-to-share-a-photo-as-a-link-full-quality-no-app-needed-1a4b</link>
      <guid>https://dev.to/sunnyradadiya/how-to-share-a-photo-as-a-link-full-quality-no-app-needed-1a4b</guid>
      <description>&lt;p&gt;You want to send someone a photo. A screenshot for a bug report, a product shot for a client, ten pictures from the weekend. You attach it, and one of three things happens: it gets compressed, it's too big, or the other person has to download it and find it later.&lt;/p&gt;

&lt;p&gt;A link fixes all three. Here's how to do it well, on any device.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not just attach it?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Chat apps compress photos.&lt;/strong&gt; Most messaging apps shrink images by default to save data. Fine for a meme, bad for a product shot or a design.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Email has a size cap.&lt;/strong&gt; Gmail stops attachments at 25 MB and Outlook.com at 20 MB. A handful of phone photos can pass that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Attachments get lost.&lt;/strong&gt; The file sits in a download folder. A link opens the picture right away, in the browser, on any phone.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pick the right format first
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Best for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JPG&lt;/td&gt;
&lt;td&gt;Photos&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PNG&lt;/td&gt;
&lt;td&gt;Screenshots, logos, anything with text&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WebP&lt;/td&gt;
&lt;td&gt;Light images for the web&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GIF&lt;/td&gt;
&lt;td&gt;Short loops&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HEIC&lt;/td&gt;
&lt;td&gt;iPhone photos (convert to JPG so every browser can open it)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A good host serves your image byte for byte, with no re-compression, so what you upload is what they see.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to turn a photo into a link
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;On a phone:&lt;/strong&gt; open the uploader in your browser, tap it, pick the photo from your library, copy the link.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On a Mac:&lt;/strong&gt; take a screenshot with &lt;code&gt;Cmd+Shift+4&lt;/code&gt;, drag the file onto the uploader, copy the link.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On Windows:&lt;/strong&gt; &lt;code&gt;Win+Shift+S&lt;/code&gt; for a screenshot, save it, drag it onto the uploader, copy the link.&lt;/p&gt;

&lt;p&gt;Then paste the link into Slack, a Jira ticket, an email or a text. The other person taps it and sees the full-size picture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sharing many photos at once
&lt;/h2&gt;

&lt;p&gt;Don't send 30 links. Put the photos in one album and share one link. For events, a shared album where guests add their own photos (via a QR code on the table) saves you from collecting pictures one by one in a group chat.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things worth turning on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A password&lt;/strong&gt;, for anything personal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An expiry date&lt;/strong&gt;, if the photo should only be visible for a while.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;View-only&lt;/strong&gt;, if you'd rather people didn't save it. It deters casual saving, but no web page can fully stop a screenshot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A QR code&lt;/strong&gt;, for a printed flyer, a frame or a product tag. If you replace the photo later, the same QR code shows the new one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A data point
&lt;/h2&gt;

&lt;p&gt;On Link in Seconds, the median image shared between October 4 and November 2, 2026 was &lt;strong&gt;1.2 MB&lt;/strong&gt;. Most photos are small; the pain is the compression and the clutter, not the size.&lt;/p&gt;




&lt;p&gt;I build &lt;a href="https://linkinseconds.com/image-to-link" rel="noopener noreferrer"&gt;Link in Seconds&lt;/a&gt;, which does exactly this: drop a photo, get a clean link and a QR code, and see how many times it was opened. Free up to 5 MB of files in total, no card needed. Happy to answer questions in the comments.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>unsplash</category>
    </item>
    <item>
      <title>How to share a single HTML file as a live link (and why it shows as code)</title>
      <dc:creator>Sunny Radadiya</dc:creator>
      <pubDate>Sun, 22 Nov 2026 14:52:49 +0000</pubDate>
      <link>https://dev.to/sunnyradadiya/how-to-share-a-single-html-file-as-a-live-link-and-why-it-shows-as-code-1mif</link>
      <guid>https://dev.to/sunnyradadiya/how-to-share-a-single-html-file-as-a-live-link-and-why-it-shows-as-code-1mif</guid>
      <description>&lt;p&gt;You made a page. A Claude artifact, a ChatGPT canvas, a Lighthouse report, a small calculator. Now you want to send it to someone, and it either downloads as a file or shows raw source code on their phone.&lt;/p&gt;

&lt;p&gt;Here's why that happens, and the quickest ways to share it as a live page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a .html file won't just open
&lt;/h2&gt;

&lt;p&gt;An HTML file only becomes a page when a browser loads it from a web address. Email it and it arrives as a file to download. Put it in Google Drive or Dropbox and you get a preview or a download, because running someone else's HTML on a storage domain would be a security hole. Google ended Drive web hosting back in 2016.&lt;/p&gt;

&lt;p&gt;So you need a host whose job is to serve that file as a page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make it one self-contained file first
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Put CSS in a &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag and JS in a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag&lt;/li&gt;
&lt;li&gt;Load libraries and fonts from absolute &lt;code&gt;https://&lt;/code&gt; URLs (a CDN)&lt;/li&gt;
&lt;li&gt;Inline images as data URIs, or use absolute URLs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Exports from Claude, ChatGPT, Jupyter and most test runners already are self-contained.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your options (checked 22 November 2026)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;th&gt;Good for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Email attachment&lt;/td&gt;
&lt;td&gt;Arrives as a file, phones often show code&lt;/td&gt;
&lt;td&gt;Never for a live page&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Google Drive / Dropbox&lt;/td&gt;
&lt;td&gt;File preview or download, not a page&lt;/td&gt;
&lt;td&gt;Storing the source&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GitHub Pages&lt;/td&gt;
&lt;td&gt;Needs a repo and a push, free on public repos&lt;/td&gt;
&lt;td&gt;Long-lived dev sites&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Netlify Drop&lt;/td&gt;
&lt;td&gt;Drag a folder, no-account drops sit behind a temporary password until claimed&lt;/td&gt;
&lt;td&gt;Multi-file sites&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tiiny Host (free)&lt;/td&gt;
&lt;td&gt;Files up to 3 MB, 1 live page&lt;/td&gt;
&lt;td&gt;One small page&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Link in Seconds&lt;/td&gt;
&lt;td&gt;One file, one link, rendered in a sandbox, with a QR code and view count&lt;/td&gt;
&lt;td&gt;Sharing one page fast&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What works inside a sandboxed page
&lt;/h2&gt;

&lt;p&gt;Hosts that render untrusted HTML safely run it inside a sandboxed frame. Scripts, forms that post to an external service, alerts and pop-ups work. What's withheld is same-origin access: no cookies, no localStorage, no sessionStorage. That restriction is exactly what lets the page be served safely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does my shared page look broken?
&lt;/h2&gt;

&lt;p&gt;Almost always because it points at files that weren't uploaded:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Relative paths&lt;/strong&gt; like &lt;code&gt;styles.css&lt;/code&gt; or &lt;code&gt;./img/logo.png&lt;/code&gt; only exist on your machine. Inline them or use https URLs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;file:// links&lt;/strong&gt; only open on your own computer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;localStorage or cookies&lt;/strong&gt; won't persist in a sandbox.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Several files?&lt;/strong&gt; Zip the folder with an &lt;code&gt;index.html&lt;/code&gt; at the top and publish it as a static site instead.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Full guide with screenshots and FAQs: &lt;a href="https://linkinseconds.com/blog/share-an-html-file-as-a-link" rel="noopener noreferrer"&gt;https://linkinseconds.com/blog/share-an-html-file-as-a-link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I build Link in Seconds solo. Happy to answer questions about sandboxing untrusted HTML in the comments.&lt;/p&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How we built a QR code designer that can't break scanning</title>
      <dc:creator>Sunny Radadiya</dc:creator>
      <pubDate>Sun, 01 Nov 2026 11:50:00 +0000</pubDate>
      <link>https://dev.to/sunnyradadiya/how-we-built-a-qr-code-designer-that-cant-break-scanning-2ggi</link>
      <guid>https://dev.to/sunnyradadiya/how-we-built-a-qr-code-designer-that-cant-break-scanning-2ggi</guid>
      <description>&lt;p&gt;Last week we added QR code design to &lt;a href="https://linkinseconds.com/qr-code-generator?utm_source=devto&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;Link in Seconds&lt;/a&gt;: colours, dot styles, rounded corners, a logo in the middle and a "Scan me" frame. The tricky part was not drawing pretty QR codes. It was making sure &lt;strong&gt;no combination of options could produce a code a phone can't read&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is how we did it, including the two styles we threw away because our own tests failed them.&lt;/p&gt;

&lt;h2&gt;
  
  
  One SVG string for everything
&lt;/h2&gt;

&lt;p&gt;We generate the code once, as an SVG string, in a pure function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;qrSvg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;design&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;QrDesign&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sizePx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That one string is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the live preview (&lt;code&gt;&amp;lt;img src="data:image/svg+xml,..."&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;the &lt;strong&gt;SVG download&lt;/strong&gt; (sharp at any print size)&lt;/li&gt;
&lt;li&gt;the source of the &lt;strong&gt;PNG download&lt;/strong&gt; (drawn onto a &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; in the browser)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No DOM, no canvas, no network inside the function, so it runs the same in the browser and in tests.&lt;/p&gt;

&lt;p&gt;We use the &lt;code&gt;qrcode&lt;/code&gt; package only for the hard part, the module matrix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;qr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;QRCode&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="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;errorCorrectionLevel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;logo&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;H&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;M&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;modules&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="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* draw a dot */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we draw every dark module ourselves as a &lt;code&gt;&amp;lt;rect&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;circle&amp;gt;&lt;/code&gt;, which is what makes the styles possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 1: the three "eyes" are drawn separately
&lt;/h2&gt;

&lt;p&gt;The big squares in three corners (finder patterns) are how a scanner locates and orients the code. We skip those modules in the dot loop and draw each eye as three solid shapes: an outer ring, a gap and a centre. Styling (square or rounded, any colour) only changes the corner radius and fill. The shape always stays solid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 2: a logo forces error correction H
&lt;/h2&gt;

&lt;p&gt;QR codes can lose part of their data and still decode. Level H tolerates the most damage (about 30%). When a logo is added we:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;switch to level H automatically,&lt;/li&gt;
&lt;li&gt;cap the logo box at about 22% of the code width, snapped to whole modules,&lt;/li&gt;
&lt;li&gt;clear the modules under it plus a one-module margin, so the logo sits on a clean background.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The user never picks an error correction level. The tool picks the safe one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 3: warn about contrast
&lt;/h2&gt;

&lt;p&gt;A designer will happily pick pale grey on white, or white on black. Both look fine on screen and fail in real light. We compute the WCAG contrast ratio and require darker dots than background:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;contrastOk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;luminance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nf"&gt;luminance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;contrastRatio&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&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;If it fails, the UI shows a warning under the colour pickers. We don't block the download, we just tell you.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test that keeps us honest
&lt;/h2&gt;

&lt;p&gt;Every style gets rendered to pixels and decoded with a real QR reader (&lt;a href="https://github.com/cozmo/jsQR" rel="noopener noreferrer"&gt;jsQR&lt;/a&gt;). If the decoded text isn't the input, the test fails:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;svg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;img&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;loadImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;svg&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;      &lt;span class="c1"&gt;// @napi-rs/canvas&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCanvas&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drawImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;img&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;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getImageData&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;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;jsQR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8ClampedArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)?.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;designs&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;%s scans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;design&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="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;qrSvg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;design&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;URL&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;We run it across short URLs, long URLs with query strings, and a Wi-Fi string, for every style combination: dots, rounded, logo, frame and all of them at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the test caught
&lt;/h2&gt;

&lt;p&gt;This is the part I'm glad we automated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Circle-shaped corner eyes.&lt;/strong&gt; They look lovely. They failed to decode. A ring of &lt;code&gt;stroke&lt;/code&gt; around a dot doesn't give the scanner the crisp 1:1:3:1:1 ratio it looks for. We dropped the option instead of shipping it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dots that were slightly too small.&lt;/strong&gt; Our first "dots" style used &lt;code&gt;r="0.45"&lt;/code&gt; (90% of the module). It decoded for some colour pairs and failed for others. At &lt;code&gt;r="0.5"&lt;/code&gt;, where neighbouring dots touch, every test passed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rounded squares with a gap.&lt;/strong&gt; We first drew rounded modules at 0.9 width with a gap between them. Combined with a logo, decoding failed on short URLs (smaller codes, fewer modules to spare). Making each rounded module fill its full cell fixed it.&lt;/p&gt;

&lt;p&gt;None of these were visible problems. They all looked fine. Without a decode test we would have shipped codes that fail on someone's restaurant menu.&lt;/p&gt;

&lt;h2&gt;
  
  
  Safety: the input is user-controlled
&lt;/h2&gt;

&lt;p&gt;Because we build an SVG string from user input, we treat everything as untrusted:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Colours&lt;/strong&gt; must match &lt;code&gt;/^#[0-9a-f]{6}$/i&lt;/code&gt; or fall back to the default, so &lt;code&gt;red" onload="..."&lt;/code&gt; never reaches the markup.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frame text&lt;/strong&gt; is HTML-escaped and capped at 24 characters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The logo&lt;/strong&gt; must be a &lt;code&gt;data:image/(png|jpeg|webp|gif|svg+xml);base64,&lt;/code&gt; URL. A remote &lt;code&gt;https://&lt;/code&gt; URL is dropped.&lt;/li&gt;
&lt;li&gt;The logo is read with &lt;code&gt;FileReader&lt;/code&gt; in the browser and &lt;strong&gt;never uploaded&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each of these has a test too.&lt;/p&gt;

&lt;h2&gt;
  
  
  The result
&lt;/h2&gt;

&lt;p&gt;Free, runs in the browser, PNG and SVG out, and every style it offers has been decoded by a QR reader in CI: &lt;a href="https://linkinseconds.com/qr-code-generator?utm_source=devto&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;linkinseconds.com/qr-code-generator&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're building anything that generates QR codes, my one takeaway: &lt;strong&gt;add a decode test.&lt;/strong&gt; It takes 20 lines and it will catch things your eyes won't.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Built with Next.js, TypeScript, the &lt;code&gt;qrcode&lt;/code&gt; package, jsQR and @napi-rs/canvas for tests. Questions welcome in the comments.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
