У меня есть изображение в базе данных mysql в качестве болта, и я хочу отобразить его в fpdf, используя php. У меня проблема с этим, поскольку я очень новичок в 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);
//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]); }
не//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://img.ruphp.com/php/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 – это файл, который возвращает изображение, которое вы хотите показать.