Converting EPS(EPT) to PNG/GIF with imagemagick creates extra frame - imagemagick

Using Ghostscript 9.53 on Mac with Imagemagick 7.0.10-59.
The EPS has a Tiff Preview on it, which gets added as a frame in gif or as an extra image for PNG. It started happening after updating imagemagick and ghostscript.
Ghostscript 9.51 and imagemagick 7.0.10-0 without ghostscript delegate did not have this issue.
Command: magick convert -verbose -density 200 -channel RGBA -colorspace RGB -alpha On my.eps my.gif
the new output is as follows:
/var/folders/zb/ygl385yn3_ggw_bqpdp4940r0000gn/T/magick-3MLz7XbvUU4OJOQBAqLqB-7bteT5s-061 PNG 890x505 890x505+0+0 8-bit sRGB 23054B 0.020u 0:00.014
EPS:/var/folders/zb/ygl385yn3_ggw_bqpdp4940r0000gn/T/magick-tWS3M8-k1os9hbHqWGRzlibuupNgItzv=>/var/folders/zb/ygl385yn3_ggw_bqpdp4940r0000gn/T/magick-tWS3M8-k1os9hbHqWGRzlibuupNgItzv EPS 890x505 890x505+0+0 16-bit sRGB 23054B 0.000u 0:00.000
TIFF:~/Downloads/my.eps=>~/Downloads/my.eps TIFF 321x182 321x182+0+0 8-bit Palette sRGB 256c 148108B 0.000u 0:00.004
~/Downloads/my.eps[0] EPT 890x505 890x505+0+0 16-bit sRGB 23054B 0.010u 0:00.008
~/Downloads/my.eps[0] TIFF 321x182 321x182+0+0 8-bit Palette sRGB 256c 148108B 0.010u 0:00.000
[ghostscript library 9.52] -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r200x200' -g890x505 -dFirstPage=1 -dLastPage=1 -dEPSCrop '-sOutputFile=/var/folders/zb/ygl385yn3_ggw_bqpdp4940r0000gn/T/magick-3MLz7XbvUU4OJOQBAqLqB-7bteT5s-06%d' '-f/var/folders/zb/ygl385yn3_ggw_bqpdp4940r0000gn/T/magick-vyRuqlNsQcaG9cv4dJXLql9ChPsp95-g' '-f/var/folders/zb/ygl385yn3_ggw_bqpdp4940r0000gn/T/magick-nK22ULA5kPuCN9Yq8dKM7E8NTQxI82vH'~/Downloads/my.eps=>~/Downloads/my.gif EPT 890x505 890x505+0+0 16-bit Palette sRGB 35c 18001B 0.960u 0:00.139
convert: Invalid TIFF directory; tags are not sorted in ascending order. `TIFFReadDirectoryCheckOrder' # warning/tiff.c/TIFFWarnings/1044.
Older version ouput was as follows:
'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r200x200' -g890x505 -dEPSCrop '-sOutputFile=/var/folders/6d/tw_d66k92ld2dc5wvtzxr4y00000gn/T/magick-40084UYHZpdfAwolz%d' '-f/var/folders/6d/tw_d66k92ld2dc5wvtzxr4y00000gn/T/magick-40084Zug0r87QHWuH' '-f/var/folders/6d/tw_d66k92ld2dc5wvtzxr4y00000gn/T/magick-40084JWA1MKLfJ5i7'
/var/folders/6d/tw_d66k92ld2dc5wvtzxr4y00000gn/T/magick-40084UYHZpdfAwolz1 PNG 890x505 890x505+0+0 8-bit sRGB 23054B 0.020u 0:00.013
EPS:/var/folders/6d/tw_d66k92ld2dc5wvtzxr4y00000gn/T/magick-40084Rxd2cgpYXsmR=>/var/folders/6d/tw_d66k92ld2dc5wvtzxr4y00000gn/T/magick-40084Rxd2cgpYXsmR EPS 890x505 890x505+0+0 16-bit sRGB 23054B 0.010u 0:00.000
~/Desktop/my.eps EPT 890x505 890x505+0+0 16-bit sRGB 23054B 0.000u 0:00.000
~/Desktop/my.eps=>~/Desktop/my.gif EPT 890x505 890x505+0+0 16-bit PaletteBilevelAlpha sRGB 3c 9061B 0.830u 0:00.121
Is there a way for me to tell imagemagick to ignore tiff preview?
EPS File here
Bad Gif here
** Updated file links

In ImageMagick 7, use magick not magick convert and not convert. Also if you have only one frame/page and want to keep on that, then add [0] to your input image. So try
magick -verbose -density 200 -channel RGBA -colorspace RGB -alpha On my.eps[0] my.gif

Related

ImageMagick error: -contrast option replaced with -level (huh?)

I have a simple ImageMagick command that uses -contrast which is well-documented here: https://imagemagick.org/script/command-line-options.php#contrast
My command:
magick in.jpg -enhance -contrast -background white -quality 100 -resize 200x200^ -gravity center -extent 200x200 out.jpg
But I'm getting this error: magick: option has been replaced '-contrast', use "-level" at CLI arg 3 # warning/operation.c/CLISimpleOperatorImage/2078.
I'm using ImageMagick 7.0.9-7 Q16 x86_64 2019-12-02.
Features: Cipher DPC HDRI Modules OpenMP(3.1)
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib gvc heic jbig jng jp2 jpeg lcms ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib
So... why is it complaining about the -contrast option? It looks like -contrast is still there, and I don't see how -level is supposed to replace it. There's nothing I can find about -contrast being replaced/removed. It's very strange.
** UPDATE - even I can see right here in the code where that error message is generated. However, I can't see why it's doing that, and as I said, can't find anything in any documentation that implies -contrast should not be used.

corrupted text characters with Imagemagick label:

I'm running into a strange bug that I cannot reproduce locally. But on Google Cloud Functions, the same text usually does the same thing, but it too has been somewhat of a rolling issue - sometimes it happens, then magically goes away.
Here's a sample of the convert call and the resulting corrupt text:
convert -background none -stroke "rgb(0, 0, 0, 0.0)" -fill "rgba(255, 255, 255, 1)" -font ./fonts/FrederickatheGreat-Regular.ttf -pointsize 68 label:"Carly" -trim \( +clone -background "rgba(135, 138, 140, 0.59)" -shadow 80x8+8+10 \) +swap -background none -layers merge +repage -rotate 0 /tmp/1057522377634683.png
The version of ImageMagick running on GCF is:
convert -version: Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-07-15
http://www.imagemagick.org Copyright: Copyright (C) 1999-2014
ImageMagick Studio LLC Features: DPC Modules OpenMP Delegates: bzlib
cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma
openexr pangocairo png rsvg tiff wmf x xml zlib
I have the same version of Imagemagick on my local machine, but cannot reproduce the text corruption. I suspect it could be with the compile version that's live on Google (note the 2017-7-15 compile date)
I'm hoping someone has run into this in the past and knows what an easy fix is - is it an issue with supplying RGBA values, .png output type, etc.
The issue was with the -stoke option without a -strokewidth being set - also I'm not 100% sure whether or not label supports those or not, I'll have to test later. But my solution was to remove the -stroke from the command and the font characters stopped being corrupt.

ImageMagick script to resize folder of images

I have a folder of images of varying sizes and quality. Is there a way with ImageMagic that I could automatically resize them to be no bigger 1100px x 1100px and less than 160kb. And not to re-size if they are smaller than those parameters. Also not to distort the image so it fits within but to only re-size so for example an image which is 2200px by 1000px would become 1100px by 500px.
I'm working on Ubuntu with ImageMagick 6.7.7-10.
Try this on a copy of your files:
mogrify -define jpeg:extent=160k -resize 1100x1100\> *.jpg
I am assuming your files are JPEG images. The command will largely work for other image types too, but it can only enforce the 160kB limit for JPEG files - not PNG, or TIFF etc.
Example
With version: ImageMagick 6.9.1-10 Q16 x86_64 2015-08-06
convert -size 2000x2000 xc:gray +noise random a.jpg
ls -lrt a.jpg
-rw-r--r-- 1 mark staff 6969601 21 Aug 18:28 a.jpg # <--- 7MB
mogrify -define jpeg:extent=160k -resize 1100x1100\> a.jpg
ls -lrt a.jpg
-rw-r--r-- 1 mark staff 147938 21 Aug 18:28 a.jpg # <--- 160kB
identify a.jpg
a.jpg JPEG 1100x1100 1100x1100+0+0 8-bit sRGB 148KB 0.000u 0:00.000

ImageMagick error: no decode delegate

I'm trying to convert an image with imagemagick, but I'm getting this error:
convert: no decode delegate for this image format
`/tmp/magick-XXITXcTr' # constitute.c/ReadImage/503.
I'm doing this:
convert http://images.icecat.biz/img/norm/high/12003462-2669.jpg -bordercolor white -border 1x1 -matte -fill none -fuzz 7% -draw 'matte 1,1 floodfill' -shave 1x1 /myimagefolder/iphone.png
I have the following delegates:
DELEGATES bzlib fontconfig freetype gs jpeg jng jp2 lcms openexr
png rsvg tiff x11 xml wmf zlib
Anyone knows what the problem is?
This is happening because the image you are trying to download no longer exists and returns a 404. ImageMagick creates a temporary file before it downloads the image. But this file will remain empty because the download fails for this image. ImageMagick will try to read the image but fails because it cannot handle empty files.

