I had imaged a full 8GB SD card, but I only wanted to distribute a smaller image. These are a few notes:
Image the SD card
dd if=/dev/sdb of=./backup.img
Now I wanted to use gparted to resize the partition, you can run sudo gparted ./backup.img
and it will show the partitions, but it will think that the partitions are located at /dev/./backup.img1 and /dev/./backup.img2 which is not correct. The trick here is to use the loopback interface.
losetup /dev/loop0 backup.img
this will make the backup.img file show up as a block device. You can then run gparted on /dev/loop0 and once again see the partition table. There still is an issue though, it will look for the partitions to be located at /dev/loop0p1 and /dev/loop0p2, these block devices do not exist. It turns out that losetup has a flag that I have not noticed anywhere before -P this causes the kernel to read the partition table of the device and create the additional block device. This lets us avoid having to manually look at the partit