Convert pictures for upload to Google+

Google plus allows you to upload pictures without using your disk quota with Google if your images are up to 2048×2048 they will not be counted towards your disk space. So if you don’t need to back up your full size pictures you can use this script to convert them to the max size google accept without taxing your storage. The script is intended to run as a bash script and has been tested in several versions of Linux. It should work well also under Cygwin in Windows and in BSD et cetera.

You need to install imagemagick in order to use the script. It relies on the ”convert” binary in that package.


#!/bin/bash

# Find out if the destination dir already exists
# and if it does not, then we need to create it.

if [ ! -d "google" ]; then
echo "Creating dump dir google."
mkdir google
fi

# Save the internal file separator symbol and then replace it
# with UNIX line breaks so that we can handle file names that
# have spaces and stuff in them.

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

# Loop over all files in current directory and then process them
# one by one storing the result in the "google" folder ready for
# upload to Google when done.

for f in * ; do
echo -n "Processing $f - "
if [ -f "google/$f" ]; then
echo "Exists, skipping."
else
echo -n "Converting - "

# Sharpen a bit to make it more enjoyable on small images
# convert image to 2048 pixels maximum side. This means
# we are able to store all files the way google allows us
# for free (not having to buy more space)

convert "$f" -filter bessel -resize 2048 -sharpen 0x1.0 "google/$f"
echo "Done."
fi
done

When the script is run it will create a subfolder named ”google” in case it does not already exist. Then it will loop over all your files in the dir trying to run the convert script on each of them. It takes a few seconds per file generally. It allso applies some sharpening which usually works well but if you don’t want that then remove that argument.

Save the script in /usr/bin/google-convert or something similar and then just cd to the folder where your jpegs are located and run the script there.