Working with Sparse Bundle images:
To compact (image size will not be modified):
osx@osx$ hdiutil compact image.sparsebundle
To resize the image:
osx@osx$ hdiutil resize -size 30g image.sparsebundle
If you want to know more:
osx@osx$ hdiutil compact -help
osx@osx$ hdiutil resize -help