Download and install Carbon Copy Cloner from here.
Launch the Carbon Copy Cloner from your Applications folder.
Click to select a Source drive to backup. We selected our Macintosh SSD.
Click to select a Destination and choose New disk image....
Navigate to the location you'd like the disk image to be saved and give it a name in the Save As field.
If you want a disk image that you can modify, choose read/write sparse disk image from the Image Format dropdown. This creates a .sparseimage file. Alternatively, you can create a read only .dmg image. This process takes longer and you cannot modify the final image. However, it's a widely used file format.
Finally, you may also choose to encrypt your disk image. This has obvious security benefits but again will take longer to complete.
Once you're happy with your selections, click OK.
Click the Clone button to begin the backup process.
You may be warned that it is difficult to boot off a disk image, click Continue Anyway.
After a few hours (depending on the amount of data you have on your drive), the disk image will have been created.