php exec imagemagick- magick转换不工作Ubuntu Linux

发布于 2025-01-19 17:44:58 字数 1320 浏览 1 评论 0 原文

我正在使用 ubuntu 并安装了 ImageMagick

identify -version

给出:

Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib

我尝试过:

exec('magick img.jpg ( -clone 0 -fill white -colorize 100 ) ( -clone 0 -color-threshold "gray(251)-gray(254)" ) -compose over -composite -quality 80% result.jpg', $output, $return_var);
echo '<pre>' , var_dump($output) , '</pre>';

还使用 convertmagick Convert 而不是 magick

然后根据 这个答案我打开了/etc/ImageMagick-6/policy.xml

并且将 更改为

但仍然不起作用,并且 $output 总是返回空数组

PS:我不想使用 PHP 扩展,已经使用了,而且它有一些缺陷

I'm using ubuntu and have installed ImageMagick

identify -version

gives:

Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib

I tried:

exec('magick img.jpg ( -clone 0 -fill white -colorize 100 ) ( -clone 0 -color-threshold "gray(251)-gray(254)" ) -compose over -composite -quality 80% result.jpg', $output, $return_var);
echo '<pre>' , var_dump($output) , '</pre>';

also convert and magick convert instead of magick

then according to this answer I opened /etc/ImageMagick-6/policy.xml

and changed <policy domain="coder" rights="none" pattern="PDF" /> to <policy domain="coder" rights="read|write" pattern="PDF" />

but still doesn't work and $output always returns empty array

PS: I don't want to use the PHP extension, already did and it has some flaws

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

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

发布评论

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

评论(2

不…忘初心 2025-01-26 17:44:58

请使用PHP进行ImageMagick进行一些测试,以了解您的版本是什么。请提供每个返回的消息。

<?php
echo "<pre>";
system("type -a convert");  
echo "</pre>";
?> 

<?php
exec("magick -version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

这个工作吗?

<?php
exec('magick img.jpg \( -clone 0 -fill white -colorize 100 \) \( -clone 0 -color-threshold "gray(251)-gray(254)" \) -compose over -composite -quality 80% result.jpg 2>&1',$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

你收到什么消息?

Please do some testing in Imagemagick with PHP to see what your versions are. Please provide any messages that come back for each.

<?php
echo "<pre>";
system("type -a convert");  
echo "</pre>";
?> 

<?php
exec("magick -version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

Does this work?

<?php
exec('magick img.jpg \( -clone 0 -fill white -colorize 100 \) \( -clone 0 -color-threshold "gray(251)-gray(254)" \) -compose over -composite -quality 80% result.jpg 2>&1',$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

What messages do you get?

将军与妓 2025-01-26 17:44:58

转换将其输出写入磁盘( result.jpg )。 exec()的输出参数是否为stdout的任何输出。如果您希望 $ output 中的图像数据指定的输出文件 -

引用男人页面:

默认情况下,“文件”的图像格式由其魔术数确定。要指定特定的图像格式,请在文件名之前使用图像格式名称和冒号(IE PS:Image)或将图像类型指定为文件名后缀(IE Image.ps)。为标准输入或输出指定“文件”为“ - ”。

Convert writes its output to disk (result.jpg). The output argument of exec() if for any output to stdout. If you want the image data in$output specify an output file of -.

To quote the man page:

By default, the image format of 'file' is determined by its magic number. To specify a particular image format, precede the filename with an image format name and a colon (i.e. ps:image) or specify the image type as the filename suffix (i.e. image.ps). Specify 'file' as '-' for standard input or output.

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