ImageMagick:此图像格式没有解码委托程序' @ error/constitute.c/ReadImage/504

40
问题:ImageMagick convert无法裁剪图像。看起来它无法识别图片类型?
我尝试过:
我在网上搜索并看到了一些类似的问题,但都不是我的情况。
我尝试了他们的解决方案,包括:
  • 通过brew卸载和重新安装ImageMagick。
  • identify -list format (JPEG、GIF、PNG、TIFF等都在,并且都具有rw权限)
  • convert -version (png是内置代理之一)
  • convert pic1.png pic1-jpg.jpg (这个可以正常工作)
  • convert pic1-jpg.jpg pic1-jpg.jpg (这个也可以正常工作)
  • convert pic1-jpg.jpg 805X972+34+94 pic1-jpg-crop.jpg (这与png一样,产生了下面显示的错误)

我正在使用Mac OSX El Capitan,在终端中的其他所有功能都正常。ImageMagick已经安装。

当我运行:
$ convert /Users/Innovate/Desktop/crop/2015-04-26-GinaDate13_487.png 805X972+34+94 /Users/Innovate/Desktop/crop/2015-04-26-GinaDate13_487-cropped.png 

我收到以下错误信息:

convert: unable to open image `805X972+34+94': No such file or directory @ error/blob.c/OpenBlob/2702.

convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.

no decode delegate for this image format `' @ error/constitute.c/ReadImage/504

在其他相关帖子中,人们会看到类似于以下的信息(除了他们的图像类型或文件名和图像类型不同):

