admin管理员组文章数量:1122826
I'm using Ghostscript to convert EPS images into PDF. We have EPS images with embedded pixel images. The conversion leaves these images at their original resolution, but it adds compression artifacts.
These are the parameters I use with Ghostscript:
-q -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dEPSCrop -dCompatibilityLevel=1.4 -dAutoRotatePages=/None -dDownsampleColorImages=false -dDownsampleGrayImages=false -dDownsampleMonoImages=false -dCompressPages=false -ddCompressEntireFile=false
Adding -dDownsampleColorImages=false
made no difference.
Adding -dPDFSETTINGS="/printer"
gives a small improvement.
I checked the various dPDFSETTINGS. -dPDFSETTINGS="/default"
should be the best: it has set all downsampling options to false. But rendering the PDF with this option still gives me compression artefacts.
This is the list of options for -dPDFSETTINGS="/default"
. I don't see any settings for compressing images.
/AutoRotatePages /PageByPage
/CannotEmbedFontPolicy /Warning
/ColorACSImageDict << /QFactor 0.9 /Blend 1 /HSamples [2 1 1 2] /VSamples [2 1 1 2] >>
/ColorConversionStrategy /LeaveColorUnchanged
/CreateJobTicket false
/DoThumbnails false
/DownsampleColorImages false
/DownsampleGrayImages false
/DownsampleMonoImages false
/EmbedAllFonts true
/GrayACSImageDict << /QFactor 0.9 /Blend 1 /HSamples [2 1 1 2] /VSamples [2 1 1 2] >>
/NeverEmbed [/Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic /Symbol /ZapfDingbats]
/Optimize false
/PreserveEPSInfo true
/PreserveOPIComments true
/PreserveOverprintSettings true
/UCRandBGInfo /Preserve
Is there a way to force Ghostscript to use lossless compression only?
I'm using Ghostscript to convert EPS images into PDF. We have EPS images with embedded pixel images. The conversion leaves these images at their original resolution, but it adds compression artifacts.
These are the parameters I use with Ghostscript:
-q -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dEPSCrop -dCompatibilityLevel=1.4 -dAutoRotatePages=/None -dDownsampleColorImages=false -dDownsampleGrayImages=false -dDownsampleMonoImages=false -dCompressPages=false -ddCompressEntireFile=false
Adding -dDownsampleColorImages=false
made no difference.
Adding -dPDFSETTINGS="/printer"
gives a small improvement.
I checked the various dPDFSETTINGS. -dPDFSETTINGS="/default"
should be the best: it has set all downsampling options to false. But rendering the PDF with this option still gives me compression artefacts.
This is the list of options for -dPDFSETTINGS="/default"
. I don't see any settings for compressing images.
/AutoRotatePages /PageByPage
/CannotEmbedFontPolicy /Warning
/ColorACSImageDict << /QFactor 0.9 /Blend 1 /HSamples [2 1 1 2] /VSamples [2 1 1 2] >>
/ColorConversionStrategy /LeaveColorUnchanged
/CreateJobTicket false
/DoThumbnails false
/DownsampleColorImages false
/DownsampleGrayImages false
/DownsampleMonoImages false
/EmbedAllFonts true
/GrayACSImageDict << /QFactor 0.9 /Blend 1 /HSamples [2 1 1 2] /VSamples [2 1 1 2] >>
/NeverEmbed [/Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic /Symbol /ZapfDingbats]
/Optimize false
/PreserveEPSInfo true
/PreserveOPIComments true
/PreserveOverprintSettings true
/UCRandBGInfo /Preserve
Is there a way to force Ghostscript to use lossless compression only?
Share Improve this question edited Nov 21, 2024 at 14:24 Hobbes asked Nov 21, 2024 at 11:24 HobbesHobbes 2,0833 gold badges20 silver badges39 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 1Apparently, GS will compress raster images using JPEG compression by default.
Compression can be disabled completely with the -dEncodeColorImages=false
switch.
But it's also possible to specify lossless compression: -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode
will compress the images using Flate encoding. This gave me the result I wanted.
-dColorImageFilter=/FlateEncode
needs the / before the setting.
If you don't want lossless compression, but higher-quality JPEG compression, you have to use Acrobat Distiller settings with the setdistillerparams
option.
This option has the syntax -c "<<... >> setdistillerparams"
This option must be placed after all other Ghostscript command line parameters except for the input file. Use the -f
switch to specify the input file. Insert the Distiller parameters you want to use between the <<
and >>
.
The option takes any Acrobat Distiller parameters as input. If you have Acrobat Distiller installed, find a *.joboptions
file for examples.
Some options are straightforward:
/LockDistillerParams false
/MaxSubsetPct 100
these can be inserted as you'd expect.
-c "<< /LockDistillerParams false /MaxSubsetPct 100 >> setdistillerparams"
Some options use a dictionary. In the .joboptions file these are split into multiple lines.
/ColorACSImageDict <<
/QFactor 0.15
/HSamples [1 1 1 1] /VSamples [1 1 1 1]
>>
You can paste the dictionary into the -c argument. Remove the returns.
-c "<</ColorACSImageDict << /QFactor 0.2 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>>> setdistillerparams"
Full command line:
"C:\Program Files\gs\gs9.52\bin\gswin64c.exe" -q -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dEPSCrop -dCompatibilityLevel=1.4 -sOutputFile=testfile.pdf -c "<</ColorACSImageDict << /QFactor 0.2 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>>> setdistillerparams" -f testfile.eps
本文标签: ghostscriptImages are compressed when they should not beStack Overflow
版权声明:本文标题:ghostscript - Images are compressed when they should not be - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311387a1934719.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
-dColorImageFilter=/FlateEncode
. I was using-dColorImageFilter=FlateEncode
which gives a misleading error message "use -sNAME= to define string constants" suggesting I should use-sNamedColorImageFilter=/FlateEncode
, which silently fails, using JPEG compression instead of Flate. – Hobbes Commented Nov 25, 2024 at 10:09"C:\Program Files\gs\gs9.52\bin\gswin64c.exe" -q -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dEPSCrop -dCompatibilityLevel=1.4 -sOutputFile=91434.pdf 91434.eps -c "<</ColorImageFilter /FlateEncode >> setdistillerparams"
creates a JPEG-compressed file while I expect a Flate-compressed file that is 3 times larger. – Hobbes Commented Dec 4, 2024 at 14:09