Replies: 4 comments 13 replies
-
Hey! The base64 data URI is a convenience functionality so that the output can be used directly in an |
Beta Was this translation helpful? Give feedback.
-
Is that actually more overhead? I'm just moving the encode from one place to another! Thanks, I'll give it a shot. |
Beta Was this translation helpful? Give feedback.
-
Got it working. For anyone else who's looking, here is my working code for user Chillerlan QRs with RobThree's TOTP library: <?php
namespace [redacted];
use chillerlan\QRCode as qr;
use chillerlan\Settings\SettingsContainerInterface;
use RobThree\Auth\Providers\Qr as mfa;
class ChillerlanQRCodeProvider extends qr\QRCode implements mfa\IQRCodeProvider {
function __construct( SettingsContainerInterface $options = NULL ) {
$options ??= new qr\QROptions( [
'outputType' => qr\QRCode::OUTPUT_MARKUP_SVG,
'eccLevel' => qr\QRCode::ECC_M,
] );
$options->imageBase64 = False; // imageBase64 above must always be False. Override if necessary.
parent::__construct( $options );
}
public function getQRCodeImage( string $qrtext, int $size ): string {
return self::render( $qrtext );
}
public function getMimeType(): string {
return match( $this->options->outputType ) {
self::OUTPUT_MARKUP_SVG=>'image/svg+xml',
self::OUTPUT_IMAGE_PNG=>'image/png',
self::OUTPUT_IMAGE_JPG=>'image/jpeg',
self::OUTPUT_IMAGE_GIF=>'image/gif',
};
}
} In your main code, use it when creating your 2FA object. (Named param syntax is PHP >=8.0): $mfa = new TwoFactorAuth(
issuer: 'My Company Name',
qrcodeprovider: new ChillerlanQRCodeProvider()
); NOTE: In the above class, I have set options that are my subjective choices. In your usage, function __construct( SettingsContainerInterface $options = NULL ) {
$options ??= new qr\QROptions();
$options->imageBase64 = False; // imageBase64 above must always be False. Override if necessary.
parent::__construct( $options );
} |
Beta Was this translation helpful? Give feedback.
-
I would love better explanation of the QR customization (colors, icons, shapes). I chose your library for the customization, but have had trouble figuring it out. Will have to take another look, as perhaps messing with this side-quest has shown me a few tricks I didn't realize I'd learned....) |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm trying to get this to work with a 2FA library. The format for the library is to get two separate values: 1) mimetype (e.g.
image/svg+xml
), and 2) the image itself in base64.Your plugin pre-combines these values in the string when it renders as dataurl.
Is there any way to easily get the base64 image string? Am I best off just exploding the string at the comma and grabbing the second element?
Beta Was this translation helpful? Give feedback.
All reactions