Page 1 of 1

fast batch converting of .eps to jpg

Posted: 2013-05-14T18:09:19-07:00
by kennethmad
First of, i am aware of the fact that jpg is not an ideal format for converting from vector but so far it has been the fastest and i have 200 000 eps files to resize.

I am running ImageMagick 6.8.4-10 2013-04-23 Q8 on Ubuntu 12.04 64 bit:

This is the command i use for converting 1 eps file to several jpeg files in different formats, ive currently just been running it as a command line argument in some php code:

Code: Select all

convert -density $density -colorspace sRGB -filter Quadratic $orgFilePath -colorspace sRGB -strip -background white -flatten \
'(' +clone -resize 5000x5000 -write rz_5000x5000/$thumbPath ')' \
'(' +clone -resize 1600x1600 -write rz_1600x1600/$thumbPath ')' \
'(' +clone -resize 1210x1210 -write rz_1210x1210/$thumbPath ')' \
'(' +clone -resize 600x600 -write rz_600x600/$thumbPath ')' \
'(' +clone -resize 512x512 -write rz_512x512/$thumbPath ')' \
'(' +clone -resize 500x500 -write rz_500x500/$thumbPath ')' \
'(' +clone -resize 200x200 -write rz_200x200/$thumbPath ')' -delete 0-6 -resize 128x128 rz_128x128/$thumbPath
For calculating density i have been using 2 different methods:
1: Using a pre-set value such as 600.

2: getting density by making imagemagick return me the size of the vector and from that calculate the needed density with something like this:
wantedDensity = round(5000*72/$max)
I also check that density is not above 1000 or below 500.

The problem: When running the above command i usually end up with an average time of 6 - 8 seconds per image but for some reason that i can't figure out i get up towards 400 seconds on every 40- 50 image i'm trying to convert. Not sure if i am doing something wrong or the files themselves are hard to convert for some reason.

All the images in this folder are the slow ones with times up to 400 seconds:

https://www.dropbox.com/sh/x7xdnhlwoy2imyf/aMksJNUorw

While the images in this folder usually go pretty fast with an average time below 15 seconds:

https://www.dropbox.com/sh/l3uzuqa0eu448nx/g5zun-XMx6

Re: fast batch converting of .eps to jpg

Posted: 2013-05-14T18:45:20-07:00
by fmw42
From looking at 2.eps using identify -verbose 2.eps


Image: 2.eps
Format: EPT (Encapsulated PostScript with TIFF preview)
Class: DirectClass
Geometry: 3671x5523+0+0
Resolution: 72x72



You have a rather large WxH if you set your density to 72. If you change your density to higher values, the resulting image will be even larger in pixels. You should make your density such that the largest image dimensions you want to save comes right from that density rather than compute some density that will make the image larger and thus need to resize it substantially to get your largest image.

Re: fast batch converting of .eps to jpg

Posted: 2013-05-14T22:13:32-07:00
by snibgo
I would do the sequential resizing a different way.

With your command, you create a version that is 5000x5000. Then you resize that to 1600x1600. Then you resize that to 1210x1210, and so on. You keep all these versions in memory until the "-delete 0-6" near the end.

You might get noticably better quality, and will use less memory, if you resize each image from the original (use "-clone 0") and delete it from the image list as you go (use "+delete").

Code: Select all

{blah blah}
'(' -clone 0 -resize 5000x5000 -write rz_5000x5000/$thumbPath +delete ')' \
'(' -clone 0 -resize 1600x1600 -write rz_1600x1600/$thumbPath +delete ')' \
'(' -clone 0 -resize 1210x1210 -write rz_1210x1210/$thumbPath +delete ')' \
{blah blah}

Re: fast batch converting of .eps to jpg

Posted: 2013-05-15T07:18:59-07:00
by kennethmad
Ok thanks for helping,

I think i figured out the problem:

For some reason i had set a min and max image density for when i calculate density, removing the max and min seems to have helped with conversion times.

I still have a few slow ones such as 40 and 90 seconds but im not sure if thats expected

Here is the current code i use for calculating density in php:

Code: Select all

function getImageDensity ($path) {
  $wantedDensity = 500;
  $defaultDPI = 72;
  $convertCmd = 'identify -format "%w x %h" ' .  $path;
  $max = 0;

  exec($convertCmd.' 2>&1', $output);
  $output =  explode("x", $output[0]);
  $width = $output[0];
  $height = $output[1];

  if($width > $height) {
    $max = $width;
  } else {
    $max = $height;
  }

  if ($max > 0) {
    $wantedDensity = round(5000*$defaultDPI/$max);
  }

  return $wantedDensity;
}
unless of course i totally misunderstood what was said.

and thank you for suggesting that i regenerate everything from the input, it seems to help a bit with the quality.