convert no decode delegate for this image format `PNG'

然而我的错误信息并没有提到图像文件类型...

我还没有尝试卸载ImageMagick然后手动从源代码安装,因为我对这样做不是很有信心...(解决方案在这里显示:https://stackoverflow.com/a/34633084/5398660

有谁知道可能出了什么问题吗?

此外,有谁能帮助我解释一下 @ error/constitute.c/ReadImage/504 这部分内容?我正在查看constitute.c的代码,但我不确定能否从中获得有用的信息来解决我的问题(我只知道一点C语言)

谢谢!


我认为在 805X972+34+94 之前缺少命令运算符。转换工具将几何参数视为文件路径处理。 - emcconville
尝试运行以下命令:convert /Users/Innovate/Desktop/crop/2015-04-26-GinaDate13_487.png -crop 805X972+34+94 /Users/Innovate/Desktop/crop/2015-04-26-GinaDate13_487-cropped.png - emcconville
哈哈,谢谢emcconville。我在发完这个帖子后就发布了解决方案。我想知道它是否与此处发布的示例不同:http://apple.stackexchange.com/a/128000/156787,因为它是El Capitan。 - Montag
你可以通过在裁剪坐标周围添加方括号 [...] convert /Users/Innovate/Desktop/crop/2015-04-26-GinaDate13_487.png[805X972+34+94] /Users/Innovate/Desktop/crop/2015-04-26-GinaDate13_487-cropped.png 或者在裁剪坐标之前加上 -crop 来完成。 - fmw42
10个回答

17
brew remove imagemagick //to delete current version
brew install imagemagick --build-from-source

在我的Mac上为我修复了它


4
我的原始回答中提到:通过brew卸载和重新安装ImageMagick。很抱歉没有明确给出命令,但我认为这应该很清楚(显然不是)。我不希望其他人在卸载并从源代码重新构建无效时感到沮丧。 - Montag
对我没用 - undefined

10

我在Ubuntu 20.04和ImageMagick上遇到了同样的错误。 必须按照此指南重新安装带有所有附加组件的ImageMagick:

#These are the steps required in order to Install ImageMagick with JPG, PNG and TIFF delegates.

sudo apt-get update 

#Install Build-Essential in order to configure and make the final Install

sudo apt-get install build-essential 

#libjpg62-dev required in order to work with basic JPG files

sudo apt-get install -y libjpeg62-dev 

#libtiff-dev is required in order to work with TIFF file format

sudo apt-get install -y libtiff-dev 

#Download ImageMagick

wget https://www.imagemagick.org/download/ImageMagick.tar.gz 

#Untar Imagemagick

tar xvzf ImageMagick.tar.gz 

#Access the working directory

cd ImageMagick/[version_number] 

#Configure and make sure to disable the "shared" option

./configure --disable-shared

#Make

sudo make

#Install

sudo make install

#Final Check

sudo make check

1
当我使用默认配置从源代码构建ImageMagick-7.1.0-16时,它安装到/usr/local/bin/magick,这意味着我需要最终的命令/usr/local/bin/magick mogrify -format jpg *.heic - Willi Ballenthin
我想在前面添加一行代码来检查是否安装了 pkg-config。如果没有安装 pkg-configconfigure 就不知道已安装的库的位置,例如 libtiff - Keugyeol

7

作为一名有所帮助的助手,我会为您翻译编程相关内容。以下是需要翻译的内容:

我也曾经为这个问题苦苦挣扎了几天,现在我来发表我的见解。在我的本地机器上运行ImageMagick命令没有问题,但是当我在运行在Azure云上的Tomcat服务器上运行命令时,出现了OP提到的错误信息。

通过运行以下命令,我可以确定原因:

convert -list format

在我的本地机器上,它会返回一个相当长的列表,列出了所有支持的格式,而在 Kudu(Azure CLI 工具)上,它会返回一个空结果。这表明 ImageMagick 没有找到处理所需的 DLL 文件的路径。
在我的情况下,问题仅仅是由于 Azure 上缺乏配置引起的:
- 系统环境变量 %PATH% 中缺少 ImageMagick 根文件夹 - 缺少一个名为 "MAGICK_HOME" 的环境变量(设置为 ImageMagick 安装目录的根文件夹) - 缺少一个名为 "MAGICK_CODER_MODULE_PATH" 的环境变量(设置为上述文件夹 + /modules/coders)
注意:对于在 Azure 上也遇到此问题的人们,您可以查看 this SO 回答,该回答解释了如何使用 XDT 转换添加环境变量。

3

好的,经过试验我找到了解决方法,现在将其发布出来以帮助其他可能遇到这个问题的人:

显然,这不是/不再是/对于我来说不是使用ImageMagick convert剪裁图像的方法。尽管这里显示了这种用法,但在我的El Capitan上没有用(也许是操作系统的问题?)。

正确的命令如下:

convert image.png -crop 805X972+34+94 image-crop.png

即命令为:

convert image.ext -crop heightXwidth+positionX+positionY* imagecropped.ext

更多信息可以在这里找到。从那个ImageMagick页面的描述中,我对其中含有“convert rose: -crop”的示例感到困惑,但您可以像我上面提到的那样使用它,而且很好用。


2
如果您查看您在答案中提供的示例,您会发现OP在代码示例中遗漏了-crop。如果您查看他的动画,您会发现它包含-crop。rose是内置于Imagemagick中用于测试的图像,因此可以将其用作rose:。 - Bonzo
1
谢谢Bonzo,注意细节做得很好。我更新了我链接的示例(带有动画),以修复缺失的-crop。感谢您解释了“rose”是什么。 - Montag
很高兴你解决了问题,只是不幸选择了一段糟糕的代码。一旦你掌握了Imagemagick,它就可以变得非常简单。但它也可以执行非常复杂的命令。 - Bonzo

3

在Ubuntu(20.04)上安装带有JPG、PNG和TIFF代理的ImageMagick

方法1

如果你使用某种Linux发行版,那么很有可能ImageMagick已经安装在你的计算机上了;如果你使用Windows系统,则很可能没有安装。无论哪种情况,你都可以输入以下命令来查找:

  1. 克隆源代码库:
git clone https://github.com/ImageMagick/ImageMagick.git ImageMagick-7.1.0    
  1. Next configure and compile ImageMagick. Note the pkg-config script is required so that ImageMagick can find certain optional delegate libraries on your system. To configure, type:

    cd ImageMagick-7.1.0
    ./configure
    make
    
  2. If build fails, try gmake instead. For advanced users, we recommend a modules build:

    ./configure --with-modules
    
  3. If ImageMagick configured and compiled without complaint, you are ready to install it on your system. Administrator privileges are required to install. To install, type

    sudo make install
    
  4. You may need to configure the dynamic linker run-time bindings:

    sudo ldconfig /usr/local/lib
    
  5. Finally, verify the ImageMagick install worked properly, type

    /usr/local/bin/convert logo: logo.gif
    
  6. For a more comprehensive test, run the ImageMagick validation suite. Ghostscript and Freetype are prerequisites, otherwise expect the EPS, PS, PDF and text annotations tests to fail.

    make check
    

方法2

请按照下面的链接进行操作

使用JPG、PNG和TIFF委托安装ImageMagick - Ubuntu (20.04)


1
今天我也遇到了一个问题,涉及到一个应用不同颜色空间配置文件的转换操作。
看起来imagick的convert命令对配置文件名的扩展名非常敏感。在我的情况下,一个没有后缀的临时文件引发了与问题标题相同的错误消息。
convert infile.jpg -profile /tmp/profile-without-suffix outfile.jpg

将正确的后缀添加到配置文件名中即可解决问题:(假设为ICC格式)
convert infile.jpg -profile /tmp/profile-without-suffix.icc outfile.jpg

1

我因缺少一些单引号而收到了相同的错误。

当使用带引号的convert -draw组合图像时,提供的图像必须用引号括起来。

没有此图像格式的解码代理 `' @ error/constitute.c/ReadImage/504

convert myBackground.png -font Arial -pointsize 20 \
  -draw "gravity west image Over 50,80,20,20 'myForeground.png'" \
  # -----------------------------------------^ added missing single quotes
  -flatten ./finalImage.jpg                  

当我在myForeground周围添加单引号时,问题消失了。多么糟糕的错误!

1

对于我(在macOS Mojave上,使用CraftCMS的Imagick),我不得不使用pecl uninstall imagickpecl install imagick重新安装Imagick(然后使用sudo apachectl -k restart重新启动Apache)。我必须运行了brew upgrade并获得了一个更新版本的ImageMagick,这导致Imagick出现了类似于NoDecodeDelegateForThisImageFormat 'JPEG' @ error/constitute.c/ReadImage/556的错误。


0

另一种Imagemagick命令是:

convert pic1-jpg.jpg[805x972+34+94] pic1-jpg-crop.jpg

或者如之前所述

convert pic1-jpg.jpg -crop 805x972+34+94 +repage pic1-jpg-crop.jpg

请查看https://www.imagemagick.org/script/command-line-processing.php上的内联图像裁剪。

通常,我更喜欢在宽度和高度之间使用小写字母x而不是大写字母X,以便更容易阅读。但两者都可以。


0

我使用了一个合适的docker镜像,例如:

docker run -v /path/to/picsdir/:/pics --rm dpokidov/imagemagick /pics/img.heic /pics/img.png

这帮助我将HEIC转换为PNG


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接