2017-11-01 10 views
0

MySQL에서 이미지 BLOB를 가져 와서 PDFlib로 PDF에 붙여 넣기를 원합니다. blob을 PDFlib의 일반 이미지로 사용할 수 있도록 변환하려면 어떻게해야합니까?MySQL에서 이미지 블롭을 PDFlib (PHP)로 PDF로로드

이것은 내가 지금하고있는 방법입니다. 내가 그 코드에 오류가 있기 때문에

$img = imagecreatefromstring($qra['photo']); //$qra['photo'] is the mysql blob field 

// Loading the image with PDFlib (this code is already tested with a normal image src like /images/example.jpg and works) 
$image = $p->load_image("auto", $img, ""); 
$p->fit_image($image, 10, 10, "boxsize={50 50} position=center fitmethod=meet"); 

은 어떻게 든 이미지는 imagecreatefromstring 제대로 만들어지지 않습니다.

blob 이미지를 올바르게 가져 와서 사용할 수 있도록하려면 어떻게해야합니까 (tmp 이미지도 사용할 수 있으므로 서버에 저장하십시오)?

+0

"imagecreatefromstring"에서 얻은 오류는 무엇입니까? – alistaircol

답변

1

. 나는 당신이 당신의 이미지를 데이터베이스에 저장된 바이트 배열로 가질 것을 기대한다. BLOB 필드를 문자열로 검색하고 PVF (PDFlib Virtual Filesystem)를 사용할 때 간단해야합니다. 이 기술을 사용하면 변수에 이름을 부여 할 수 있습니다.이 이름은 나중에 load_image() 호출에 사용될 수 있습니다.

는 PDFlib PHP 패키지뿐만에서 PDFlib Coobkook에 포함 starter_pvf.php 샘플에서 설명된다 http://www.pdflib.com/pdflib-cookbook/general-programming/starter-pvf/php-starter-pvf/

샘플 단지 디스크로부터 영상 데이터를 판독하지만,이 유사해야 데이터베이스에서 가져 오는 방법

# We just read some image data from a file; to really benefit 
# from using PVF read the data from a Web site or a database instead 

$imagedata = read_file("../input/PDFlib-logo.tif"); 
$p->create_pvf("/pvf/image", $imagedata, ""); 

# Load the image from the PVF 
$image = $p->load_image("auto", "/pvf/image", ""); 
1

나는 이런 식으로 뭔가가 당신을 위해 작동합니다 생각이 더 간단

<?php 

$img = imagecreatefromstring($qra['photo']); //$qra['photo'] is the mysql blob field 

ob_start(); // capture the image from the blob 
imagepng($img); // Output a PNG image to either the browser or a file 
$img = ob_get_clean(); // Get current buffer contents and delete current output buffer 

// img should now be png resource 

// Loading the image with PDFlib (this code is already tested with a normal image src like /images/example.jpg and works) 
$image = $p->load_image("auto", $img, ""); 
$p->fit_image($image, 10, 10, "boxsize={50 50} position=center fitmethod=meet");