我想从MySQL中获取我的图像块,并将其粘贴到一个带有PDFlib的PDF中。如何转换blob,以便将其用作PDFlib的正常图像?
我现在就是这样做的。
$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映像也能工作)?
发布于 2017-11-07 12:11:14
这更简单。我希望您将图像作为字节数组存储在数据库中。因此,当您将BLOB字段作为字符串检索并使用PVF (PDFlib虚拟文件系统)时,应该很简单。使用这种技术,您可以给变量一个名称,它可以在load_image()调用之后使用。
这在starter_pvf.php示例中得到了演示,它包括在PDFlib软件包中,以及PDFlib Coobkook: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", "");发布于 2017-11-02 14:42:57
我想像这样的东西会对你有用的:
<?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");https://stackoverflow.com/questions/47055783
复制相似问题