Ponderings,  Pre-Travel

Image Size Management

For the first few months of our blog, we used to upload images in their native size, which is 4K. This is rather insane and I have now decided that it is not something we want to do for several reasons:

1. Upload & download bandwidth cost
2. Upload time
3. Readers really don’t need 4K images

The first step was to stop the madness. So, since late August we have been batch re-sizing our images using the Photo Editor app for Android. We copy the images we have selected to add to the blog into an upload/ folder. Then we batch process them to a maximum width or height of 1024 pixels, keeping their aspect ratio. This is the largest dimension WordPress saves in our case. Then we use a preset folder pair in the FolderSync app to push those images to an upload/ folder mirror on the server. From there, we can use the “add from server” plugin inside WordPress, which is set to import the upload/ folder on the server. This used to take a long time, and now we can upload and import 20+ images to a new blog post in less than five minutes!

This leaves the issue of some 550+ 4K images that remain on the server and are linked to from various places. WordPress automatically adds different sized copies of each image to year/month folders on the server. My solution was to delete the large original files, then copy and rename the largest copy of the same image in order not to break any links. To do this manually would have taken about a month and made me go insane. Instead, I wrote some PHP to list the files in question and was able to filter this list to see the naming conventions and differences between the file sizes. We used to upload 4:3 images, then 16:9, some are iPhone sized with different names, some have now been uploaded in the correct size and don’t need modifying. So after a bit of trial and error with my filter settings, I got the correct list. First step was to rename all original files with a precursor “old”, then copy and rename the largest version of the same files to the original name. After that, I simply deleted all the old originals. Once I had the correct list, this took less than 5 minutes using PHP.

If you find a broken image link, please let me now!

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *