Extract definition of constants
Extract codes to generate a thumbnail
Resize canvas only if needed