将图像保存在mysql数据库中作为bolb,我希望使用php在fpdf中显示它。我遇到问题了,因为我对fpdf很陌生。我真的需要帮助。谢谢。需要将图像从mysql数据库显示到fpdf
回答
您将需要此扩展FPDF:http://www.fpdf.org/en/script/script45.php
[更新]
$query = "SELECT imageField FROM yyy WHERE ...";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$image = $row['imageField'];
$pdf->MemImage($image, 50, 30);
谢谢你的回复,我试过了,但我相信只有当图像保存到主机时才有效。但我目前的图像保存在mysql(blob)中。 – 2010-09-19 10:28:26
这正是这个脚本的用途。你需要将你的blob加载到一个变量中,然后使用'MemImage($ blob,...)'方法 – Mchl 2010-09-19 11:06:11
对不起,但我还是不太了解,并且希望得到你的指导方针...的扩展。我有copr的例子... – 2010-09-19 12:43:02
//Alternatively
//1) Put the class VariableStream inside your php file instead of declaring it
//--------------------------
enter code here
class VariableStream
{
var $varname;
var $position;
function stream_open($path, $mode, $options, &$opened_path)
{
$url = parse_url($path);
$this->varname = $url['host'];
if(!isset($GLOBALS[$this->varname]))
{
trigger_error('Global variable '.$this->varname.' does not exist', E_USER_WARNING);
return false;
}
$this->position = 0;
return true;
}
function stream_read($count)
{
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
function stream_eof()
{
return $this->position >= strlen($GLOBALS[$this->varname]);
}
function stream_tell()
{
return $this->position;
}
function stream_seek($offset, $whence)
{
if($whence==SEEK_SET)
{
$this->position = $offset;
return true;
}
return false;
}
function stream_stat()
{
return array();
}
}
//----------------------------------------------------
//2) open and read your mysql longblob that contains your binary data from your image
//in my case the function declaration is this
function showImage($cdImg) {
Global $pdf;
//declare your pdf class
//Connects the way you do. this case assigned as $odbc_conn
$query = 'SELECT cd_img, ds_img, bin_img FROM tb_img WHERE cd_img = '.$cdImg;
$result= mysqli_query($odbc_conn, $query);
$row = mysqli_fetch_array($result);
if (!empty($row["bin_img"]))
{
//IF your data is encoded
//$data=base64_decode($row['bin_img']);
//
$data=$row['bin_img'];
}
mysqli_free_result($result);
mysqli_close($odbc_conn);
stream_wrapper_register('var', 'VariableStream');
$x=null;
$y=null;
$w=0;
$h=0;
$link='';
//Display the image contained in $data
$v = 'img'.md5($data);
$GLOBALS[$v] = $data;
$a = getimagesize('var://'.$v);
if(!$a)
$pdf->Error('Invalid image data');
$type = substr(strstr($a['mime'],'/'),1);
$pdf->Cell(1);
$pdf->Cell(26, 1, '', '', 0,'L');
$pdf->Cell(150, 1, '', '', 1,'L');
//650=150 choose your options for height and width
//845=156
//$xc=ceil((676-$a['width'])/2);
$pdf->Image('var://'.$v, 44, $y, 150, 0, $type, $link);
unset($GLOBALS[$v]);
}
这是代码$pdf->Image('http://www.elwebmaster.com/wp-content/uploads/2015/06/PHP-logo.png',30,278,8);
或者如果你的根目录$pdf->Image($_SESSION['raiz'].'imagens/tsunami.jpg',150,285,12);
你可以有斑点保存图像在你的SQL数据库中,然后使用$pdf->Image($_SESSION['raiz'].'imagens/picture.php?id=1',150,285,12);
其中id是数据库索引,picture.php是文件rets rieve你想要显示的图像
- 1. 需要帮助,以显示从MySQL数据库中的数据
- 2. 从mysql数据库显示图像(BLOB)到tkinter窗口
- 3. 如何显示来自mysql数据库的图像而不重叠,FPDF?
- 4. 显示从数据库检索图像到图像控制
- 5. 显示从mysql数据库
- 6. 从android数据库中显示图像
- 7. 从数据库中显示图像php
- 8. 从数据库中显示图像
- 9. 显示图像从数据库中ASP.NET
- 10. 从数据库中显示图像
- 11. 显示图像从数据库
- 12. 如何从数据库显示图像到剃刀视图?
- 13. PHP需要显示MPTT而不修改MySql数据库
- 14. 使用fpdf在PDF中显示图像
- 15. Django将不会从数据库中显示图像
- 16. 我需要显示数据从数据库到下拉模式CodeIgniter
- 17. 从blob显示图像mysql
- 18. 将数据库图像显示到stimulreport中
- 19. 根据MySQL数据库中的值显示图像
- 20. 显示从数据库到结果页面的图像
- 21. 显示从数据库的多个图像到asp.net页面
- 22. 需要显示从WebApi调用检索到的图像
- 23. 从数据库中显示的数据 - 包括图像
- 24. 使用JQuery示例需要的图像显示需要
- 25. 如何从SQL数据库动态显示/显示图像到Crystal Report 7?
- 26. 显示从MySQL数据库在PHP
- 27. 很热来显示二进制图像从数据库到图像框。?8
- 28. 联合图像和数据显示绑定到数据库
- 29. 如何将图像从sqlite显示到flex数据网格中
- 30. 从SQLite数据库中获取图像并将其显示到GridView Android Studio
看到更新的答案 – Mchl 2010-09-19 16:15:43