0

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

  • 1
    If you can't find a command line solution, I would personally get a batch image compressor application and shrink them all off your pc and reupload – Michael d Feb 27 '18 at 18:29
  • You were kinda stuck. I would normally have made ftp backups of the files, take one copy, and used thumbnailer to manage the file sizes. Thumbnailer is inexpensive and better than anything I have ever used. Once verified the work was correct, I would have deleted the originals and uploaded the new. I am glad you found a solution. Cheers!! – closetnoc Feb 28 '18 at 4:00
  • Maybe not the best solution but I would use a php script to resize and possibly do a little compression. Your script can be run from the command line using 'php myscript.php'. php.net/manual/en/ref.image.php – DraganAscii Jun 14 '18 at 18:22
1

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 http://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.
  • Thanks! I'll check out tinypng, that sounds good. I should have said this earlier but they're all JPGs, but it looks like tinypng works with jpgs too. – Dan Mantyla Feb 27 '18 at 19:12
  • 1
    Yes. They do and actually → tinyjpg.com is the same thing – George Feb 28 '18 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.