51

I have a .eps file that I can look at in Photoshop, and it has a very high resolution, sharp edges, etc. at even larger than 1024x1024.

With ImageMagick I want to convert this .eps to a 1024x1024 .jpg with very high resolution.

However, with the following command, the image is very blurry:

convert -resize "1024x1024" -colorspace RGB -flatten test.eps test.jpg 

What ImageMagick parameters do I have to use so that the resulting .jpg is 1024x1024 and a high quality, sharp image?

here's some XMP data we found, perhaps what is causing it to not be resized with -size:

enter image description here

Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
  • 7
    since JPG uses the DCT-transformation its intended for natural-images, i.e. photos. It is not suited for images with sharp edges. Use png-instead. Just a thought... – Fredrik Pihl Sep 28 '11 at 13:17
  • the command `convert -resize "1024x1024" -colorspace RGB -flatten test.eps test.png` still produces a blurry .png file, I need to increase the dpi I would think but can't get the right parameter setting – Edward Tanguay Sep 28 '11 at 13:22
  • try using `-filter` as described [here](http://www.imagemagick.org/script/command-line-options.php?ImageMagick=l4s55sb18gpqvae2pfd820a1g4#filter) to change the resize method used to something more appropriate – Fredrik Pihl Sep 28 '11 at 13:26
  • couldn't find any filter setting that would work, e.g. `convert -resize "1024x1024" -colorspace RGB -flatten -define filter:blur=.4 test.eps test.jpg` doesn't make it any sharper but turns it into little squares – Edward Tanguay Sep 28 '11 at 13:38
  • well, blur with an radius of .4 is perhaps not the best filter suitable for resize :-) – Fredrik Pihl Sep 28 '11 at 14:03

2 Answers2

92

For vector graphics, ImageMagick has both a render resolution and an output size that are independent of each other.

Try something like

convert -density 300 image.eps -resize 1024x1024 image.jpg

Which will render your eps at 300dpi. If 300 * width > 1024, then it will be sharp. If you render it too high though, you waste a lot of memory drawing a really high-res graphic only to down sample it again. I don't currently know of a good way to render it at the "right" resolution in one IM command.

The order of the arguments matters! The -density X argument needs to go before image.eps because you want to affect the resolution that the input file is rendered at.

This is not super obvious in the manpage for convert, but is hinted at:

SYNOPSIS

convert [input-option] input-file [output-option] output-file

erjiang
  • 44,417
  • 10
  • 64
  • 100
  • 3
    thanks, that did it, actually the best resolution result is when density=resize, e.g.: `convert -density 1024x1024 -resize 1024x1024 test.eps test.jpg` – Edward Tanguay Sep 28 '11 at 14:41
  • 2
    No, I don't believe that does what you think it does. It renders your image at 1024dpi, and then downsamples it to 1024x1024px. For example, a 4x4in EPS would become 4096x4096px in memory, and then resized to 1024x1024px. – erjiang Sep 28 '11 at 15:59
  • 30
    When I was googling, I found this stackoverflow answer just after/below a different one that had the right answer and a key nugget. It's key point was to make sure the -density flag (I used "-density 400%") appears before the input file name. In my original setup, I was sandwiching all the flags between the input file name and the output file name, and -density has no effect in that case (leading to a blurry text font image). So readers should make sure that -density appears _before_ both test.eps and test.jpg. [A common case for me was converting pdf to png.] – Jose_X Oct 18 '11 at 20:09
  • 3
    Jose_X you are the only one to have solved my problem after hours and hours of searching. Putting the density BEFORE the source was the answer. THANK YOU – Sean Clark Jan 09 '13 at 06:03
0

Maybe you should try it with -quality 100 -size "1024x1024", because resize often gives results that are ugly to view.

Stephan
  • 327
  • 3
  • 11
  • 1
    hmm, `convert -colorspace RGB -flatten -quality 100 -size "1024x1024" test.eps test.jpg` creates a .jpg with a size of 100x41, why would that be? – Edward Tanguay Sep 28 '11 at 13:36
  • Have you tried it without the quotation marks? Otherwise I won't get, where the problem is – Stephan Sep 28 '11 at 13:45
  • Yes, I tried it without quotes with same result, a colleague mentioned that the "XMP information define the thumbnail as a smaller size", perhaps I need to override that somehow? – Edward Tanguay Sep 28 '11 at 13:50
  • I posted the XMP data above, strange that it states height=104, width=256 but it creates a test.jpg with height=100, width=41. – Edward Tanguay Sep 28 '11 at 13:56
  • the command `convert -colorspace RGB -flatten -quality 100 -size "1024x1024" test.eps test.png` also produces a 100x41 image – Edward Tanguay Sep 28 '11 at 13:58
  • Other thing I know is to use `-resize 1024x1024\!` that should ignore the ratios. – Stephan Sep 28 '11 at 13:59
  • the commands `convert -quality 100 -size 1024x1024 test.eps test.png` and `convert -size 1024x1024 test.eps test.png` crash ImageMagick, "ImageMagick has encountered a problem" – Edward Tanguay Sep 28 '11 at 14:02
  • Have you tried it with the "\!" addition & -resize instead of size (just due to the \!) – Stephan Sep 28 '11 at 14:05
  • the command `convert -quality 100 -size 1024x1024\! test.eps test.png and convert -size 1024x1024 test.eps test.png` gives me an invalid argument for -resize error – Edward Tanguay Sep 28 '11 at 14:08
  • Yeah. As I said you have to use -resize in this case instead of -size – Stephan Sep 28 '11 at 14:11
  • the command `convert -quality 100 -resize 1024x1024\! test.eps test.png and convert -size 1024x1024 test.eps test.jpg` also gives me the invalid argument error – Edward Tanguay Sep 28 '11 at 14:15
  • Hm then I have no idea, just a link, which could help you: http://www.imagemagick.org/Usage/resize/ – Stephan Sep 28 '11 at 14:20
  • the command `convert -colorspace RGB -density 1024x1024 test.eps test.jpg` causes ImageMagick to crash. – Edward Tanguay Sep 28 '11 at 14:20