0

I am trying to generate a thumbnail for different Pdf's using ImageMagick. The below command works for most of the scenarios. However, it fails for very few PDF's.

The following the command I am using.

/usr/local/bin/convert “a.pdf[0]" -thumbnail  300x143 -strip -quality 80.0 -colorspace sRGB -intent relative -density 72 -auto-orient -background white -alpha remove “b.jpeg"

The following is the error I received for the failed ones.

convert: no decode delegate for this image format PNG' @ error/constitute.c/ReadImage/556. convert: no images defined/mnt/cgi_otmm/assethub/stage/thumb/vol1/INTERNAL_7e9439b4-c5bb-4a46-a81d-738d2c138432_pdf_thumb.jpeg' @ error/convert.c/ConvertImageCommand/3288.

I have installed ImageMagick manually from the source as mentioned in the below URL.

https://www.imagemagick.org/script/install-source.php

I have installed the delegates manually from the location https://www.imagemagick.org/download/delegates/.

I have installed libjpeg, libpng, libFreeType and libTiff

I have used the following commands to install the same. The commands to install it are taken from one the comments in stackoverflow. ImageMagick no decode delegate

wget http://www.imagemagick.org/download/delegates/jpegsrc.v9a.tar.gz
sudo tar xvf jpegsrc.v9a.tar.gz -C /usr/local/src/
cd /usr/local/src/jpeg-9a
./configure --enable-shared
make
sudo make install
  • What Operating System are you using? – Mark Setchell Oct 18 '18 at 10:56
  • @MarkSetchell Centos – jagannathan rajagopalan Oct 18 '18 at 11:45
  • See https://stackoverflow.com/questions/52861946/imagemagick-not-authorized-to-convert-pdf-to-an-image/52863413?s=6|0.0000#52863413 – fmw42 Oct 18 '18 at 18:31
  • @fmw42 this does not seem to be the issue. Tried the fix as well. It does not fix the issue. It is not converting only for few PDF's. It works for most of them. – jagannathan rajagopalan Oct 19 '18 at 04:10
  • If your PDF is CMYKA (i.e. with alpha), then Ghostscript will not process it correctly. You will need to convert it to RGBA. `convert -colorspace sRGB image.pdf image.jpg`. Add your other commands as desired, but put -colorspace sRGB before the pdf. If on a very old Imagemagick (or the image seems too dark), then change to -colorspace RGB. If this does not solve it, then post a link to one of your problematic PDFs. I am puzzled why you are getting a PNG error for a command that does not involve PNG. Do you have libpng installed? Does PNG show up in `convert -version`? – fmw42 Oct 19 '18 at 04:48
  • That error about PNG may be because the delegate.xml file is trying to use pngalpha for Ghostscript for PDFs with alpha and if your PDF is CMYKA, then my comment above would explain that. – fmw42 Oct 19 '18 at 04:52
  • @fmw42 I tried with the following command. It still showed the same error. /usr/local/bin/convert -colorspace sRGB "/mnt/dcv/qtr_stg/internal/1533081600/INTERNAL_7e9439b4-c5bb-4a46-a81d-738d2c138432.pdf[0]" -thumbnail 300x143 -strip -quality 80.0 -intent relative -density 72 -auto-orient -background white -alpha remove "/mnt/cgi_otmm/assethub/stage/thumb/vol1/INTERNAL_7e9439b4-c5bb-4a46-a81d-738d2c138432.pdf_thumb.jpeg" – jagannathan rajagopalan Oct 19 '18 at 05:44
  • @fmw42 Thanks for your continued response. the convert -version does not return pnglib. However, i installed the libPng using hte commands mentioned in the question. – jagannathan rajagopalan Oct 19 '18 at 05:45
  • What do you get from `convert -version`? Does it include png in the living. If not, then your install was not correct. You may have to install IM after installing PNG. Try `convert -colorspace sRGB image.pdf image.tiff` or `convert -colorspace sRGB image.pdf -background white -flatten image.jpg` to see if that works. If it works, then it is a libpng issue. If it fails, then post an example pdf so I can test. – fmw42 Oct 19 '18 at 05:49
  • @fmw42 convert -version.[svdamilad@corp.target.com@cgilx2007 ~]$ convert -version Version: ImageMagick 7.0.8-12 Q16 x86_64 2018-10-19 https://imagemagick.org Copyright: © 1999-2018 ImageMagick Studio LLC License: https://imagemagick.org/script/license.php Features: Cipher DPC HDRI OpenMP Delegates (built-in): jpeg zlib This is the response to the command. Is there any way we can install latest version of Image Magick in centos using yum? The same PDF works in MAC if i install ImageMagick using brew in MAC. yum install of centos seems to be returning some old version of Image Magick – jagannathan rajagopalan Oct 19 '18 at 05:52
  • You only have jpeg and zlib delegates. So that explains some of your issues. You do not have libpng installed so you cannot use PNG for input or output. You do not have tiff nor many other useful delegates. How did you install? If you got it from binary, then it should have all the needed delegates. If you installed from source, that is hard to do as each delegate may need other delegates installed first. You are also using IM 7, which should be using magick rather than convert. To install from binary see https://imagemagick.org/script/download.php – fmw42 Oct 19 '18 at 05:55
  • @fmw42 I have installed via binary, I could'nt install latest ImageMagick version 7+ in centos 7. That is yum install ImageMagick does not install Magick 7. Is it possible to install Magick 7+ version in centos using yum command? – jagannathan rajagopalan Oct 19 '18 at 06:11
  • I installed libpng by the following commands. downloaded the delegate zip. and then executed the following commands. .1) /configure --enable-shared 2) make 3) sudo make install Then we execute the image magick again. 1) ./configure 2) sudo make install 3) sudo ldconfig /usr/local/lib – jagannathan rajagopalan Oct 19 '18 at 06:12
  • Sorry, I am not a Linux user and do not know much about installing on that platform. The link I gave you should allow you to install the binary – fmw42 Oct 19 '18 at 16:28

0 Answers0