PDF to JPG/PNG wrong dimensions in Rails

When i'm running convert via command line
convert -verbose -density 300 -trim -quality 100 1565_002.pdf test_image.png
the result is good. Verbose showing output:
"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r400x400" "-sOutputFile=/var/tmp/magick-39357qEey9jeURtmJ%d" "-f/var/tmp/magick-39357DTf85TEO2pfX" "-f/var/tmp/magick-39357aIeGxsC4sZlD"
/var/tmp/magick-39357qEey9jeURtmJ1 PNG 3400x4400 3400x4400+0+0 8-bit sRGB 144KB 0.300u 0:00.289
1565_002.pdf PNG 3400x4400 3400x4400+0+0 16-bit sRGB 144KB 0.000u 0:00.000
1565_002.pdf=>test_image.png PNG 3400x4400=>2778x3582 3400x4400+311+233 8-bit sRGB 2c 39.4KB 0.410u 0:00.420
BUT when uploading pdf via rails
has_attached_file :photo,
# ...storage options...
:styles => { :pdf_thumbnail => ["", :png] },
:convert_options => {
:all => '-auto-orient',
:pdf_thumbnail => "-verbose -density 300 -trim -quality 100"
}
The result is VERY poor.
Rails (paperclip) + Verbose output:
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey.pdf[0]'
Command :: convert '/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey.pdf[0]' -auto-orient -verbose -density 300 -trim -quality 100 -auto-orient '/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey20150206-39272-1qf97j3.png'
/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey.pdf[0]=>/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey20150206-39272-1qf97j3.png PNG 612x792=>500x645 612x792+56+42 8-bit sRGB 2c 4.06KB 0.010u 0:00.020
The problem is here - "PNG 612x792=>500x645 612x792+56+42" instead of "PNG 3400x4400 3400x4400+0+0".
So how this could be fixed? Or what option should i add.
I'm using rails (4.0.2), paperclip (3.5.2), rmagick (2.13.4)
Finally, i tried these solution - https://gist.github.com/bastien/3059321
There additional ghostscript setup which transform pdf with more deeper pixel per inch value (originally was r144 and i've changed it to r400) and other custom options.

Resources