Skip to content

Commit

Permalink
feat(export/png): add as_canvas method
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Jan 4, 2024
1 parent 8ce7f01 commit f221da3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: qr-code
version: 1.0.2
version: 1.0.3
crystal: ">= 0.36.1"

development_dependencies:
Expand Down
22 changes: 21 additions & 1 deletion src/qr-code/export/png.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "stumpy_png"

# https://github.com/whomwah/rqrcode/blob/master/lib/rqrcode/export/png.rb#L1
class QRCode
def as_png(
def as_canvas(
bit_depth : Int32 = 1,
border_modules : Int32 = 3,
color_type : Symbol = :grayscale,
Expand Down Expand Up @@ -33,6 +33,26 @@ class QRCode
end
end

png
end

def as_png(
bit_depth : Int32 = 1,
border_modules : Int32 = 3,
color_type : Symbol = :grayscale,
color : String = "#000000",
fill : String = "#ffffff",
size : Int32 = 128
)
png = as_canvas(
bit_depth,
border_modules,
color_type,
color,
fill,
size
)

# return the image bytes
io = IO::Memory.new
StumpyPNG.write(png, io)
Expand Down

0 comments on commit f221da3

Please sign in to comment.