Updated QR code on dashboard share menu
This commit is contained in:
parent
aab11565c0
commit
335cf79d93
|
@ -7,7 +7,6 @@
|
|||
"require": {
|
||||
"php": ">=8.0",
|
||||
"awssat/laravel-visits": "^6.0",
|
||||
"bacon/bacon-qr-code": "^2.0",
|
||||
"codedge/laravel-selfupdater": "^3.6",
|
||||
"cohensive/oembed": "^0.17",
|
||||
"doctrine/dbal": "^3.0",
|
||||
|
@ -20,6 +19,7 @@
|
|||
"laravel/tinker": "^2.5",
|
||||
"livewire/livewire": "^2.12",
|
||||
"rappasoft/laravel-livewire-tables": "^2.15",
|
||||
"simplesoftwareio/simple-qrcode": "~4",
|
||||
"spatie/laravel-backup": "^8.17"
|
||||
},
|
||||
"require-dev": {
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
@php
|
||||
use BaconQrCode\Renderer\ImageRenderer;
|
||||
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
|
||||
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
|
||||
use BaconQrCode\Writer;
|
||||
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
|
||||
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||||
use App\Models\User;
|
||||
$usrhandl = Auth::user()->littlelink_name;
|
||||
@endphp
|
||||
|
@ -685,33 +681,57 @@ $usrhandl = Auth::user()->littlelink_name;
|
|||
</div>
|
||||
@php
|
||||
try {
|
||||
$qrCodeData = url('@'.Auth::user()->littlelink_name);
|
||||
$redirectURL = url('').'/'.'u/'.Auth::user()->id;
|
||||
|
||||
$renderer = new ImageRenderer(
|
||||
new RendererStyle(400),
|
||||
new SvgImageBackEnd()
|
||||
);
|
||||
$writer = new Writer($renderer);
|
||||
if (extension_loaded('imagick')) {
|
||||
$imgSrc = QrCode::format('png')->size(1000)->generate($redirectURL);
|
||||
$imgSrc = base64_encode($imgSrc);
|
||||
$imgSrc = 'data:image/png;base64,' . $imgSrc;
|
||||
$imgType = 'png';
|
||||
} else {
|
||||
$imgSrc = QrCode::size(1000)->generate($redirectURL);
|
||||
$imgSrc = base64_encode($imgSrc);
|
||||
$imgSrc = 'data:image/svg+xml;base64,' . $imgSrc;
|
||||
$imgType = 'svg';
|
||||
}
|
||||
|
||||
$svgImageData = $writer->writeString($qrCodeData);
|
||||
|
||||
$svgImageBase64 = base64_encode($svgImageData);
|
||||
|
||||
$imgSrc = 'data:image/svg+xml;base64,' . $svgImageBase64;
|
||||
} catch(exception $e) {echo '<p class="text-center pt-5">{{__("messages.QR code could not be generated")}}</p>'; if(auth()->user()->role == 'admin'){echo "<p class='ps-3'>{{__('messages.Reason:')}} <pre class='ps-4'>".$e->getMessage()."</pre></p>";}}
|
||||
} catch(exception $e) {
|
||||
$imgSrc = url('/assets/linkstack/images/themes/no-preview.png');
|
||||
$imgType = NULL;
|
||||
}
|
||||
@endphp
|
||||
<div class="modal-body">
|
||||
<div class="bd-example">
|
||||
<img draggable="false" src="@php if(isset($imgSrc)){echo $imgSrc;} @endphp" style="width:100%;height:auto;" class="bd-placeholder-img img-thumbnail">
|
||||
<img id="generatedImage" draggable="false" src="@php if(isset($imgSrc)){echo $imgSrc;} @endphp" style="width:100%;height:auto;" class="bd-placeholder-img img-thumbnail">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@if($imgType == 'png')
|
||||
<button type="button" class="btn btn-info" id="downloadButton">{{__('messages.Download')}}</button>
|
||||
@endif
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{__('messages.Close')}}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var downloadButton = document.getElementById("downloadButton");
|
||||
var generatedImage = document.getElementById("generatedImage");
|
||||
|
||||
downloadButton.addEventListener("click", function() {
|
||||
var format = generatedImage.getAttribute("data-format") || "png";
|
||||
var downloadLink = document.createElement("a");
|
||||
downloadLink.href = generatedImage.src;
|
||||
downloadLink.download = "generated_image." + format;
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- Library Bundle Script -->
|
||||
<script src="{{asset('assets/js/core/libs.min.js')}}"></script>
|
||||
|
||||
|
|
Loading…
Reference in New Issue