In Harry Potter and the Half Blood Prince, when Harry goes into the headmaster's/headmistresse's study with McGonagall, Dumbledore's portrait is already on the wall, how was it painted so quickly? Did someone paint it really fast or is it part of the magic of Hogwarts?
According to the "Howarts Portraits" article by JK Rowling on Pottermore, the headmaster portraits are actually painted before the headmaster dies:
Traditionally, a headmaster or headmistress is painted before their death. Once the portrait is completed, the headmaster or headmistress in question keeps it under lock and key, regularly visiting it in its cupboard (if so desired) to teach it to act and behave exactly like themselves, and imparting all kinds of useful memories and pieces of knowledge that may then be shared through the centuries with their successors in office.
Thus, when Dumbledore died all they had to do was take the portrait out of its cupboard and hang it on the wall, which should only take a matter of seconds.