hdiutil create -verbose -srcfolder "path to files to image" -nospotlight -format UDZO "path to temp image"
This creates a disk image which is compressed and doesn't have a spotlight index.
Next you need to run
prinf password| hdituil segment -o "path to final image" -segmentSize 1g -encryption AES-256 -stdinpass "path to tmp image"This will segment the image with a maximum size of 1GB per segment and encrypt it using AES-256 the
printf passwordsets the password to "password"