GithubHelp home page GithubHelp logo

Custom QR Codes with Logo about segno HOT 5 CLOSED

darryllane avatar darryllane commented on July 24, 2024
Custom QR Codes with Logo

from segno.

Comments (5)

heuer avatar heuer commented on July 24, 2024

That's possible, but this project does not provide any helper function for this purpose since it requires more advanced image processing which is beyond the scope of this project.
However, Segno generates just simple PNG images which can be processed further.

Example code:

import io
from PIL import Image
import segno

out = io.BytesIO()
# Nothing special here, let Segno generate the QR code and save it as PNG in a buffer
segno.make('Blackbird singing in the dead of night', error='h').save(out, scale=5, kind='png')
out.seek(0)  # Important to let Pillow load the PNG
img = Image.open(out)
# Ensure colors (Segno saves a grayscale PNG to reduce the file size), use 'RGBA' if you need transparency
img = img.convert('RGB')
img_width, img_height = img.size
logo_max_size = img_height // 3  # May use a fixed value as well
logo_img = Image.open('./blackbird.jpg')  # The logo
# Resize the logo to logo_max_size
logo_img.thumbnail((logo_max_size, logo_max_size), Image.Resampling.LANCZOS)
# Calculate the center of the QR code
box = ((img_width - logo_img.size[0]) // 2, (img_height - logo_img.size[1]) // 2)
img.paste(logo_img, box)
img.save('qrcode_with_logo.png')

QR Code:
qrcode_without_logo

Logo:
blackbird

Result:
qrcode_with_logo

from segno.

heuer avatar heuer commented on July 24, 2024

See also https://github.com/heuer/segno/tree/master/examples/logo

from segno.

darryllane avatar darryllane commented on July 24, 2024

Thanks I will have a tinker ^_^

from segno.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.