Page 1 of 1

A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-01T21:48:48-07:00
by kjhttr
Hi everyone,

A smoothed-looking pdf file becomes a pixelated png file when I convert the pdf file using convert command.



I produced a .ps file, and I converted it into a pdf file using ghostscript command ps2pdf.

Although the original .grd file has coarse pixels, my plots in pdf and ps formats look smooth.

But when I converted the smoothed-looking pdf or ps files into a png file, it became pixelated with the same coarse pixels in my original .grd input.

Is there anyway to keep the same smoothness when I convert a pdf file into a png file?

Thanks in advance!

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-01T23:03:56-07:00
by fmw42
ImageMagick uses Ghostscript to process PDFs. But Ghostscript does not preserve vector information. It rasterizes it. That explains why that happens. Add -density 300 before reading the PDF and that should make it higher resolution.

______________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-02T05:56:07-07:00
by snibgo
As Fred says.

The "-density" number can be as large as you want, to make the rasterised image as smooth as you want (and also larger).

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-02T08:58:13-07:00
by kjhttr
Sorry for missing details.

Here is the version information.
Version: ImageMagick 7.0.8-9 Q16 x86_64 2018-08-04 https://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: https://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI
Delegates (built-in): bzlib freetype jng jpeg lcms png raw tiff webp xml zlib

I use MacOS X Mojave.

on the terminal I computed,

"convert -density 300 original_file.ps 3.png"

and "convert -density 300 original_file.pdf -density 300 2.png"

Do you know how to upload an image from my local machine? I wish I could attach one image. It didn't work
(look at the box with a question mark below)


Image

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-02T09:34:28-07:00
by fmw42
You must upload to some free hosting service and the put the URL here. If you post images, then post the originals also.

IM 7.0.8.9 is rather old. Currently at 7.0.8.36. Perhaps you should upgrade and test again.

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-02T12:41:42-07:00
by kjhttr
You can check the figures at the following URL : https://kjhttr.wixsite.com/kjhttr

Sorry for the bad quality. But at least you can see the difference between the pdf image and the png images.

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-02T13:39:10-07:00
by snibgo
The PNG samples show posterisation of the background colours. The commands you show above cannot cause that posterisation.

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-02T14:40:57-07:00
by fmw42
It would always be best if you post images separately so we can test with them.

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-02T15:51:24-07:00
by kjhttr
https://www.dropbox.com/sh/gaq5bpor1rcm ... dluEa?dl=0
---------------------------------------------------------------------------------------------------------

I uploaded an original postscript on a dropbox directory. I took a screen shot as well and uploaded it together.

Note that the png file is a screen shot I took in order to show you how this looks like.

You can download them at the URL provided above.



What I found so far is that the original ps file looks smooth if I use Preview.app in my Mac.

However, on the website, it is pixelated. If I download it and open it again, it looks smooth.

I used gs command to open it using a PC where Ubuntu is installed. It looks pixelated.

I generated the figure using Generic Mapping Tools. Because of one GMT command that I used, this plot is supposed to look smooth as I see it using

Preview.app.



If you think this problem is not related to magick convert, let me know then I will delete this thread.

Thank you a lot, snibgo and tmw42.

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-04-02T16:24:22-07:00
by fmw42
Using ImageMagick 6.9.10.36 or 7.0.8.36 and density 300 and Ghostscript 9.25, your image converts to png without issue and looks fine to me, no jagged edges as far as I can tell.

Code: Select all

convert -density 300 original.ps original.png
For IM 7, use magick only, not convert and not magick convert.

I suspect you may have an issue with Ghostscript. What is your version. If 9.26, downgrade, since that one seems to have some bugs. I believe that 9.23, 9.24, and 9.25 are likely fine.

Re: A smoothed-looking pdf file becomes a pixelated png file.

Posted: 2019-05-21T12:56:25-07:00
by kjhttr
Hi

It turned out that I had an issue when I generated the postscript file.
I regenerated it and converted it using

magick mogrify -format png -density 300 *.ps

and

convert -density 300 original.ps original.png

They both look great.

Thanks for helping me.