Create image styles in bulk for Drupal 7

Since we use responsive images a lot in Drupal, we use the following to create image styles in bulk.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Implements hook_image_default_styles().
*/
function MY_MODULE_image_default_styles() {
$styles = array();
$widths = array(
200,
320,
440,
640,
720,
960,
1024,
1280,
1440,
1600,
1800,
2000,
2200,
);

foreach ($widths as $width) {
$styles['w' . $width] = array(
'label' => 'w' . $width,
'effects' => array(
1 => array(
'name' => 'image_scale',
'data' => array(
'width' => $width,
'height' => '',
'upscale' => 0,
),
'weight' => 1,
),
),
);
}

return $styles;
}