Automatically Resizing Image Fields with ImageCache

ImageCache provides automated image manipulation in conjunction with the image CCK field. To use it, you need to download, install, and enable the modules in ImageAPI and ImageCache, as shown in Tables 7.2 and 7.3.

ImageCache consists of a variety of presets, which are actions that are invoked as needed for image fields. When you go to Administer, Site Building, ImageCache (admin/build/imagecache), you see the list of your presets and can add new ones, as shown in Figure 7.14.

TABLE 7.2 ImageCache Module Reference

Download from Enable in section Permissions

ImageCache ImageCache ImageCache ImageCache

Administration

Administer, Site Building, ImageCache (admin/build/lmagecache)

project/imagecache ImageCache

Administer Imagecache

Flush Imagecache

View Imagecache basic

View Imagecache thumbnail

List, Add Preset

TABLE 7.3 ImageAPI Module Reference

Download from project/imageapi (moving to core in Drupal 7)

Enable in section ImageCache

Permissions none

Administration none

To the right of each preset are links that enable you to edit and delete them, as well as to export them for further use. The Flush link is an example of the benefits you get from using ImageCache. Drupal can cache the preset results for each preset that has been applied to an image. The Flush command will remove all those cached images; there will be a performance hit the first time they need to be recreated for any given image, but you may need to do this if you change the settings.

FIGURE 7.14

List and view ImageCache presets.

« o

Manage ImageCache pre

^ Add new preset

Administer

Content management Site building

ImageCache Menus Modules Themes URL aliases Site configuration User management

Preset Name basic thumbnail

Storage Actions

Normal Edit Delete Flush Export Normal Edit Delete Flush Export ryiiiii.vw *

In Figure 7.15, you can see the actions that you can add to a preset. (You can add several to an individual preset.)

When you click an action to add it, you fill in the necessary values for that action, as shown in Figure 7.16.

The actions and transformations that you can choose are standard image manipulation ones. Most of the actions provide a check box that lets you specify whether the image can be upscaled—that is, if it can be made larger than the original. This can result in poor image quality. In general, it is better to downscale images, making them smaller than the original. (That is why multimegapixel cameras take photos that are more easily manipulated than low-resolution cameras.) The other action to watch out for is an action that changes an image's aspect ratio. Such actions cause distortions in the image. Each action has a brief description that provides information about its consequences. Also, the fact that this is not Drupal terminology, but image manipulation terminology, makes it easier for you to get more information if you want to study a book or article for further information.

« ^ n

Edit preset: thumbnail | localhost

jfeiler

Edit preset: thumbnail

My account Create content Administer

Content management Site building Blocks

ImageCache

thumbnail

'he namespace Is used In URL's for Images to tell Imagecache how to process an Image. Please only use alphanumeric characters, underscores ( }, and hyphens (-) for preset names.

Action Settings

Menus Modules Hi ernes

+ Scale width: 100, height:, upscale: No Configure Delete

New Actions

URL aliases Site configuration User management Reports Help Log out

Add Crop - Crop an image to the rectangle specified by the given offsets and dimensions.

Add Deprecated Scale - Precursor to Scale and Crop. Has inside and outside dimension support. Tliis action will be removed in ImageCache 2.1).

Add Desaturate - Convert an image to grey scale.

Add Resize - Resize an image to an exact set of dimensions, ignoring aspect ratio. Add Rotate - Rotate an image.

Add Scale - Resize an image maintaining the original aspect-ratio (only one value necessary). Add Scale And Crop ■ Resize an image to an exact set of dimensions, ignoring aspect ratio. Add Sharpen - Sharpen an image using unsharp masking.

(update Preset)

Add actions to a preset.

« ^ o

Add imagecache_scale to thumbnail | localhost

jfeiler

Add imagecache_scale to thumbnail

My account

Weight:

Create content

100%

Enter a width In pixels or as a percentage. I.e. 500 or 30%. Height: 100%

Enter a height In pixels or as a percentage. I.e. 500 or 80%. □ Allow Upscaling

(Add Action)

r^M.j.n-n

Specify values for a presets action.

0 0

Post a comment

  • Receive news updates via email from this site