Community Documentation

Working with images (Drupal 7)

Last updated February 3, 2012. Created by purrin on May 9, 2005.
Edited by marcvangend, gaele, likewhoa, nicoz. Log in to edit this page.

The Image module (in core as of Drupal 7) allows you to display and manipulate images on your website. It exposes a setting for using the Image toolkit, allows you to configure image styles that can be used for resizing or adjusting images on display, and provides an image field (using the Field API) for attaching images to content.

Since Drupal 7 image handling is part of Drupal core, for Drupal 6 you need to use additional contributed modules.

The Image module integrates the functionalities of the Imagefield module, and also parts of the ImageCache and (the Drupal 6) Image module functionalities for image manipulations.

Usage

Adding an image field to a content type

In a default installation, only Articles have an image field, but this type of field can be added to other content types (e.g. Basic page or custom content types) as well. An image field can also be added to a user profile, a comment, or a taxonomy term. An unlimited number of image fields can be added, each with a variety of settings such as allowed extensions, maximum file size and default directory for storing the images.

To control the way the image is displayed you must define styles (see below).

To add an image field to a content type:

  1. Choose the content type via Administration > Structure > Content types.
  2. Choose "Manage fields".
  3. Enter a label for the field, e.g. "Product picture", define a field name and choose "Image".
  4. Decide if there should be a limit on how many images can be attached (defaults to 1).
  5. Choose a default image for this field (optional).
  6. Define further settings, such as allowed extensions, maximum file size and default directory for storing the image files.
  7. Save the settings.

For more information on creating custom fields in Drupal 7 consult the Field UI documentation.

Add images to content

To add images to content:

  1. Choose Administration > Add content > [Content type].
  2. The image field will be displayed in the list of fields once you've added it to the content type (see above). Click 'Browse', then select and upload the desired image.
  3. Enter alternate text to improve accessibility and optimize it for search engines.
  4. Save the article.

Images can be added and removed from the node's Edit tab. If the node is deleted, all associated images are deleted with it.

Adding images inline

To use images attached to nodes via the Image module inline (ie. in your node body text) you can use the Insert module. It provides a button to easily add an img tag with the path to the image in the src attribute and styles of your choosing. Creating image styles (see below) with inline images in mind, combined with some CSS to set the float property, can give users the option to easily set content to display to the left or right of document text.

You'll want to go to "Manage display" for your content type to ensure the image is set to hidden, otherwise it will be displayed twice.

Adding and changing styles

Using image styles you can scale, crop, resize, rotate and desaturate images without affecting the original image. By default three sizes are defined: 'thumbnail,' 'medium', and 'large'. The thumbnail style, for example, is shown with the teaser for image posts and when browsing image galleries.

When you change an image style, the module automatically refreshes all created images. Every image style must have a name, which will be used in the URL of the generated images.

To create or change image styles:

  1. Choose Administration > Configuration > Media > Image styles.
  2. Add or select a style to edit its settings.
  3. When configuring styles you can add effects: crop, scale, resize, rotate, desaturate, and rotate (other contributed modules provide additional effects). For example, by combining effects as crop, scale, and desaturate, you can create square, grayscale thumbnails.
  4. Save the settings.

To start using the defined styles they must be assigned to the display of a content type. For each display (e.g. "default" or "teaser"), a different style can chosen.

To assign a style:

  1. Choose Administer > Structure > Content types > Manage display.
  2. Choose the display (e.g. "default" or "teaser") via the tab buttons.
  3. Click the gear wheel button to choose an image style; you are also able to link the image to the node.
  4. Save the settings.
  5. Check the content that contains the image style in question to see your new styles at work.

Setting image quality

You can specifically define the image quality on your site. Take into account that better image quality means bigger files.

  1. Navigate to Administration > Configuration > Media > Image toolkit.
  2. Enter the desired quality in the field JPEG quality.
  3. Save the settings.

Troubleshooting image & gallery settings

In some circumstances, functions like adding images to galleries don't work unless Clean URLs are activated. (You get no result from attempting to add to galleries) More info on Clean URLs. [Related bug report]

Flushing or Rebuilding the Image styles

In Drupal 6 imagecache module was introduced into the Drupal 7 core, since then the option to 'flush' the image presets has changed. In the Drupal 7 UI, this 'Flush' image styles preset was removed, but now just resaving your image style will flush the image cache. If you need to flush all image styles, eg. after adjusting the JPEG quality, you can run the following code (for instance using Devel or Drush):

<?php
// Flush all image styles in Drupal 7.
foreach (image_styles() as $style) {
 
image_style_flush($style);
}
?>

Drupal 6

Unlike Drupal 7, Drupal 6 has no core Image module. You add image functionality in Drupal 6 by using a variety of different contributed modules.

