Images D6 vs. D7

One of the most unnoticed changes from Drupal 6 to Drupal 7 was the inclusion of image handling in core. A typical Drupal 6 setup comprised of CCK and Imagefield to add images to nodes, along with Imagecache to render the image in various sizes. The Drupal 7 core Field and Image modules are for the most part direct replacements for CCK, Imagefield, and Imagecache; however there is a distinct difference worth noting. Preset handling.

Drupal 6's Imagecache processes a preset (a set of croping and resizing rules) as it renders an image into a page. Let's take a common use-case where you have a page displaying View of an image gallery. Say the gallery is 5 columns wide and 10 columns tall and using some image preset. As the page renders, it will build all 50 derivative images in the same page request.

This mechanism has changed in the implementation of Drupal 7's core Image module. Instead Drupal renders the markup for the page with the appropriate URLs for the derivative images without generating the files. The derivative images are generated only when the user's browser makes HTTP requests to load the images. With this method the generation of the derivative images is spread across multiple requests.

Just to recap Drupal 6 renders the page and generates the preset derivative files all at once. Drupal 7 renders the page with the URLs for where it expects to find the images, then actually generates the images on subsequent requests for each file. One other important item to note is that when a derivative image is generated, it is saved into the site's files directory so the site doesn't have to keep regenerating the images.