Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

debian - ImageMagick: How do I convert pdf to jpg? I get ERROR: no decode delegate for this image format

Problem

I need to convert a multipage pdf to jpg-files but ImageMagick keeps throwing errors that are hard to interpret.

Installing ImageMagick

At first I installed it using apt-get, but as I could read that several people had problems doing that, i ended up installing it from source.

My linux distribution (A Docker image):

>lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

Installing ImageMagick from source:

# Installing build tools and ghostscript
apt update
apt-get install -y build-essential make ghostscript

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

# Installing and cleaning up
tar xvzf ImageMagick.tar.gz && cd ImageMagick-7* && ./configure && make && make install && ldconfig /usr/local/lib && cd .. && rm -r ImageMagick-7*

# Checking ImageMagick version
>magick -version
Version: ImageMagick 7.0.10-60 Q16 x86_64 2021-01-25 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): jpeg x xml zlib

Converting files

# Image to image
>convert test.jpg test.png

# PDF to image 
>convert test.pdf test.jpg
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/572.
convert: no images defined `test.jpg' @ error/convert.c/ConvertImageCommand/3304.

Is Ghostscript the problem?

The Ghostscript installation is a common problem for many, but Ghostscript seems to work fine and produce a jpg-file

# PDF to image with Ghostscript
gs -sDEVICE=pngalpha -sOutputFile=test.jpg test.pdf

Do I have to install more Delegates?

The error suggests that there is something off with my limited delegates, so I thought to install all dependencies up front.

# Listing dependencies
>apt update && apt build-dep imagemagick
Reading package lists... Done
E: You must put some 'source' URIs in your sources.list

This is where I got stuck.

question from:https://stackoverflow.com/questions/65920674/imagemagick-how-do-i-convert-pdf-to-jpg-i-get-error-no-decode-delegate-for-th

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Solution

It turned you that it was indeed the delegates that were missing. I haven't seen this well described in the documentation or anywhere else.

NOTE: Delegates should be installed before you install ImageMagick

Here is how I fixed it:

# Adding source URI
echo "deb-src http://deb.debian.org/debian buster main" >> /etc/apt/sources.list
apt update

# Installing dependencies
apt-get build-dep imagemagick

Now I can convert pdf to jpg!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...