0

I have a base64 image, and I want to display it in the following dataView

<?= DetailView::widget([
    'model' => $model,
    'attributes' => [
        'nome:ntext',
        'img1:ntext', // here is the base64 string that is also accessed by "$ model-> img1"
    ],
]) ?>

I tried the following code, but it did not work

[
    'attribute' => 'img1',
    'value' => base64_decode($model->img1),
    'format' => ['image', ['width' => '100', 'height' => '100']]
],
rob006
  • 21,383
  • 5
  • 53
  • 74

1 Answers1

0

Try something like this

[
    'attribute' => 'img1',
    'value' => 'data:image/png;base64,' . $model->img1,
    'format' => ['image', ['width' => '100', 'height' => '100']]
],

or

[
    'attribute' => 'img1',
    'value' => 'data:image/jpeg;base64,' . $model->img1,
    'format' => ['image', ['width' => '100', 'height' => '100']]
],

depending on image type.


BTW: If you're storing images in database you may want to read Store pictures as files or in the database for a web app? (and tens of duplicates). It is quite likely that you will have a lot of problems because of this approach.

rob006
  • 21,383
  • 5
  • 53
  • 74