Merge Logo Into Simple QRCode (Laravel 5) - laravel

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;

Related

Blade view for rich text field on description tag

I'm using voyager in a laravel 7 shopping app for the description of all products.
I want to output the field for the description of the product
#section('description', {!! $item->description !!} )
and
for the facebook share = og:description" content="{!! $item->description !!}">
When I use {!! $item->description !!} in the body, no problem. But in the tag the output always read the p tag and all style form the description.
The weird thing is it's working find on localhost but not on the server. I tried various combination of solution with the same result. I feel there's a quick or maybe it's just not possible?
try html_entity_decode() ref link https://www.php.net/manual/en/function.html-entity-decode.php
{!! $item->description !!}
to
{!! html_entity_decode($item->description) !!} // it will render html
If you are using laravel 7/8 you can create a blade component then you can simple call
<x-editor :content="$description></x-editor>
check out this laravel docs
try this:
{{strip_tags(trim($item->description)}}

Laravel: Display image from public storage

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

Image not displaying in show blade but displaying in index blade

Please I need your help. So am trying to display an image in my view, it quite working on the index blade but not working on the show with the same code.
Here is my code
<img src="{{asset('/blog_images/'.$post->photo )}}" style="width:300px; height:150px" alt="NO IMAGE">
I've even gone ahead to try other helpers like public_path, url.
Please note that i inspected on the browser and it returned the full part to the image yet didn't display.
I'm thinking it might have to do with a certain settings somewhere.
Cheers!
What is in your Controller show method?)
It must be somthing like this:
public function show($id)
{
$post = Post::find($id);
return view('post.show', compact('post'));
}

Show an image in a blade file after using Intervention Image (Laravel)

I want to show an image in a blade template that contains already some HTML code after doing some modifications (resize, insert...) to this image using the Intervention Image library.
Example :
public function image(){
return $img = Image::make('images/test.jpg')
->resize(800, 500)
->insert('some_url', 'bottom-right', 10, 10)
->text('foo', 100, 100, function($font) {
$font->file('fonts/font.ttf');
$font->size(100);
$font->color('#fdf6e3');})
->response();
}
This method is called using this route :
Route::get('/image', 'MyController#image');
The result is perfect :)
but I want to show this image in a blade template that contains already HTML code, and not just return the image using the route.
Thanks in advance.
Try just setting returned like this <img src="$img"> in your blade.

Qrcode in laravel

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().

Resources