How To Create And Use Drupal 7 Image Styles?

Image styles are used to set presets for image processing. Using image styles, we can crop, desaturate, resize, rotate and scale images. We can also add various effects before an image is displayed. When an image is displayed with a style, a new image file is created and the original image is left unchanged. By default, Drupal has three image styles: thumbnail, medium and large.

Creating image styles using Drupal UI

  1. Navigate to "Configuration" -> "Media" -> "Image Styles". Here you can see a list of default image styles.
  2. Click on "Add Style" to create an image style or click on "Edit" to edit the existing style.
  3. Add an effect from the available drop down and click on Add button. You can add the effect as per your requirement. The available effects are listed below:
  • Crop: Cropping will remove portions of an image to make it the specified dimensions.
  • Desaturate: Desaturation will convert the image into a grayscale image.
  • Resize: Resizing will make images an exact set of dimensions. This may cause images to be stretched or shrunk disproportionately.
  • Rotate: Rotating an image may cause the dimensions of an image to increase to fit the diagonal.
  • Scale: Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.
  • Scale and Crop: Scale and crop will maintain the aspect-ratio of the original image, then crop the larger dimension. This is most useful for creating perfectly square thumbnails without stretching the ima

 4. You can add multiple effects on a single image style. Multiple Effects will be applied as per the row weight. If you are looking for more effects than the ones provided by Drupal core, then install ImageCache Actions module.

Once you are done with creating an Image style, you need to assign it to an image.

Assigning image styles to image fields

Image styles can be assigned in "Content Types Display" or "Views Field Display".

Content Types Display Settings:

  1. Navigate to "Structure" -> "Content types" -> "<content_type>" -> Manage Display.
  2. Click on the settings icon.
  3. Select the image style from the dropdown. You can also link an image to the content or file.
  4. Save the settings.

Views Field Display Setting:

  1. Navigate to "Structure" -> "Views"
  2. Edit your view.
  3. Click on your image field and select an image style as shown below:
  4. Apply the settings and then save your view.

Adding Image Style manually in your theme template file

Sometimes, we may need to display the styled image manually in our template file. We can use "image_style_url($style_name, $path)" function in such cases. This function returns the absolute URL where a style image can be downloaded, suitable for use in an <img> tag. Requesting the URL will cause the image to be created. Here is an example:

// Original image uri.
$path = 'private://myimagefolder/imgfilename.jpg';
// Machine-readable name of the style.
$style = 'thumbnail';
// URL of the image style.
// Use this within your template file by assigning it to $vars['style_url'].
$style_url = image_style_url($style, $path);
Drupal Development

Sign up for our weekly newsletter


  • by Alex Vallejo (not verified)
  • Wed, 09/17/2014 - 07:09

The args in your example are backwards, they should be $style, $path

neerav.mehta's picture
  • by neerav.mehta
  • Wed, 09/17/2014 - 21:30

That's absolutely correct! Thank you for pointing this out. We have fixed the article. :)

  • by Jay (not verified)
  • Sat, 01/03/2015 - 12:27

Newbie question, but even though you have selected Image Style to be Large, will the system still create thumbnails upon upload? If so, how do I access the thumbnails?

neerav.mehta's picture
  • by neerav.mehta
  • Mon, 02/09/2015 - 23:27

Yes, system will still create thumbnails on upload. If you want the URL of the thumbnail, you can right click on the thumbnail and copy the image URL.

  • by Samba (not verified)
  • Mon, 07/20/2015 - 07:34

Will custom image styles create new files like "Thumbnail" style does? If so, how can I do this.

neerav.mehta's picture
  • by neerav.mehta
  • Mon, 07/20/2015 - 20:10

Yes, custom image styles will create new files. Can you explain the question "how can I do so"? I didn't understand it.

Add new comment