7.x image.module image_style_save($style)

Saves an image style.


array $style: An image style array containing:

  • name: A unique name for the style.
  • isid: (optional) An image style ID.

Return value

array An image style array containing:

  • name: An unique name for the style.
  • old_name: The original name for the style.
  • isid: An image style ID.
  • is_new: TRUE if this is a new style, and FALSE if it is an existing style.
8 calls to image_style_save()
ImageAdminStylesUnitTest::testStyleReplacement in modules/image/image.test
Test deleting a style and choosing a replacement style.
ImageDimensionsTestCase::testImageDimensions in modules/image/image.test
Test styled image dimensions cumulatively.
ImageFieldTestCase::createRandomStyle in modules/image/image.test
Create a random style.
ImageStylesPathAndUrlTestCase::setUp in modules/image/image.test
Sets up a Drupal site for running functional and integration tests.
ImageThemeFunctionWebTestCase::testImageFormatterTheme in modules/image/image.test
Tests usage of the image field formatters.

... See full list


modules/image/image.module, line 685
Exposes global functionality for creating image styles.


function image_style_save($style) {
  if (isset($style['isid']) && is_numeric($style['isid'])) {

    // Load the existing style to make sure we account for renamed styles.
    $old_style = image_style_load(NULL, $style['isid']);
    drupal_write_record('image_styles', $style, 'isid');
    if ($old_style['name'] != $style['name']) {
      $style['old_name'] = $old_style['name'];
  else {

    // Add a default label when not given.
    if (empty($style['label'])) {
      $style['label'] = $style['name'];
    drupal_write_record('image_styles', $style);
    $style['is_new'] = TRUE;

  // Let other modules update as necessary on save.
  module_invoke_all('image_style_save', $style);

  // Clear all caches and flush.
  return $style;


hkirsman’s picture

An example from http://www.drupalfoo.com/drupal-7-creating-image-style-programatically-m...

  $style = image_style_save(array('name' => 'avatar'));
  $effect = array(
    'name' => 'image_scale',
    'data' => array(
      'width' => 64,
      'height' => 64,
      'upscale' => TRUE,
    'isid' => $style['isid'],
Graber’s picture

add a label for your new style:

	$style = image_style_save(array(
		'name' => 'cart_block_thumb',
		'label' => 'Cart block thumbnail (50 x 50)')
	$effect = array(
		'name' => 'image_scale',
		'data' => array(
			'width' => 50,
			'height' => 50,
			'upscale' => TRUE,
		'isid' => $style['isid'],