I want to minimize the size of a SQL Server image before it gets loaded on the clients.
Unfortunately I get the example not implemented: Resizing and then displaying BLOB element from database
Code:
<?php
include "dbconf2.php";
$sqlimage="
SELECT
F.Grafik,
F.knr,
F.brstatus1,
F.untertitel1,
F.anzeigeweb1
FROM FOTO F
WHERE F.knr LIKE 'FHTG20900%'
;";
$stmtimage = sqlsrv_query($connVHS, $sqlimage);
while ($result2=sqlsrv_fetch_array($stmtimage)) {
echo "titel: ".$result2['untertitel1']."<br>";
echo "knr: ".$result2['knr']."<br>";
echo "status: ".$result2['brstatus1']."<br>";
echo "web: ".$result2['anzeigeweb1']."<br>";
echo '<img src="data:image/jpeg;base64,'.base64_encode( $result2['Grafik']).'" style="max-height: 500px; max-width: 400px;"/>'."<br>";
echo "<br>";
}
?>
Edit: my simple implementation:
$image = imagecreatefromstring(base64_encode( $result2['Grafik']));
$image = imagescale($image, 100, 100);
ob_start();
imagejpeg($image);
$contents = ob_get_contents();
ob_end_clean();
echo "<img src='data:image/jpeg;base64,".base64_encode($contents)."' />";
imagedestroy($image);
but I get these errors:
Warning: imagecreatefromstring(): Data is not in a recognized format ...
Warning: imagescale() expects parameter 1 to be resource, boolean given in ...
Warning: imagedestroy() expects parameter 1 to be resource, null given in ...