I have a directory with 22,902 images.
Average size is 2.237 megabytes. I know this because I used ls -l | awk '{ total += $5; count++ } END { print total/count }'
to get the average file size.
This adds up to mean that there's about 50 gigabytes of images in this one directory. The problem is that I'm on a shared hosting environment (hostgator) and my site is just getting too big. Right now I'm even struggling to make a full site backup!
The largest one is 21 megabytes and there are five that are over 15 megabytes. Most though are a few megabytes each.
What can I do????
I don't think we need ALL of these images. Maybe I can delete all the oldest ones? What these images are, they're for NPR articles that we host. We use the NPR module for Drupal that lets us Pull stories from the NPR API. And there's several dozen stories automatically pulled a day.
What do you think? Thanks!
EDIT:
There's
- 22,278 .jpg files
- 546 .png files
- 320 .bin files ???
ImageMagick is installed on the server, thankfully.
Here's a command I tested with some of the images:
convert -strip -interlace Plane -quality 50% -verbose x.jpg x.jpg
It made the largest jpg photo - 21 MGs - a 2.2 MG file. And it make a 46 KB jpg photo only 21 KBs.
But that's for JPEGs. It made a PNG bigger! It converted a 6.8 MB png to 8.5 MBs.
So, this is the command I came up with:
ls -1 | grep '.jpg' | awk '{print $1} {print $1}' | xargs -t -n2 convert -strip -interlace Plane -quality 60%
and forget about the .png images and whatever the .bin files are
It will take a loooooooong time to complete