Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Nova: how to display image from binary string?

I save PNG's binary content in database. I want display this PNG's on page without temporary save file on disk. I think need generate img tag like <img src="data:image/png;base64,......

But I do not understand how it is better to implement it and what type of field to take as a basis.

            Image::make('Image')->displayUsing(function($item) {
                $mime_type = 'image/png';
                return 'data: ' . $mime_type . ';base64,' . base64_encode($item);
            }),

But Laravel Nova generated:

<img src="http://172.18.0.3/storage/data: image/png;base64,......" class="rounded-full w-8 h-8" style="object-fit: cover;">

Added unnecessary http://172.18.0.3/storage/and rounded class.

How to prevent it adding?

like image 740
4n70wa Avatar asked Sep 20 '25 10:09

4n70wa


1 Answers

Work code for Laravel Nova 2.0.1:

Image::make('QRCode', 'qrcode')->thumbnail(function($value, $disk) {
    return 'data: image/png;base64,' . $value;
})->preview(function($value, $disk) {
    return 'data: image/png;base64,' . $value;
})->displayUsing(function($value) {
return  base64_encode($value);})

Also need remove rounded-full from field.thumbnailUrl?t("img",{staticClass:"rounded-full w-8 h-8", in file public\vendor\nova\app.js

like image 179
4n70wa Avatar answered Sep 23 '25 00:09

4n70wa