The quickest way:
hdiutil create -srcfolder "Source Folder" "File to Output.dmg"
Note that it uses “Source Folder” as the root of the DMG; you may want to put “Source Folder” into an empty, similarly-named folder and compress that instead.
Also check out EasyDMG, a Cocoa wrapper for hdiutil.