Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. $query = "SELECT imageField FROM yyy WHERE ...";
  2. $result = mysql_query($query);
  3. $row = mysql_fetch_assoc($result);
  4. $image = $row['imageField'];
  5.  
  6. $pdf->MemImage($image, 50, 30);
  7.  
  8. //Alternatively
  9. //1) Put the class VariableStream inside your php file instead of declaring it
  10. //--------------------------
  11.  
  12. enter code here
  13.  
  14. class VariableStream
  15. {
  16. var $varname;
  17. var $position;
  18.  
  19. function stream_open($path, $mode, $options, &$opened_path)
  20. {
  21. $url = parse_url($path);
  22. $this->varname = $url['host'];
  23. if(!isset($GLOBALS[$this->varname]))
  24. {
  25. trigger_error('Global variable '.$this->varname.' does not exist', E_USER_WARNING);
  26. return false;
  27. }
  28. $this->position = 0;
  29. return true;
  30. }
  31.  
  32. function stream_read($count)
  33. {
  34. $ret = substr($GLOBALS[$this->varname], $this->position, $count);
  35. $this->position += strlen($ret);
  36. return $ret;
  37. }
  38.  
  39. function stream_eof()
  40. {
  41. return $this->position >= strlen($GLOBALS[$this->varname]);
  42. }
  43.  
  44. function stream_tell()
  45. {
  46. return $this->position;
  47. }
  48.  
  49. function stream_seek($offset, $whence)
  50. {
  51. if($whence==SEEK_SET)
  52. {
  53. $this->position = $offset;
  54. return true;
  55. }
  56. return false;
  57. }
  58.  
  59. function stream_stat()
  60. {
  61. return array();
  62. }
  63. }
  64. //----------------------------------------------------
  65. //2) open and read your mysql longblob that contains your binary data from your image
  66. //in my case the function declaration is this
  67.  
  68. function showImage($cdImg) {
  69.  
  70. Global $pdf;
  71. //declare your pdf class
  72. //Connects the way you do. this case assigned as $odbc_conn
  73.  
  74. $query = 'SELECT cd_img, ds_img, bin_img FROM tb_img WHERE cd_img = '.$cdImg;
  75.  
  76. $result= mysqli_query($odbc_conn, $query);
  77.  
  78. $row = mysqli_fetch_array($result);
  79.  
  80. if (!empty($row["bin_img"]))
  81. {
  82.  
  83. //IF your data is encoded
  84. //$data=base64_decode($row['bin_img']);
  85. //
  86. $data=$row['bin_img'];
  87. }
  88.  
  89. mysqli_free_result($result);
  90.  
  91. mysqli_close($odbc_conn);
  92.  
  93. stream_wrapper_register('var', 'VariableStream');
  94.  
  95. $x=null;
  96.  
  97. $y=null;
  98.  
  99. $w=0;
  100.  
  101. $h=0;
  102.  
  103. $link='';
  104.  
  105.  
  106. //Display the image contained in $data
  107. $v = 'img'.md5($data);
  108. $GLOBALS[$v] = $data;
  109. $a = getimagesize('var://'.$v);
  110. if(!$a)
  111. $pdf->Error('Invalid image data');
  112. $type = substr(strstr($a['mime'],'/'),1);
  113. $pdf->Cell(1);
  114. $pdf->Cell(26, 1, '', '', 0,'L');
  115. $pdf->Cell(150, 1, '', '', 1,'L');
  116. //650=150 choose your options for height and width
  117. //845=156
  118. //$xc=ceil((676-$a['width'])/2);
  119.  
  120. $pdf->Image('var://'.$v, 44, $y, 150, 0, $type, $link);
  121.  
  122. unset($GLOBALS[$v]);
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement