在PHP(plphp)中,我们如何使用Imagick管理存储在bytea中的文件?

发布于 2024-12-13 20:24:06 字数 419 浏览 5 评论 0原文

我们使用 bytea 列将整个图像文件存储在 PostgreSQL 中。

在 PHP 中,我尝试从 bytea 字段打开图像文件(这些存储为十六进制),然后想要使用 Imagick 操作/转换图像。

字节流必须从十六进制转换为可管理的 - 以类似文件的方式 - 由 Imagick 进行吗?还有其他秘方吗?

如果我们必须读取文件头之外的内容,我也不会感到惊讶。违规片段如下:

// Decode image from hex?
$image = new Imagick ($row['thewholefile']);
// ERROR:  Uncaught exception 'ImagickException' with message 'Unable to read the file: /x0000000 (etc)

We are storing entire image files in PostgreSQL, using bytea columns.

In PHP, am trying to open an image file from the bytea field (these stored as hex), then want to manipulate/convert the image using Imagick.

Must the bytestream be converted out of hex to be manageable - in a file-like way - by Imagick? Is there any other secret sauce?

I wouldn't be surprised if we had to read beyond the file header bits, either. Offending snippet is below:

// Decode image from hex?
$image = new Imagick ($row['thewholefile']);
// ERROR:  Uncaught exception 'ImagickException' with message 'Unable to read the file: /x0000000 (etc)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟柳画桥 2024-12-20 20:24:06

实际上,这里的问题与 PostgreSQL 的 bytea 表示格式有关 - 由于我们使用 PG 的 v9.n,默认输出是十六进制:

我们必须首先将输出设置为 PG 的“Old School”bytea 处理。然后,通过对原始列数据进行 pg 转义,我们得到了可以使用的东西:

SET bytea_output = 'escape'

$unescaped   = pg_unescape_bytea($content);

Actually the problem here had to do with PostgreSQL's bytea presentation format- as we are using v9.n of PG, the default output is hex:

We had to first set output to PG's 'Old School' bytea handling. Then, by pg-unescaping the raw column data, we had something we could work with:

SET bytea_output = 'escape'

$unescaped   = pg_unescape_bytea($content);
两人的回忆 2024-12-20 20:24:06

错误非常清楚,就像文档一样:构造函数需要一个文件名或文件名数组。使用 Jauzsika 的解决方案。

The error is pretty clear, just as the documentation: the constructor requires a filename or an array of filenames. Use Jauzsika's solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文