i want to make qrcode, in there i can make it but i have something trouble when i want to change the format of qrcode to png file. but its only show symbol
here my view :
<?php echo QrCode::size(265)->generate($row->id) ?>
this qrcode i use :
"simplesoftwareio/simple-qrcode": "~1"
here my referance : https://www.simplesoftware.io/docs/simple-qrcode
can anyone help me ? or can someone give me solution ?
before i change format to png :
and this after i change it :
There are more simple example available as well.
<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('QrCode as PNG image!')) !!} ">
If you are formatting it as png file format, you need to include it with a <img> tag.
Taken from the documentation
//Inside of a blade template.
<img src="{!!$message->embedData(QrCode::format('png')->generate('Embed me into an e-mail!'), 'QrCode.png', 'image/png')!!}">
You can also do this:
$png = QrCode::format('png')->size(512)->generate(1);
$png = base64_encode($png);
echo "<img src='data:image/png;base64," . $png . "'>";
In controller
$path = getenv('IMAGE_URL')."/img/logo.png";
$png = QrCode::format('png')->merge($path, .17, true)->size(300)->errorCorrection('H')->generate($data);
$png = base64_encode($png);
In blade file
<img src='data:image/png;base64,{{$png}}'>
I came to this page because I needed to create a PNG file to send inline in an email in laravel8.
I used the examples above in order to create the QR code as a png which worked brilliantly. I used the following code:
<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('QrCode as PNG image!')) !!}" />
However a number of email services (including Gmail) do not display images that use inlined base64 as above. Instead, they require you to add the base64 image as an attachment to the email and then reference that attachment in the img src.
Thankfully laravel (I'm using laravel8) has a really cool function that does this for you, so my code ended up looking like this (which worked):
<?php
$qrCodeAsPng = QrCode::format('png')->size(500)->generate("my text for the QR code");
?>
<img src="{{ $message->embedData($qrCodeAsPng, 'nameForAttachment.png') }}" />
The $message variable is one that is in every blade that is being sent as an email in laravel. In my case I did not want to create an actual image on the server, but if you wanted to use an image that you had stored you would use $message->embed().
Related
I have the following code to display an image - without going into details about why I am not just using the image name.
<?php
$data = base64_encode(file_get_contents('example.png'));
$info = getimagesize('example.png');
$image = sprintf('data:%s;base64,%s', $info['mime'], $data);
?>
<img src="<?php echo $image; ?>" download='final-image.png' />
It works as expected displaying the image.
However when someone right-clicks the image, in FireFox it wants to save it as (scriptname).png and Chrome wants to save it as download.png.
I can't use header() as headers are already being sent.
Is there any way to force a filename that works across browsers?
I am saving an uploaded image like this:
$profile_picture = $request->file('profile_picture');
$user->profile_picture = $profile_picture->getClientOriginalName();
Storage::disk('public')->put( $user->profile_picture, $request->file('profile_picture') );
and then I am trying to display that image in HTML with:
<img class="img-fluid" src="{{ asset('storage/'. Auth::user()->profile_picture) }}">
the image is being saved in storage/app/public, but the image is not showing in html, how do i go about this?
thank you
You may use response method on a Laravel filesystem
return Storage::disk('public')->response($user->profile_picture);
N.B: In order to do that, you need a Laravel route. The above code should be located in a controller method
hiii i want to generate pdf of an invoice . pdf is generate but it can't display an image
i use laravel/snappy for window
here is my view file
<div>
<img src="{{ asset('image/logo.png') }}" class="pl-3" width="15%" />
Download PDF
</div>
here is my controller
if($request->has('download')) {
$pdf = PDF::loadView('pdfview')-
>save(storage_path('invoices/aazsaa.pdf'));
return $pdf->download('userlist.pdf');
}
image is shown in view but when i download image is not render
yehh i got the solution of my problem
i use base64 encoder to display an image
here is my view file
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAV4AAABkCAMAAAD5Y6hXAAAArlBMVEX////rUYmIHVHwf6j2rsj60eDfw9GoWX/Hlq7sXZH+8/f38POQLF3Ppbn73Of3udDuaJnn0tz86O/v4ejyi7DvdKG4d5egSnTzl7iYO2j0osCwaIv4xdjXtMXAhqLq2OH84+y/haGdRG+FFEuSMF+zb5Dy5uzewM/e3uDHlKz0nb3NoLb0Z5nwcZ/27vLsWY7DxMb0xdemX4Pl5ebCv8LR0dTBwsTzw9b2s8ylUnsmpw2bAAAO7ElEQVR4nO1diXajuBLFNtgsxjaL8e4sz0kmnemkO+/1zOT/f+yh0loSi8hiJ9O+Z860QQulS1GqKgniOGecccYZZ5xxxhlnfAFEt3f+zcv14XBYra4Xo+Jh+BidWqZ/DbJ4c+hrWBW721PL9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hutyy9f1WB+u+x0q2oEXEBqb5WTj7FBGx4wyL6y/kNbDyY8tqVmsHarrb/YCWO7NWpbva3n86PAGx4Qmqg/wwpX9fTeEsPRab3oDB33eD+JioxEEucvkbwJJO2wqKf3cP7S1ptAdt5cVxcR4zA+a++bQL6ZsarU3uQK9vlZ59vPqMJ9aR1u7v34TjcD9yxYO38o403YFc8vi+tV/+BjIh8ovTXz3idB5vv2q7EUie/brtC8F6Io2420hJh/bHp3Ix1+S4uoyWuvRjIyMn/HQTbGTB6d3qJvoKXFsN+ZXt9MrB4DnucM75zJVkbtR6d3BGTt6TZXuh+zLdNP3Mpu9EZ7W3qjov3xsYQ3p0nQafD9Jz93CnpHGVXJhUOpa11IGXWl13Fs6Y0tHh87/PPUe/o7unmOvECmq45O74ZuzR7yBz7ZjFrnoA+k138vekk67ulnOayd92dPZKvvT+Q5CHpt8IH0ZmP6FL0VkDEN/i4fhnug9+kSTv/u9DrR8F2+PQgrOAq9bHXvE9FbDnSo2IlkKAZO6S2PeVCUQUVcvzwpKyB6UQG70FBplqkFCapmnYyBL2YEYBwmQO+f4D7s/>
i change the src of image in tag. i just put base64 string of an image instead of path, and it's work
I'm using https://www.simplesoftware.io/docs/simple-qrcode to generate QR code with laravel 5. I want to add a logo at the centre of the qr code since it's doable (according to this plugin) however part of the output was something like this:
j�W�X�"(�#��E 4=��X w����M�X�"(�#��EG��=5y��'��wX���I�C��E P,�bu� {?��ݻ�����Ò��"(�#��E P,��WX-�Vm\VWF��qb��'B���#�X�"(�#����T������L��M��꽾�Q�m�#- r�h�����ly"#{��������bQe_��Z]]��ko����G7EDT�i4TH�,}����t��������ŷ�n�������Q�啵�����R�F�m� �(��|x�����ny%���������UQU�5)U˾+���lUX���k��L=��O��kyemv�X��h�D�L$s>� L����L�$�9������$��(�\a�幂 ��ů�U�qK%��D�P��N��D3���$K��ʣ��#�Օ���i2s����nT��a�I㲎��7+)AG�H�>�;�$��KMT���J�<|����p��;�K7��!��<.*'N���7��>�%�ɮs:AMLD-����3J�䃭?�
Here is my code:
{!! QrCode::format('png')->merge('https://www.seeklogo.net/wp-content/uploads/2016/09/facebook-icon-preview-1.png', .3, true)->size(200)->generate('http://www.simplesoftware.io'); !!}
Anyone experience with this kindly help me out, your help is appreciated! :)
Thank you.
You are seeing the raw output of a PNG image. You will need to base64 encode the image and then place it within an img tag like this:
<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->merge('https://www.seeklogo.net/wp-content/uploads/2016/09/facebook-icon-preview-1.png', .3, true)->size(200)->generate('http://www.simplesoftware.io');) !!} ">
You should not return file by blade. In your controller you should have something like:
$response = Response::make($file);
$response->header('Content-Type', "image/png");
return $response;
Is there a way to check if the file exists in Twig for an image uploaded in a newly created post?
The way I have my post setup is if an image is not uploaded the Twig template will show an empty box with the proportions of where the image should be, but it's a blank box that's awkward to look at.
Question, is if there is a specific command to use with an if statement to check if a file exists if so, display the image code if not do not display the image code.
Image code: (this is the code I want to hide if no image exists to get rid of the empty box)
<div class="entry-thumbnail">
<img width="230" height="172" src="{{ asset(['images/', post.image]|join) }}" class="" alt=""/>
</div>
you could write a twig extension and use some code like this:
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Finder\Finder;
$this->fs=new Filesystem();
if (!$this->fs->exists($directory)) {
$this->logger->info("there is no ".$directory." ...");
} else {
$this->logger->info("Directory ".$directory." already exists.");
}
but i would rather use javascripz like
in your img tag :
<img ... onError="this.src='imagefound.gif';" />
update:
The image Tag has an onError-Handler that triggers when the image in the src attribute is not found. So instead of using this simple inline syntax you could do the same like :
pseudo jquery code:
$(document).on('error','img',function(){
$(this).attr("src","../path/to/placeholerImage.png");
});