gpqr_file_content
Description
Filters the content of the QR code file. This is the raw content of the file and is useful if the file format of the QR code is SVG.
Note: This filter is only available if generating QR code. Filtering the contents of barcodes is not supported at this time. Please reach out if this is something you need!
Usage
Filter generated QR code file contents for all forms.
add_filter( 'gpqr_file_content', 'my_custom_function' );
Filter generated QR code file contents for a specific form.
add_filter( 'gpqr_file_content_FORMID', 'my_custom_function' );
Parameters
content string
File content represented as a UTF-8 string.
fg_hex string
RGB hex to use for the foreground. Defaults to black.
bg_hex string
RGB hex to use for the background. Defaults to white.
meta array
Various meta information used to generate the QR code. Includes properties such as ‘error_correction_level’, ‘size’, ‘format’, and ‘form’.
Examples
Customize QR code styling.
Update QR codes to have rounded blocks and place a small logo in the center. Note, you will need to also use gpqr_params_pre_generate
to generate QR codes as SVGs instead of PNGs.
To encode your image as base64, there are a variety of online solutions as well as ways to do it using CLI tools.
// https://gravitywiz.com/documentation/gpqr_params_pre_generate
add_filter( 'gpqr_params_pre_generate', function ( $params, $content ) {
$params['format'] = 'svg';
// Increase error correction level to get more reliable scans with a logo present.
$params['error_correction_level'] = 'q';
return $params;
}, 10, 2 );
add_filter( 'gpqr_file_content', function ( $content, $fg_hex, $bg_hex, $meta ) {
if ( rgar( $meta, 'format' ) === 'svg' ) {
// Overlay a logo on the QR code.
$logo = '<image
x="75"
y="75"
xlink:href="data:image/png;base64,ENCODE_YOUR_LOGO_AS_BASE64_AND_PUT_IT_HERE"
width="50"
height="50"/>';
$content = str_replace( '</svg>', $logo . '</svg>', $content );
// Round the corners of each block in the QR code.
$content = str_replace(
'<rect id="r0" width="6" height="6" fill="' . $fg_hex . '"/>',
'<rect id="r0" width="5.5" height="5.5" rx="5" ry="5" fill="' . $fg_hex . '"/>',
$content
);
}
return $content;
}, 10, 4 );
Example output when using this snippet (converted back to PNG):
Since
This filter is available since Gravity Forms QR Code 1.0.5.