Skip to content

Commit

Permalink
Show logo in QR code
Browse files Browse the repository at this point in the history
Show logo in QR code (for SVG QR code representation)
  • Loading branch information
zorantica committed Aug 22, 2023
1 parent 7e7db87 commit df16bad
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Item-type APEX plugin uses PL/SQL package for calculations and graphical impleme
- 1.6 - older databases compatilbility (10g)
- 1.7 - Numeric mode BUG with "0" at the beginning of triplet group
- 2.0 - SVG image files support
- 2.1 - Show logo in QR code

## Install PL/SQL package
- download 2 script files from "package" directory
Expand Down
56 changes: 51 additions & 5 deletions package/ZT_QR.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -2364,7 +2364,14 @@ FUNCTION f_qr_as_svg(
p_margines_yn varchar2 default 'N', --margines around QR code (4 modules) - values Y or N
p_module_color varchar2 default 'black', --colors are defined as SVG named colors OR rgb (with # or rgb function)
p_background_color varchar2 default 'white',
p_module_rounded_px pls_integer default 0 --0 - sharp corners; > 0 - rounded in pixels
p_module_rounded_px pls_integer default 0, --0 - sharp corners; > 0 - rounded in pixels
p_logo_yn varchar2 default 'N',
p_logo_size_percent number default 20,
p_logo_image clob default null,
p_logo_back_rect_yn varchar2 default 'Y',
p_logo_back_rect_color varchar2 default 'white',
p_logo_back_rect_round_px pls_integer default 0,
p_logo_margine_px number default 5
) RETURN clob IS

lcQR varchar2(32727);
Expand Down Expand Up @@ -2420,7 +2427,32 @@ BEGIN
end if;

END LOOP;



--add logo (optional)
if p_logo_yn = 'Y' then
DECLARE
lnLogoBckWidth number;
lnLogoBckPos number;
lnLogoWidth number;
lnLogoPos number;

BEGIN
lnLogoBckWidth := round(lnMatrixSize * p_module_size_px * p_logo_size_percent / 100, 2);
lnLogoBckPos := (lnCanvasSize / 2) - (lnLogoBckWidth / 2);
lnLogoWidth := lnLogoBckWidth - p_logo_margine_px * 2;
lnLogoPos := lnLogoBckPos + p_logo_margine_px;

if p_logo_back_rect_yn = 'Y' then
p_add_clob('<rect x="0" y="0" width="' || lnLogoBckWidth || '" height="' || lnLogoBckWidth || '" fill="' || p_logo_back_rect_color || '" rx="' || p_logo_back_rect_round_px || '" transform="translate(' || lnLogoBckPos || ', ' || lnLogoBckPos || ')" />');
end if;

p_add_clob('<image x="' || lnLogoPos || '" y="' || lnLogoPos || '" width="' || lnLogoWidth || '" height="' || lnLogoWidth || '" href="' || p_logo_image || '" />');

END;
end if;


--finish SVG
p_add_clob('</svg>');

Expand All @@ -2436,7 +2468,14 @@ PROCEDURE p_qr_as_svg(
p_margines_yn varchar2 default 'N', --margines around QR code (4 modules) - values Y or N
p_module_color varchar2 default 'black', --colors are defined as SVG named colors OR rgb (with # or rgb function)
p_background_color varchar2 default 'white',
p_module_rounded_px pls_integer default 0 --0 - sharp corners; > 0 - rounded in pixels
p_module_rounded_px pls_integer default 0, --0 - sharp corners; > 0 - rounded in pixels
p_logo_yn varchar2 default 'N',
p_logo_size_percent number default 20,
p_logo_image clob default null,
p_logo_back_rect_yn varchar2 default 'Y',
p_logo_back_rect_color varchar2 default 'white',
p_logo_back_rect_round_px pls_integer default 0,
p_logo_margine_px number default 5
) IS

lcClob clob;
Expand All @@ -2449,9 +2488,16 @@ BEGIN
p_module_size_px => p_module_size_px,
p_module_color => p_module_color,
p_background_color => p_background_color,
p_module_rounded_px => p_module_rounded_px
p_module_rounded_px => p_module_rounded_px,
p_logo_yn => p_logo_yn,
p_logo_size_percent => p_logo_size_percent,
p_logo_image => p_logo_image,
p_logo_back_rect_yn => p_logo_back_rect_yn,
p_logo_back_rect_color => p_logo_back_rect_color,
p_logo_back_rect_round_px => p_logo_back_rect_round_px,
p_logo_margine_px => p_logo_margine_px
);

p_print_clob_htp(lcClob);

END p_qr_as_svg;
Expand Down
29 changes: 25 additions & 4 deletions package/ZT_QR.pks
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,15 @@ p_module_size_px - width and height of one module
p_module_color - module color; colors can be defined as named colors (for example black, red, white...), using rgb function (for example rgb(255, 0, 0) ) or HEX values (for example #FF0000)
p_background_color - background color; colors can be defined as named colors (for example black, red white...), using rgb function (for example rgb(255, 0, 0) ) or HEX values (for example #FF0000)
p_module_rounded_px - if modules should have rounded edges (if size of this parameter is half the module size (or larger) then modules are represented as circles)

Procedure prints SVG image using HTP.P procedure (can be used to print SVG image directly in HTML code)
p_logo_yn - should logo be displayed on not (values Y / N)
p_logo_size_percent - logo background rectangle size (in percentages) related to QR code size
p_logo_image - logo image (URL reference or base64 content)
p_logo_back_rect_yn - should logo background rectangle be displayed or not
p_logo_back_rect_color - logo background rectangle color
p_logo_back_rect_round_px - logo background rectangle rounded edges
p_logo_margine_px - a margine between logo and background rectangle

Procedure prints SVG image using HTP.P procedure (can be used to print SVG image directly into HTML code)
*/
FUNCTION f_qr_as_svg(
p_data varchar2, --data going to be encoded into QR code
Expand All @@ -220,7 +227,14 @@ FUNCTION f_qr_as_svg(
p_margines_yn varchar2 default 'N', --margines around QR code (4 modules) - values Y or N
p_module_color varchar2 default 'black', --colors are defined as SVG named colors OR rgb (with # or rgb function)
p_background_color varchar2 default 'white',
p_module_rounded_px pls_integer default 0 --0 - sharp corners; > 0 - rounded in pixels
p_module_rounded_px pls_integer default 0, --0 - sharp corners; > 0 - rounded in pixels
p_logo_yn varchar2 default 'N',
p_logo_size_percent number default 20,
p_logo_image clob default null,
p_logo_back_rect_yn varchar2 default 'Y',
p_logo_back_rect_color varchar2 default 'white',
p_logo_back_rect_round_px pls_integer default 0,
p_logo_margine_px number default 5
) RETURN clob;

PROCEDURE p_qr_as_svg(
Expand All @@ -230,7 +244,14 @@ PROCEDURE p_qr_as_svg(
p_margines_yn varchar2 default 'N', --margines around QR code (4 modules) - values Y or N
p_module_color varchar2 default 'black', --colors are defined as SVG named colors OR rgb (with # or rgb function)
p_background_color varchar2 default 'white',
p_module_rounded_px pls_integer default 0 --0 - sharp corners; > 0 - rounded in pixels
p_module_rounded_px pls_integer default 0, --0 - sharp corners; > 0 - rounded in pixels
p_logo_yn varchar2 default 'N',
p_logo_size_percent number default 20,
p_logo_image clob default null,
p_logo_back_rect_yn varchar2 default 'Y',
p_logo_back_rect_color varchar2 default 'white',
p_logo_back_rect_round_px pls_integer default 0,
p_logo_margine_px number default 5
);


Expand Down

0 comments on commit df16bad

Please sign in to comment.