你好,我遇到php读取sql server中image类型的图片数据的问题,现在想把数据库中的图片信息保存成文件

请大侠不吝赐教,非常感激。QQ 310830356

第1个回答  2016-12-23
  
// 定义上传目录
$upload_dir = $_SERVER['DOCUMENT_ROOT'].'/upload/';
// 创建目录
if(!is_dir($upload_dir))mkdir($upload_dir);

// 二进制数据 $picture
$image_type = image_type_to_mime_type($picture));
// 取得图片类型
$temp = explode('/', $image_type);

// 文件名
$uuid = rand(0,100).strtotime('+1 day');
$name = $uuid.$temp[1];
$path = $upload_dir.$name;

// 打开文件准备写入
$file = fopen($path, 'w');
// 写入
fwrite($file, $picture);
//关闭
fclose($file);
第2个回答  2018-03-17
sqlserver image类型存入的实际上是16进制数据 因此需要读取三原色 拼成图片

$face_data = "0xD174B8007795CC........";//数据库存储数据
$size = 0;
$im = imagecreatetruecolor(48, 48);
for ($y = 0; $y < 48; $y++) {
for ($x = 0; $x < 48; $x++) {
$hex = substr($face_data, ($size++)*4, 3);

$red = substr($hex,2,1);
$green = substr($hex,1,1);
$blue = substr($hex,0,1);

$color = imagecolorallocate($im, ord($red), ord($green), ord($blue));
imagesetpixel($im, $x, $y, $color);
}
}

header('Content-type: image/jpeg');
$big_img = imagecreatetruecolor(96, 96);
imagecopyresampled($big_img, $im,0, 0, 0, 0, 96,96, 48, 48);
imagejpeg($big_img);
imagedestroy($big_img);
imagedestroy($im);
第3个回答  2015-10-13
你把图片路径存起来不就好了吗

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网