我已经为此苦苦挣扎了一段时间。我只是无法从我的数据库上的 blob 字段生成图像。
这是我的整个代码:
<?php require_once('db.php'); ?>
<?php
@mysql_select_db($db_login, $login);
$query_consulta_fotos = "select `foto01_NmArquivo`, `foto01_Descricao`, `foto01_Arquivo`, `foto01_Tipo`, `foto01_Tamanho` from equipamentos where id = 2";
$result = @mysql_query($query_consulta_fotos);
$data = @mysql_result($result,0,"foto01_Arquivo");
$type = @mysql_result($result,0,"foto01_Tipo");
Header( "Content-type: $type");
$size = 150; // new image width
$src = imagecreatefromstring($data);
$width = imagesx($src);
$height = imagesy($src);
$aspect_ratio = $height/$width;
if ($width <= $size) {
$new_w = $width;
$new_h = $height;
} else {
$new_w = $size;
$new_h = abs($new_w * $aspect_ratio);
}
$img = imagecreatetruecolor($new_w,$new_h);
imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$width,$height);
// determine image type and send it to the client
if ($type == "image/pjpeg") {
imagejpeg($img);
} else if ($type == "image/x-png") {
imagepng($img);
} else if ($type == "image/gif") {
imagegif($img);
}
imagedestroy($img);
mysql_free_result($consulta_fotos);
?>
如果我回显 $data 和 $type 我分别得到整个 char 链和文件的 MIME,一切看起来都很好。
任何帮助表示赞赏。
谢谢!