GD imagejpeg() 压缩?

发布于 2024-11-18 00:23:21 字数 455 浏览 10 评论 0原文

我正在开发一个项目,使用 GD 库在 PHP 中编辑 jpg 的像素。 PHP 的输出保留了我设置的像素值(咳嗽-隐写术-咳嗽),这对我的项目来说是非常重要和关键。

这是我第一次尝试用 PHP 进行图像处理。我以前在 Java 实现中没有遇到过任何问题,所以我很愚蠢,没有在进一步研究之前研究 GD 的 jpeg 压缩质量。

事实证明,经过我的努力,我的代码并没有按照预期的方式运行。我很确定这不是我的代码(在编辑的图像资源上测试了编码和解码功能并且它们有效)。

我的问题是:

  1. 我看到的唯一问题是 imagejpeg() 的压缩。我是对的吗?

  2. 是否有任何库可以提供我需要的压缩?(保留我更改的像素值)

I'm working on a project where I edit the pixels of a jpg in PHP using the GD library.
Its very crucial and key to my project that the output from PHP retains the pixel values I set (cough-steganography-cough).

This is the first time I've attempted image manipulation in PHP. I've had no problems before in my Java implementations, so I was foolish not to investigate GD's jpeg compression quality before pursuing further.

It turns out that after all my effort, my code does not function the way its supposed to. I am pretty sure it is not my code (tested the encode and decode functions on edited image resources and they worked).

My questions are:

  1. The only problem I can see is with imagejpeg()'s compression. Could I be right?

  2. Are there any libraries that provide the compression that I need?(retain pixel values that I changed)

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

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

发布评论

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

评论(3

帅气称霸 2024-11-25 00:23:21

默认情况下,imagejpeg 输出的图像质量为 75,尝试将其设置为 100 以获得完整质量的图像。

  bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )

查看手册了解更多详细信息。

还可以尝试使用 imagecopyresampled。 (我认为您会在代码中的某处使用 imagecopyresized 。使用 imagecopyresampled 而不是它。)

编辑

那么我认为您应该尝试 < a href="http://www.imagemagick.org/script/index.php" rel="nofollow">ImageMagick(或 GD2)。它提供了比 GD 更好的质量。检查这个

By default the quality of the image output from imagejpeg is 75, Try setting it at 100 to get the image at full quality.

  bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )

Check the manual for further details.

Also try using imagecopyresampled. (I think you would have been using imagecopyresized somewhere in your code. Use imagecopyresampled instead of it. )

EDIT

Then I think you should try ImageMagick(or GD2). It gives a better quality than GD . Check this

一身仙ぐ女味 2024-11-25 00:23:21

如果您执行隐写术JPEG 文件格式不太适合隐写术> 逐个像素。

JPEG 使用图像压缩 - 即使具有最高质量 - 也会破坏每个像素的位级信息。 jpeg 类型的压缩(有损压缩)是为人类设计的眼睛/大脑保留图像,但不保留文件中的图像位。

您需要使用能够保留像素的图像格式 - 正如您已经编写的那样。这种格式更可能是带有 RLE 压缩的 BMP 或带有 ZIPRLE 的 TIFF 图像格式压缩。这称为无损数据压缩

The JPEG file format is not very suitable for steganography if you do the steganography pixel by pixel.

JPEG uses an image compression - that even with maximum quality - that will destroy the information on the bit level on each pixel. The jpeg type of compression (lossy compression) is made for the human eye/brain to retain the image but not the bits of the image in the file .

You need to use an image format that is capable to retain the pixels - as you wrote it already as well. Such a format more likely is BMP with RLE compression or the TIFF image format with ZIP or RLE compression. That's called lossless data compression.

只是在用心讲痛 2024-11-25 00:23:21

使用 imagepng() 而不是 imagejpeg() 函数并将压缩设置为 0 :

bool imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] )

请参阅:http://php.net/manual/en/function.imagepng.php

Use the imagepng() instead of the imagejpeg() function and set the compression to 0 :

bool imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] )

See : http://php.net/manual/en/function.imagepng.php

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