Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

munguru's avatar

image

how to show this image to blade php?

static function generateImage($id)
{
    $shop= DB::connection('Shop')->table('shoplist')->where('productnum', $id)->first();
    if ($shop) {
        $binary = bin2hex($shop->ShopImage);
    } else {
        return false;
    }
    if ($binary != "00") {
        $line = 0;
        $table =  "<table border='0' style='style:none;' cellpadding='0' cellspacing='0' width='16' height='11'>";
        for ($m = 0; $m < 35; $m++) {
            $table .= "<tr>";
            for ($n = 0; $n < 30; $n++) {
                $offset = $line * 8 * 16 + $n * 8;
                $color = substr($binary, $offset + 4, 2) . substr($binary, $offset + 2, 2) . substr($binary, $offset, 2);
                $table .= "<td style='width:1px;height:1px;background-color:#$color'></td>";
            }
            $table .= "</tr>";
            $line++;
        }
        $table .= "</table>";
    } else {
        $table = null;
    }
    return $table;
}
0 likes
7 replies
Snapey's avatar

format your code block if you want it reviewed

tykus's avatar

That is not generating an image; it is generating an HTML table (sometimes) which, I guess, is intended to be like a pixel-art representation of the original binary image??? But ultimately it is a table... so should be output directly to the Document (rather than inside an <img> element

munguru's avatar

@tykus it is pixeleted image but generated in background color style. it shows with content

{!! Command::generateImage($shop->productnum) !!}

tykus's avatar

@munguru okay, so this...

But ultimately it is a table... so should be output directly to the Document (rather than inside an img element)

Please or to participate in this conversation.