3

I got an EPS file (3854x8000) and I want to scale it down, because this is way to big, but without losing the clipping path. (If it is possible -- I tried to scale it down by using ImageMagick:

convert picture.eps -resize 768x1024 picture_small.eps

The result is edgily. Until now I haven't tried to keep the clipping path, because I don't know how.

Until now if haven't found any solution for this problem.

Can ImageMagick actually do this?

Clarification:

(edit by Alex - as I am a collague of mht working on the same issue)

EPS files - as well as JPGs can contain a clipping path (German: Freistellungspfad). This is a vector path usually around a raster image that specifies which part of the background should be clipped. Using ImageMagick the clipping path is shown in the output of identify -verbose like this:

   Clipping path: 
<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="240" height="240">
<g>
<path style="fill:#00000000;stroke:#00000000;stroke-width:0;stroke-antialiasing:false" d="
M 53,133
L 126,63
L 151,163
"/>
</g>
</svg>

Download Test Image

Tried so far:

/opt/ghostscript-9.15-linux-x86_64/gs-915-linux_x86_64
  -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT 
  -dMaxBitmap=500000000  
  -r144 -sDEVICE=eps2write 
  -sOUTPUTFILE=out.eps 
  dreieck_rgb_pfad2_photoshop.eps

and:

convert dreieck_rgb_pfad2_photoshop.eps -clip eps3:out.eps
Alex
  • 32,506
  • 16
  • 106
  • 171
mht
  • 103
  • 1
  • 7
  • What do you mean by *"keep the clipping path"*? Are you talking about the *BoundingBox*, or what? – Kurt Pfeifle Feb 25 '15 at 19:46
  • Basically clipping paths are preserved in ImageMagick using the -clip option - anyways, this seems not to work http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=27222&sid=45c8c0c3e5eaaae99c720946fa1e3732 – Alex Mar 24 '15 at 13:32
  • @Alex: It would be more than helpful if you could add a (link to a) sample EPS file that shows the behaviour you are describing. – Kurt Pfeifle Mar 24 '15 at 18:02
  • @Alex: Your "Clarification" does not contain any EPS or PostScript in the code example you added. It looks more like SVG! Hence, it does not bear any relevance to the OP (which was created by someone called "@mht", not(!) you, asking about an EPS problem). -- Please ask a new question under your own name, and also add a sample file that can be used to analyse the problem you are seeing, and to test any suggested solutions. – Kurt Pfeifle Mar 24 '15 at 18:04
  • mht is a colleague of mine. And what you see here is the output of ImageMagick's identify. It displays the clipping path as SVG even the input is a JPG or EPS. – Alex Mar 25 '15 at 10:35
  • I have added a sample file. – Alex Mar 25 '15 at 10:55
  • @Alex: You cannot expect any arbitrary StackOverflow user to recognize as a fact that `mht` is a colleague of yours. And even if, it is confusing if you add unrelated information to an existing question. It is always better and desirable to post new questions in such cases... – Kurt Pfeifle Mar 25 '15 at 13:21
  • Sure, did not offend you. And I meant to clarify the question which I think I did - because you asked what is meant by the clipping path. – Alex Mar 26 '15 at 11:25

2 Answers2

2

Try setting the density before reading the file like this:

convert -density 300 picture.eps -resize 768x1024 picture_small.eps
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • My answer is not the best... I wasn't thinking about the fact that your output file is `eps` and you may want it to preserve vectors. Please see @KurtPfeifle 's answer for a proper explanation. – Mark Setchell Feb 25 '15 at 20:30
  • This does not preserve the clipping path. – Alex Mar 25 '15 at 10:57
2

You didn't say why your EPS is 'too big'. Is it the dimensions only, or is it the file size too?


To decide over the best method for scaling down an EPS file one would have to know what the exact nature of the contained PostScript code is.

EPS can contain 2 different types of graphical elements rendered on a page:

  1. Vector-based elements (including Fonts to display text)
  2. Raster-based elements (a.k.a. "pixel images")

Some EPS are based on purely one of these two types of content, some contain a mix between both.

If you are sure that your EPS is purely raster data, the the ImageMagick conversion does no harm.

But be aware: ImageMagick cannot handle EPS (nor PostScript or PDF) directly itself. It calls an external 'delegate' to process these input types. This delegate is Ghostscript.

Ghostscript then converts the EPS (or PS or PDF) input into big raster image, covering the complete page (or multiple images for multiple pages if input was PostScript or PDF with more than 1 page).

After this: gone are your vector data and fonts!

Then ImageMagick takes the raster images which Ghostscript created and applies its own processing to it: down-sampling, colorizing, etc. -- whatever you requested via the ImageMagick command line.

If you want again EPS as the output, ImageMagick is not able to re-create vector shapes. Everything inside the EPS now will be pixelated, including fonts. The EPS will just be a small, thin PostScript wrapper around a full-page raster image.

With ImageMagick you could end up in the worst case with

  • a file that is much larger in file size than the purely vector-original,
  • that has degraded in quality and lost all vectors and fonts at the same time because of the pixelization.

Hence it may offer several advantages to run Ghostscript yourself, not relying on ImageMagick:

  • You have more command line parameters available to fine-tune the output. (ImageMagick at this stage only knows about the resolution request to pass to Ghostscript, using -density NNN.)

  • You could pick a different output format, depending what your final purpose is for the output EPS you want to create from the initial EPS. Maybe it should go into a Word or LaTeX or Libre/OpenOffice document as an illustration? Want to simply print it? Want to convert it into a PNG or JPEG?

    • You could even ask for EPS again (running it with the parameter -sDEVICE=eps2write with recent releases). This can preserve (most) of the vector elements, including fonts, from the original file into the output EPS.
    • You can ask for PDF output (running with -sDEVICE=pdfwrite). This also preserves vectors and fonts. And it can be used to include into LaTeX documents directly (no need to convert to image first).

So it all depends on the final purpose of your conversion, how to do it in the most appropriate way. I could give you more specific Ghostscript command line recommendations, would I know your goal.


Update:

After quickly the newly provided sample EPS (see "Clarification" section of OP), I can state the following:

  1. The so called "EPS" file was created using Adobe Photoshop
  2. It is composed of various chunks:
    • An unidentifiable chunk of garbage bytes at the beginning (64400 Bytes)
    • A real EPS file, starting after byte offset 64400, composed of:
      1. a 13 line PostScript header
      2. 156 lines containing a smaller, embedded preview image (4874 Bytes)
      3. 100 lines containing a hex-encoded ICC Profile (6749 Bytes)
      4. ca. 300 lines of XML metadata by Photoshop (18746 Bytes)
      5. ca. 7200 lines of image raster data, most likely TIFF (475213 Bytes)

It looks like all attempts by the OP poster (as well as by the hijacker of the question) to convert this not-quite-so-standard EPS file to another image format (or to a "smaller" EPS) was failing, because the respective process used the embedded 240x240 pixels preview image instead of the embedded main TIFF.

In any case, it looks like the creators of this so-called EPS file should be booking a 'Photoshop and Graphic Formats training course' or similar.

Because if you create an EPS file with a simple black triangle composed of vector paths (which can be described and preserved in less than 20 lines of code containing less than 200 Bytes!) and then save it as a 500+ kB TIFF to wrap that into an EPS again, you're doing it wrong...


Update 2:

I asked a friend who has access to an Adobe Photoshop CC installation to open the file, to zoom into the triangle, to screenshoot what he sees and to send the shot to me. He did. The zoom level was 500%.

Here it is:

Screenshot at 500%

As you can clearly see, even Photoshop's original file is "edgily". And in no way is it 3854x8000 pixels, as the first sentence of the OP states.

If the EPS does not really contain a vector representation of the triangle illustration, there will be no way to avoid that "edgily" outcome when scaling it...


Update 3:

Just to proof my point, that you can have a vector based EPS file in a few dozen lines and a few hundred Bytes, here it is:

%!PS-Adobe-3.0 EPSF-3.0
%%Creator: Kurt Pfeifle (manually)
%%CreationDate: Wed Mar 25, 2015 (16:30 h)
%%Pages: 1
%%DocumentData: Clean7Bit
%%LanguageLevel: 2
% %%BoundingBox: 42 61 121 142
%%BoundingBox: 0  0  240 240
%%EndComments
%%BeginProlog
%%EndProlog
%%BeginSetup
%%EndSetup
%%Page: 1 1
%%BeginPageSetup
%%EndPageSetup
gsave
    42 61 79 81 rectclip
    gsave
        0             setgray
         42.4  85.6   moveto
        100.8 141.6   lineto
        120.8  61.6   lineto
        closepath
         42.4  85.6   moveto
        eofill
    grestore
grestore
showpage
%EOF 

(You can easily comment in/out two alternative lines of %%BoundingBox: settings...)

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345