: Shrinking image sizes from the server command line? I have a directory with 22,902 images. Average size is 2.237 megabytes. I know this because I used ls -l | awk '{ total += ; count++
I have a directory with 22,902 images.
Average size is 2.237 megabytes. I know this because I used ls -l | awk '{ total += ; 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 } {print }' | 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
More posts by @Candy875
1 Comments
Sorted by latest first Latest Oldest Best
I don't believe this question is really related to "webmasters". But there are aspects influencing SEO.
The easiest thing you can do is apply for a free plan at tinypng.com/ and optimize the biggest images using one of their libraries from command line.
Next you could scrub your DB for all the references to the images and coem up with the list of not used ones.
And finally you could put them all (or partially) to let's say imgur. How this impacts SEO? I'm not sure. Should not be any bad.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.