You may want to look at http://contentdeveloper.com/2010/01/how-to-customize-qr-codes-with-your-brands-identity/ (there were some other articles I read just a couple nights ago, but I can't find them, though this should work as well)...also, something I read suggested using the highest error correction level. This way, more of the data in the barcode is merely error-correction data. You can overwrite this with no worries, as long as you realize that if the rest of the barcode gets damaged, you may not be able to recover the data.
Unfortunately, it's just going to involve a bunch of trial and error.
Good luck!
EDIT: Sorry, I just read that you wanted it generated automatically rather than editing the image.