**Update**
I have now built a script to do this automatically.
The script will minimise the size as much as possible.
Script can be found here

I recently had to resize a Raspbian Server Edition image into a 1 gigabyte image. As I didn’t actually have a 1 gigabyte SD card to use as a template, I generated my own by resizing the original 2 gigabyte image.

This was done on another computer, but this can also be done on the Pi itself, and you can even flash the resulting image to an SD card if you have a USB SD Card reader on the Pi.

Also, most commands will need to be run as root, or use sudo to run the commands.

Step 1 : Mounting the image

First thing I did was make a copy of the 2gb image to work on, this is not essential if you downloaded the image originally, but I’m working on the original RSE image.
# cp RSEv2.3.img RSE1g.img

Similar to part 1, we need to mount the image via loopback.
# losetup -f --show RSE1g.img

This will mount the image file as a loopback device, and show you which one it was mounted as. By default, it should be /dev/loop0

Step 2: Resizing the Partition

Once the image is mounted, we then need to run parted on the image file, and get it to print out the current partitions.
# parted /dev/loop0
GNU Parted 2.3
Using /dev/loop0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

As you can see, the 2nd partition, which is the linux partition, is 1877 megabytes. To resize the partition, we need to remove it, and recreate it with a new size.

Running the command rm 2 will remove the 2nd partition.
(parted) rm 2

To recreate it, we need to use mkpart command, and specify that we will be creating it as a primary partition, starts at 62.9MB, and ends at 900MB to give us a partition of 837 MB.
(parted) mkpart primary 62.9 900

Once the partition has been created, running print again will show us the new setup.
(parted) print
Model: Loopback device (loop)
Disk /dev/loop0: 2003MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

We will also need to get the amount of sectors in the new partition so we can resize the filesystem to the right size later. To do that, we change the units to sectors, and then run the print command again
(parted) unit s

Now when we run the print command, the partitions will show up with sectors as the units instead
(parted) print
Model: Loopback device (loop)
Disk /dev/loop0: 3911680s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Once the filesystem has been verified as clean, we can then use resize2fs to resize the filesystem.
We will need to calculate the size of the new filesystem to resize it correctly. To do that, we need to take the size of the partition in sectors (1634304), and divide by 8 (4KB blocks divided by 512 bytes/sector), assuming we are using 4KB blocks in the filesystem.
# echo '1634304 / 8' | bc
204288

We can use resize2fs now to resize the filesystem to the correct size.
# resize2fs /dev/loop1 204288
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/loop1 to 204288 (4k) blocks.
The filesystem on /dev/loop1 is now 204288 blocks long.

Once the resize is done, we can now remove all loopback devices
# losetup -d /dev/loop0 /dev/loop1

Step 4: Resize the image file

Once the resize is all completed, we just need to lop off the end of the image file that has all the free space.
Since the 2nd partition ends at the 900MB mark, we can lop it off right there with the truncate command
# truncate -s 900M RSE1g.img

The filesize will now be 900 Megabytes which is small enough to fit onto any 1GB SD Card.