0

I have a huge directory of images on a CentOS server (~65gb). The images are predominantly jpeg's but theres some png's and a couple of gif's.

Here's the annoying and weird part - the images are all stored without extensions, with filenames such as z_1bC5f4. They've had an initial optimization by imagemagick but I need to reduce all their sizes. I'd like to install a CLI optimization tool but i'm not sure how I get round the lack of extension. I also need to run this on the production server without using all cpu and memory.

There's also the question of which tool to use - there's a lot out there, trimage looks good but doesn't appear to work on CentOS.

Any ideas?

robjmills
  • 990
  • 8
  • 24
  • Do you have a database that maps their filenames to their image type? How do you currently send the correct mimetype for each image if they could be one of 3 image types? You'd run the process (whatever it ends up being) nice 19 or something, so it'll not slow down your production server, and just use idle resources. – i-CONICA Apr 03 '14 at 12:22
  • we do have them mapped in a db yes. – robjmills Apr 03 '14 at 13:05

2 Answers2

2

Is there a reason you can't install ImageMagick? I'm assuming that's what you're looking at, since you have this question tagged as such - if so, my instinct would be to simply run something akin to:

pushd 
for f in *
do
  nice -n 19 convert -size 1024x1024 $f resize 1024x1024 $f
done
popd

That specific command will create images with a maximum dimesion of 1024 pixels, retaining the aspect ratio for each individual image. How you manipulate the size, and any calculations you add to determine size, is entirely up to you.

John
  • 8,920
  • 1
  • 28
  • 34
  • we have imagemagick installed and have used that already but i'm hoping to try something which is better at optimising as imagemagick isn't great at that element compared to things like imageoptim – robjmills Apr 03 '14 at 13:06
2

You can use the file command to determine what the extension should be

file -b --mime-type a
image/jpeg

file -b --mime-type c
image/gif

So it should be fairly straightforward to loop over the files - run the file command to determine the extension - run the utility to optimize them - do something else

To reduce the impact of the processing on your server use the nice command to reduce the cpu priority of the converter.

I can't help with a suitable utility I really have never had to do something like this.

ewwhite
  • 194,921
  • 91
  • 434
  • 799
user9517
  • 114,104
  • 20
  • 206
  • 289