Comments

Please don't post requests

Please don't post requests for general help with setting up this module here: those should go in the forum or the issue queue.

Comments on handbook pages should be used for corrections and clarifications and questions specifically about the content of the page.

Can this be injected to

Can this be injected to comments as well?

Getting images out of drupal

You've explained how to put images INTO drupal 7, but what's the point of it if there's no way to get an image OUT of drupal? For example, if i create a basic page (say node/9), and i want to display on the page a thumbnail of an image (already uploaded as node/8), what is the link that has to be used??? is it something like node/8/thumbnail?

I've tried searching for an answer everywhere with no luck.. is it possible that people are putting images into drupal with no intention of getting them out again? I don't understand

Use views for displaying

Use views for displaying content(including images). CCK = content in, Views = content out.

"Patience Luke, Let the object of your desire come to you." -- Obi Wan Kenobi

The easiest way to include an

The easiest way to include an image with a basic page is to add an image or file field to the basic page content type. Then, the image style (ie thumbnail, large, small, etc) that is displayed when the page is displayed can be controlled by the image style you set in the admin/structure/types/manage/[your-content-type]/display for the image field.

For images that are their own separate nodes, you can add a term reference field to the image content type and the basic page content type, then use Views to establish a relationship between your image nodes and your basic pages based on the term reference values.

Reggie W

Somehow "Manage Fields" does

Somehow "Manage Fields" does not show up anywhere in my D7 install

Are you looking under the

Are you looking under the "operations" column, corresponding to each content type? On my D7 install, next to each specific content type, there are options for various operations such as "edit", "manage fields", "manage display" and "delete".

List / un-list images not available in Drupal 7

I think the built-in Drupal 7 core image module works great except for one thing: Back in Drupal 6 and CCK it was possible to un-list certain images (hide them from display in full node view). In node edit page there were check-boxes next to each uploaded image that made that possible.

In Drupal 7, this is possible for attached files but not for attached images. The function disppeared for images as imagefield moved into core.

I would love to see that function back. Thanks.

I agree completely with this

I agree completely with this sentiment. Why is there no option for display/list? File fields have the display field available.

There are some good behavior options that are missing because of this lacking feature. If you want to use a combination of Insert module and automatic display of some images, it is currently not possible.

Image Gallery not scaling

In Drupal 7, I have several galleries using the same "type" and image gallery. I have set the image style from default to scale - put my settings in and it's not scaling!

I have spent hours fiddling - trying to figure out what I am doing wrong and am stumped.

For an example of my challenge please refer to ...http://amwdoorandwindow.com/Cabinetry

If you then venture to the Door portfolio page (http://amwdoorandwindow.com/Doors) you will see that I avoided this issue by sizing the first 8 pics in Photoshop (adding a border) on a template so the size of the photo is consistent - but that defeats the purpose of my client being able to load his own photos.

Any help, guidance will be greatly appreciated.

Amy

You have to use "scale and

You have to use "scale and crop" image effect not "scale" only. When you use a galley style like that one, all the small images have to be the same width and height. Good luck.

galleries

hi Amy, grate site! I´m new to drupal, can you please tell me how to set a page like your "portfolio" with several photo galleries inside? thanks you!

Wysiwyg, IMCE and Lightbox2

I followed the documentation above and also found the following post helpful. The author focuses on TinyMCE, but I got this working with CKEditor also.

Configuring and Adding Images to Drupal 7 Content with Wysiwyg, IMCE and Lightbox2
http://drupal.cocomore.com/blog/configuring-and-adding-images-drupal-7-c...

I'm glad you found that article helpful...

I tried to provide near equal coverage of TinyMCE and CKEditor so that it would be helpful for anyone setting up IMCE with Wysiwyg. I think a lot of it would still be helpful (the IMCE configuration) if you are setting up a non-Wysiwyg-integrated editor, too, such as the BUEditor now in use on Drupal.org. In the next day I should have a new post up about BUEditor, which I'm planning to move Cocomore Drupal to, as well (I discovered it a few months back and decided I liked it better than CKEditor, which we are currently using, although there are some pros and cons to both. It took me a while to realize just how extensible and customizable BUEditor is and now that I've added fields to the "add image" dialog and changed other defaults, I'm really happy with it (in local experiments), so hope to set it up on Drupal.Cocomore in the next day or two.

About me:

drupal 7 and drupal 6 are

drupal 7 and drupal 6 are quite different, its good they give new things to us but they should understand rarely people know the extentions and measurement they should mentioned in the help list. I found some solution like "crope and scale" as someone also mentioned before.

Thanks

For beginning user it worked great.
Ed

nobody click here