Planetary Nebulae
Something that needs to be prefaced is that planetary nebulae actually have nothing to physically do with planets. The reason for their name is because early astronomers who discovered them thought that they were planets.
When stars with masses from 1-8 solar masses die out, they usually turn into planetary nebulae. On an astronomical scale, nebulae live very short lives, on the ranges of a few millennia. There is no truly definite shape for nebulae as there are plenty of nebulae out there that have deformed shapes.
They form from the dissipated UV radiation given off by the atmospheres of red giant stars at the end of their lifetimes. The UV rays congregate into a P.N.N(Planetary Nebula Nucleus) which is extremely hot. This nucleus heats up the rest of the ejected elements and ionizes them into a hot gas with a rapid expansion rate. This is why many of the nebulae observed(like the ones in the slideshow above) are so colorful and somewhat deformed.
Citations/Attributions
Planetary nebula. Provided by: Wikipedia. Located at: https://en.wikipedia.org/wiki/Planetary_nebula. License: CC BY-SA: Attribution-ShareAlike