Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PNG压缩使用pngquant,php脚本中正确的shell命令 函数compress\u png($path\u to\u png\u file,$max\u quality=90) { 如果(!file_存在($path_to_png_file)){ 抛出新异常(“文件不存在:$path_to_png_File”); } $min_质量=60; $compressed_png_content=shell_exec(“pngquant--quality=$min_quality-$max_quality-_Php_Apache_Shell - Fatal编程技术网

PNG压缩使用pngquant,php脚本中正确的shell命令 函数compress\u png($path\u to\u png\u file,$max\u quality=90) { 如果(!file_存在($path_to_png_file)){ 抛出新异常(“文件不存在:$path_to_png_File”); } $min_质量=60; $compressed_png_content=shell_exec(“pngquant--quality=$min_quality-$max_quality-

PNG压缩使用pngquant,php脚本中正确的shell命令 函数compress\u png($path\u to\u png\u file,$max\u quality=90) { 如果(!file_存在($path_to_png_file)){ 抛出新异常(“文件不存在:$path_to_png_File”); } $min_质量=60; $compressed_png_content=shell_exec(“pngquant--quality=$min_quality-$max_quality-,php,apache,shell,Php,Apache,Shell,此代码返回错误: 致命错误:未捕获异常“exception”,消息为“转换为压缩PNG失败”。服务器上是否安装了pngquant 1.8+ 堆栈跟踪:压缩png('pic.png',60)#1{main}抛出 如何编写shell命令?以及如何在服务器上安装pngquant:windowsserver2008r2sp1、php5.5.5、apache2.4。此处下载的windows文件:首先指定pngquant的完整路径。路径可能未按预期定义。接下来,确保您没有权限问题。Apache可能以本地服务

此代码返回错误:

致命错误:未捕获异常“exception”,消息为“转换为压缩PNG失败”。服务器上是否安装了pngquant 1.8+ 堆栈跟踪:压缩png('pic.png',60)#1{main}抛出


如何编写shell命令?以及如何在服务器上安装pngquant:windowsserver2008r2sp1、php5.5.5、apache2.4。此处下载的windows文件:

首先指定
pngquant
的完整路径。路径可能未按预期定义。接下来,确保您没有权限问题。Apache可能以本地服务或其他帐户的形式运行,而PHP可能就是以这种方式运行的。此外,请确保转义最小/最大质量值,就像转义文件名一样。我还要验证它们是否为整数。如果不起作用,您有命令示例,以及文件结构示例吗?我要举个例子
function compress_png($path_to_png_file, $max_quality = 90)
{
    if (!file_exists($path_to_png_file)) {
        throw new Exception("File does not exist: $path_to_png_file");
    }
    $min_quality = 60;
    $compressed_png_content = shell_exec("pngquant --quality=$min_quality-$max_quality - < ".escapeshellarg($path_to_png_file));
    if (!$compressed_png_content) {
        throw new Exception("Conversion to compressed PNG failed. Is pngquant 1.8+ installed on the server?");
    }
    return $compressed_png_content;
}
$read_from_path = "pic.png";
$save_to_path = "compressed_file.png";
$compressed_png_content = compress_png($read_from_path);
file_put_contents($save_to_path, $compressed_png_content);