我现在已经挣扎了一段时间了。我无法从我的数据库中的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,一切看起来都很好。
感谢任何帮助。
谢谢!