首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用MySQL ( PDFlib )将图像块从PDFlib加载到PDF中

用MySQL ( PDFlib )将图像块从PDFlib加载到PDF中
EN

Stack Overflow用户
提问于 2017-11-01 13:17:56
回答 2查看 784关注 0票数 0

我想从MySQL中获取我的图像块,并将其粘贴到一个带有PDFlib的PDF中。如何转换blob,以便将其用作PDFlib的正常图像?

我现在就是这样做的。

代码语言:javascript
复制
$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映像也能工作)?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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/中。

示例只是从磁盘读取图像数据,但这应该类似于从数据库中获取图像数据。

代码语言:javascript
复制
# 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
EN

Stack Overflow用户

发布于 2017-11-02 14:42:57

我想像这样的东西会对你有用的:

代码语言:javascript
复制
<?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");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47055783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档