Skip to content

Conversation

@jmooring
Copy link
Member

@jmooring jmooring commented Jan 2, 2025

Closes #13205

Note that this uses (create.Client).FromString under the covers, which seemed a lot simpler than creating a FromBytes or FromImage method.

Site and theme authors should test the rendered image per the documentation:

Always test the rendered QR code after resizing, both on-screen and in print.

@jmooring jmooring force-pushed the qrcode-13205 branch 2 times, most recently from 98c9ccc to d0029d8 Compare January 2, 2025 19:49
@jmooring jmooring force-pushed the qrcode-13205 branch 3 times, most recently from ae08c96 to fa99b36 Compare January 3, 2025 08:17
@jmooring jmooring marked this pull request as draft January 3, 2025 11:26
@jmooring jmooring marked this pull request as ready for review January 3, 2025 11:33
@jmooring jmooring force-pushed the qrcode-13205 branch 4 times, most recently from 76dc38c to 5ca121f Compare January 4, 2025 06:26
@jmooring
Copy link
Member Author

jmooring commented Jan 5, 2025

I'll handle styling of the example images on the docs site, so if you build the docs from this repo the examples will be stretched.

@jmooring jmooring force-pushed the qrcode-13205 branch 3 times, most recently from c1e7ff1 to 58c4771 Compare January 5, 2025 15:20
@jmooring jmooring requested a review from bep January 5, 2025 15:22
@bep bep self-requested a review January 6, 2025 09:58
@bep bep merged commit 4ea94c4 into gohugoio:master Jan 6, 2025
6 checks passed
@jmooring jmooring deleted the qrcode-13205 branch January 6, 2025 15:19
@mrusme
Copy link

mrusme commented May 11, 2025

Just in case anyone is stumbling upon this feature -- thank you for it btw! -- and is thinking "dammit, no way to change the colors of the QR code to adjust for dark/light themes!", I got you covered:

      <div id="qrcode">
      {{ with (images.QR .Permalink (dict "level" "high" "scale" 3)) }}
        <img src="{{ .RelPermalink }}"
            width="{{ .Width }}"
            height="{{ .Height }}"
            alt="QR code linking to {{ $.Permalink }}"
            class="qrcode-light"
            loading="lazy">
        {{ with . | images.Filter images.Invert }}
          <img src="{{ .RelPermalink }}"
              width="{{ .Width }}"
              height="{{ .Height }}"
              alt="QR code linking to {{ $.Permalink }}"
              class="qrcode-dark"
              loading="lazy">
        {{ end }}
      {{ end }}
      </div>
@media (prefers-color-scheme: dark) {
  #qrcode > .qrcode-light {
    display: none;
  }
}

@media (prefers-color-scheme: light) {
  #qrcode > .qrcode-dark {
    display: none;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants