php - 在 PHP 中压缩 PNG 文件

标签 php c compression png cairo

我正在生成带有 PHP 开罗扩展名的 PNG 文件。图像包含背景和文本。现在我想在 cairo 生成这些图像后用 PHP 压缩这些图像。有没有图书馆可以做到这一点?

我找到了 pngcrush 工具。但它是一个命令行工具。我不想调用 system 调用。如果没有 PHP 解决方案,C 解决方案也可以。在这种情况下,我将制作一个 PHP 扩展。

我已阅读 this related问题。但是里面没有答案。

最佳答案

您可以使用 imagepng() ...

//If you don't already have a handle to the image and it's just on the file system...
$im = imagecreatefrompng("yourGenerateFile.png");
$quality = 5; //0 - 9 (0= no compression, 9 = high compression)
imagepng($im, 'file/to/save.png', $quality);  //leave out filename if you want it to output to the buffer
imagedestroy($im);

关于php - 在 PHP 中压缩 PNG 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9947827/

相关文章:

java - 以编程方式在 Android 中的 Php 服务器上上传图像

c - fget 上的段错误

c - Go:导入和 C 库之间的类型冲突

c# - ServiceStack流压缩

php - 为什么我的 Joomla! 2.5 扩展安装内容从 admin 目录到 joomla 而不是从 site 目录? (可下载代码)

php - 从 Android 应用程序向 PHP 发送帖子

PHP/Twitter oAuth - 自动推文

php - mysql查询到html表

C、使用Pointers扫描打印Matrix

java - 有没有人得到压缩来使用 ASmack