Display image in GridView Widget based on DB

I have saved images in mysql db using this code

migration file

'content' => 'LONGBLOB NOT NULL',

controller file

    $model->content = file_get_contents($model->path);


in view file and its works fine

echo '<img src="data:image/jpeg;base64,'.base64_encode($model->content).'"/>';

in gridview

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
            'attribute' => 'content',
            'format' => ['html'],
            'filter' => false,
            'value' => function ($data) {
                if (!empty($data['content'])) {
                    return Html::img(Yii::getAlias( $data['content'] )
                return "Not choosen";
        ['class' => 'yii\grid\ActionColumn'],

but there is nothing appearing

Have you tried with 'format' => 'raw'?

yes i do !

Oh, I’ve reviewed your code and the problem seems to be on the line above. Change it to this:

return Html::img( 'data:image/jpeg;base64' . base64_encode( $data['content'] ) );

You are setting the image src as Yii::getAlias( $data[‘content’] ) and setting a property 'data:image/jpeg;base64', this is the equivalent of doing this:

<img src="<?= $model->content ?>" data:image/jpeg;base64=".base64_encode" />

You should set the values in the “src” attribute, which is the first parameter of the Html::img method.