Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/noverney/randoms
Browse files Browse the repository at this point in the history
  • Loading branch information
jareem committed Oct 29, 2023
2 parents f661a03 + d402b81 commit f3497f1
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 2 deletions.
Binary file added notebooks/fancy-qr-code.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions notebooks/make-fancy-qr-code.py
@@ -0,0 +1,79 @@
import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.svg import SvgImage
from qrcode.image.styles.moduledrawers import RoundedModuleDrawer
from qrcode.image.styles.colormasks import SolidFillColorMask

import PIL
from PIL import Image, ImageDraw

if not hasattr(PIL.Image, 'Resampling'):
PIL.Image.Resampling = PIL.Image
# Now PIL.Image.Resampling.BICUBIC is always recognized.

import tempfile
import os

#Custom function for eye styling. These create the eye masks
# Set up parameters
w_cm, h_cm = (10, 10) # Real label size in cm we are just setting it for the new rounded image
res_x, res_y = (300, 300) # Desired resolution
# Inch-to-cm factor
f = 2.54

# Determine image size w.r.t. resolution
w = int(w_cm / f * res_x)
h = int(h_cm / f * res_y)

def add_corners(im, rad, size=(w,h)):
#circle = Image.new('L', (rad * 2, rad * 2), 0)
circle = Image.new('L', size, 0)
draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, rad * 2 - 1, rad * 2 - 1), fill=255)
alpha = Image.new('L', im.size, 255)
w, h = im.size
alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
im.putalpha(alpha)
return im

def create_rounded_image(image_path, output_path):
im = Image.open(image_path)
radius = 100
im = add_corners(im, radius)
im.save(output_path, transparent=True)

def create_qr(center_logo_path, output_path, data='http://meetingmunch.com/docs'):

# create a temp path
temp_dir = tempfile.TemporaryDirectory()
print(temp_dir.name)
image_path = os.path.join(temp_dir.name, "rounded.png")

create_rounded_image(center_logo_path, image_path)

qr = qrcode.QRCode(
version=None,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=100,
border=4,
)

qr.add_data(data)

qr_img = qr.make_image(image_factory=StyledPilImage,
module_drawer=RoundedModuleDrawer(),
embeded_image_path=image_path,)
# just in case our sticker has different backgound color than white
#color_mask=SolidFillColorMask(front_color=(0,0,0,255), back_color=(255,255,255,0)))
qr_img.save(output_path)

# use temp_dir, and when done:
temp_dir.cleanup()

# call the function given the first path being logo
# and the second path being the ouput file path
# I also have the function which creates an SVG of the QR code instead of image
create_qr('../website/static/img/SVG/justlogo.png', "fancy-qr-code.png")
24 changes: 24 additions & 0 deletions notebooks/make-qr-code.py
@@ -0,0 +1,24 @@
import qrcode
import qrcode.image.svg

# define a method to choose which factory metho to use
# possible values 'basic' 'fragment' 'path'
method = "basic"

data = "https://meetingmunch.com/docs"

if method == 'basic':
# Simple factory, just a set of rects.
factory = qrcode.image.svg.SvgImage
elif method == 'fragment':
# Fragment factory (also just a set of rects)
factory = qrcode.image.svg.SvgFragmentImage
elif method == 'path':
# Combined path factory, fixes white space that may occur when zooming
factory = qrcode.image.svg.SvgPathImage

# Set data to qrcode
img = qrcode.make(data, image_factory = factory)

# Save svg file somewhere
img.save("qrcode.svg")
2 changes: 2 additions & 0 deletions notebooks/qrcode.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion website/docusaurus.config.js
Expand Up @@ -127,7 +127,7 @@ const config = {
],
},
],
copyright: `Copyright © ${new Date().getFullYear()} MeetingMunch, Inc. Built at BaselHack.`,
copyright: `Copyright © ${new Date().getFullYear()} MeetingMunch, Inc. Built with ❤️ at BaselHack.`,
},
prism: {
theme: lightCodeTheme,
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/index.js
Expand Up @@ -18,7 +18,7 @@ function HomepageHeader() {
<Link
className="button button--secondary button--lg"
to="https://meetingmunch.com/login">
Get Started - 5min ⏱️
Get Started - 1min ⏱️
</Link>
</div>
</div>
Expand Down
Binary file added website/static/img/SVG/justlogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f3497f1

Please sign in to comment.