drupal-image-style-generator 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.idea/misc.xml CHANGED
@@ -1,6 +1,12 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
+ <component name="IntellijSFCCConnectionSettings">
4
+ <option name="sourceScanned" value="true" />
5
+ </component>
3
6
  <component name="IntellijSFCCDeploymentSettings">
4
- <option name="json" value="{&#10; &quot;isFullCodeVersionCleanup&quot;: false,&#10; &quot;tasks&quot;: [],&#10; &quot;isWebDavActionAllowed&quot;: true&#10;}" />
7
+ <option name="json" value="{&#10; &quot;isFullCodeVersionCleanup&quot;: false,&#10; &quot;tasks&quot;: [],&#10; &quot;multiInstancePair&quot;: []&#10;}" />
8
+ </component>
9
+ <component name="IntellijSFCCFileSystemListener">
10
+ <option name="loaded" value="true" />
5
11
  </component>
6
12
  </project>
package/README.md CHANGED
@@ -50,5 +50,7 @@ gen({
50
50
 
51
51
  **gridSize**: (Default: 0) Number to which grid the images are rounded up. In the worst case, the image is gridSize - 1 px to big for the breakpoint, but a higher grid will result in lower individual image styles.
52
52
 
53
- **convertTo**: (Default: null) enables the image_convert style - allowed values are `png`, `jpg`, `jpeg`, `jpe`, `gif`, `webp`
53
+ **convertTo**: (Default: null) enables the image_convert style - allowed values are `png`, `jpg`, `jpeg`, `jpe`, `gif`, `webp`
54
+
55
+ **clearCropTypes**: (Default: null) If set to true, unused `crop.type.aspect_*.yml` files will be removed. This can cause a lot of trouble and require you to remove all existing crop definition entities. Should not be done in a live site.
54
56
 
package/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  const REQUIRED_OPTIONS = ['themePath', 'themeName', 'syncFolder'];
2
2
  const helpers = require('./src/helpers');
3
3
  const path = require("path");
4
+ const yaml = require("js-yaml");
5
+ const {v4} = require("uuid");
4
6
 
5
7
  /**
6
8
  * @param {{themePath: string, themeName: string, syncFolder: string, gridSize?: number, convertTo?: string, clearCropTypes?: boolean}} options
@@ -64,6 +66,7 @@ module.exports = function (options) {
64
66
  imageStyles[styleId].image_style_mappings = [];
65
67
 
66
68
  imageStyles[styleId].widths = {};
69
+ imageStyles[styleId].heights = {};
67
70
  imageStyles[styleId].cropTypes = {};
68
71
  }
69
72
 
@@ -78,14 +81,24 @@ module.exports = function (options) {
78
81
  }
79
82
  }
80
83
 
81
- let width = bp.imageStyles[styleId].width || parsedWidth;
84
+ let height = bp.imageStyles[styleId].height || imageStyles[styleId].height; // if height is set once, this is set
82
85
 
83
- // adjust the width to the grid, so we save a couple of image styles
84
- width = Math.ceil(width / IMAGE_STYLE_GRID_SIZE) * IMAGE_STYLE_GRID_SIZE;
86
+ if (height) {
87
+ // set the new height
88
+ imageStyles[styleId].height = height;
89
+ imageStyles[styleId].heights[bpName] = height;
90
+ }
91
+
92
+ if (!height || bp.imageStyles[styleId].width) {
93
+ let width = bp.imageStyles[styleId].width || parsedWidth;
85
94
 
86
- // set the new width
87
- imageStyles[styleId].width = width;
88
- imageStyles[styleId].widths[bpName] = imageStyles[styleId].width;
95
+ // adjust the width to the grid, so we save a couple of image styles
96
+ width = Math.ceil(width / IMAGE_STYLE_GRID_SIZE) * IMAGE_STYLE_GRID_SIZE;
97
+
98
+ // set the new width
99
+ imageStyles[styleId].width = width;
100
+ imageStyles[styleId].widths[bpName] = imageStyles[styleId].width;
101
+ }
89
102
 
90
103
  if (imageStyles[styleId].manual_crop) {
91
104
  imageStyles[styleId].cropTypes[bpName] = 'aspect_' + imageStyles[styleId].aspectRatio.replace(':', 'x');
@@ -258,6 +271,62 @@ module.exports = function (options) {
258
271
  }
259
272
  };
260
273
  }
274
+ } else if (imageStyles[styleId].height) {
275
+ // this is a height style
276
+ const styleHeight = imageStyles[styleId].heights[bpName] * multiplyNum;
277
+ styleLabel = `Scale Height ${styleHeight}`;
278
+ concreteStyleId = `sh_${styleHeight}`;
279
+ styleFileName = `image.style.${concreteStyleId}.yml`;
280
+ styleFilePath = `${syncFolder}/${styleFileName}`;
281
+
282
+ styleYml = fs.existsSync(styleFilePath) ?
283
+ yaml.load(fs.readFileSync(styleFilePath, 'utf8')) :
284
+ {
285
+ uuid: uniqueId,
286
+ langcode: 'de',
287
+ status: true,
288
+ dependencies: {},
289
+ name: concreteStyleId,
290
+ label: styleLabel,
291
+ effects: {}
292
+ }
293
+ ;
294
+
295
+ const scaleEffect = helpers.getEffectByTypeId('image_scale', styleYml.effects);
296
+ const convertEffect = helpers.getEffectByTypeId('image_convert', styleYml.effects);
297
+
298
+ hasChanges = !scaleEffect || scaleEffect.data.height !== styleHeight ||
299
+ (convertTo && (!convertEffect || (convertEffect && convertEffect.data.extension !== convertTo))) || (!convertTo && convertEffect)
300
+ ;
301
+
302
+ if (hasChanges) {
303
+ styleYml.effects = {};
304
+
305
+ if (convertTo) {
306
+ const convertEffectId = v4();
307
+ styleYml.effects[convertEffectId] = {
308
+ uuid: convertEffectId,
309
+ id: 'image_convert',
310
+ weight: -1,
311
+ data: {
312
+ extension: convertTo
313
+ }
314
+ }
315
+ }
316
+
317
+ const effectId = v4();
318
+ styleYml.effects[effectId] = {
319
+ uuid: effectId,
320
+ id: 'image_scale',
321
+ weight: 1,
322
+ data: {
323
+ width: null,
324
+ height: styleHeight,
325
+ upscale: false
326
+ }
327
+ };
328
+ }
329
+
261
330
  } else {
262
331
 
263
332
  // generate the filename
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drupal-image-style-generator",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A helper tool to automatically geenrate drupal 8+ responsive image styles",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,15 @@
1
+ uuid: 0727fb6a-8037-41bc-b503-52ffab0af788
2
+ langcode: de
3
+ status: true
4
+ dependencies: {}
5
+ name: sh_108
6
+ label: Scale Height 108
7
+ effects:
8
+ db36ed3a-be4e-43fe-b87d-dbe3650489d7:
9
+ uuid: db36ed3a-be4e-43fe-b87d-dbe3650489d7
10
+ id: image_scale
11
+ weight: 1
12
+ data:
13
+ width: null
14
+ height: 108
15
+ upscale: false
@@ -0,0 +1,15 @@
1
+ uuid: 0fdf495a-4ab9-4e0e-bb5f-e7ebccf97a6e
2
+ langcode: de
3
+ status: true
4
+ dependencies: {}
5
+ name: sh_176
6
+ label: Scale Height 176
7
+ effects:
8
+ a6c03b5d-c1f9-4a01-9e62-b54d598aaa36:
9
+ uuid: a6c03b5d-c1f9-4a01-9e62-b54d598aaa36
10
+ id: image_scale
11
+ weight: 1
12
+ data:
13
+ width: null
14
+ height: 176
15
+ upscale: false
@@ -0,0 +1,15 @@
1
+ uuid: 284b7900-d250-49e6-aedf-56d2e915877a
2
+ langcode: de
3
+ status: true
4
+ dependencies: {}
5
+ name: sh_216
6
+ label: Scale Height 216
7
+ effects:
8
+ b2ba04fe-b48e-458e-9c00-014a5dfa3195:
9
+ uuid: b2ba04fe-b48e-458e-9c00-014a5dfa3195
10
+ id: image_scale
11
+ weight: 1
12
+ data:
13
+ width: null
14
+ height: 216
15
+ upscale: false
@@ -0,0 +1,15 @@
1
+ uuid: 111d834b-a445-44f5-b90a-ec14c2474089
2
+ langcode: de
3
+ status: true
4
+ dependencies: {}
5
+ name: sh_38
6
+ label: Scale Height 38
7
+ effects:
8
+ 778dae1b-d341-45bd-8132-d34567713839:
9
+ uuid: 778dae1b-d341-45bd-8132-d34567713839
10
+ id: image_scale
11
+ weight: 1
12
+ data:
13
+ width: null
14
+ height: 38
15
+ upscale: false
@@ -0,0 +1,15 @@
1
+ uuid: 605ecee1-e0d1-49c9-9212-05ae5f69e42b
2
+ langcode: de
3
+ status: true
4
+ dependencies: {}
5
+ name: sh_76
6
+ label: Scale Height 76
7
+ effects:
8
+ 1c63103f-ba73-44c6-841b-b948f7630d90:
9
+ uuid: 1c63103f-ba73-44c6-841b-b948f7630d90
10
+ id: image_scale
11
+ weight: 1
12
+ data:
13
+ width: null
14
+ height: 76
15
+ upscale: false
@@ -0,0 +1,15 @@
1
+ uuid: 2d2a2c04-b28b-4a35-a500-150815f3d280
2
+ langcode: de
3
+ status: true
4
+ dependencies: {}
5
+ name: sh_88
6
+ label: Scale Height 88
7
+ effects:
8
+ 91e17ce1-80b6-44db-8faf-5843921dc975:
9
+ uuid: 91e17ce1-80b6-44db-8faf-5843921dc975
10
+ id: image_scale
11
+ weight: 1
12
+ data:
13
+ width: null
14
+ height: 88
15
+ upscale: false
@@ -0,0 +1,42 @@
1
+ uuid: 82f42ee2-56b7-43a9-8e80-a8d8d0d2fe0c
2
+ langcode: de
3
+ status: true
4
+ dependencies:
5
+ config:
6
+ - image.style.sh_38
7
+ - image.style.sh_76
8
+ - image.style.sh_88
9
+ - image.style.sh_176
10
+ - image.style.sh_108
11
+ - image.style.sh_216
12
+ theme:
13
+ - height
14
+ id: height_hero
15
+ label: Height Hero
16
+ image_style_mappings:
17
+ - breakpoint_id: default.xs
18
+ multiplier: 1x
19
+ image_mapping_type: image_style
20
+ image_mapping: sh_38
21
+ - breakpoint_id: default.xs
22
+ multiplier: 2x
23
+ image_mapping_type: image_style
24
+ image_mapping: sh_76
25
+ - breakpoint_id: default.md
26
+ multiplier: 1x
27
+ image_mapping_type: image_style
28
+ image_mapping: sh_88
29
+ - breakpoint_id: default.md
30
+ multiplier: 2x
31
+ image_mapping_type: image_style
32
+ image_mapping: sh_176
33
+ - breakpoint_id: default.lg
34
+ multiplier: 1x
35
+ image_mapping_type: image_style
36
+ image_mapping: sh_108
37
+ - breakpoint_id: default.lg
38
+ multiplier: 2x
39
+ image_mapping_type: image_style
40
+ image_mapping: sh_216
41
+ breakpoint_group: height
42
+ fallback_image_style: sh_38
@@ -0,0 +1,32 @@
1
+ default.xs: # mobile phones
2
+ label: XS
3
+ mediaQuery: '(max-width: 575px)'
4
+ weight: 0
5
+ multipliers:
6
+ - 1x
7
+ - 2x
8
+ imageStyles:
9
+ height_hero:
10
+ label: 'Height Hero'
11
+ height: 38
12
+ default.md: # large tablets
13
+ label: MD
14
+ mediaQuery: '(min-width: 576px) and (max-width: 991px)'
15
+ weight: 1
16
+ multipliers:
17
+ - 1x
18
+ - 2x
19
+ imageStyles:
20
+ # assuming, that the breakpoint is at md
21
+ height_hero:
22
+ height: 88
23
+ default.lg: # desktop
24
+ label: LG
25
+ mediaQuery: '(min-width: 992px) and (max-width: 1199px)'
26
+ weight: 3
27
+ multipliers:
28
+ - 1x
29
+ - 2x
30
+ imageStyles:
31
+ height_hero:
32
+ height: 108
package/test/test.js CHANGED
@@ -71,8 +71,11 @@ describe('Running image generator tests', function () {
71
71
  })
72
72
 
73
73
 
74
+ console.log(fs.readdirSync(syncFolder));
75
+
76
+
74
77
  expect(res).to.be.true;
75
- expect(fs.readdirSync(syncFolder)).deep.equal([
78
+ expect(fs.readdirSync(syncFolder)).to.include.members([
76
79
  'core.extension.yml',
77
80
  'crop.type.aspect_165x266.yml',
78
81
  'crop.type.aspect_635x424.yml',
@@ -90,4 +93,37 @@ describe('Running image generator tests', function () {
90
93
  expect(cropYml.aspect_ratio).to.equal('165:266');
91
94
  });
92
95
 
96
+ it('should generate the correct height only styles', () => {
97
+ const themeName = 'height';
98
+ const themePath = './test/data/crop/web/themes/' + themeName;
99
+ const syncFolder = './test/data/crop/config/sync/';
100
+
101
+ const res = gen({
102
+ themePath: themePath,
103
+ themeName: themeName,
104
+ syncFolder: syncFolder
105
+ })
106
+
107
+
108
+ expect(res).to.be.true;
109
+ expect(fs.readdirSync(syncFolder)).to.include.members([
110
+ 'core.extension.yml',
111
+ 'image.style.sh_38.yml',
112
+ 'image.style.sh_76.yml',
113
+ 'image.style.sh_88.yml',
114
+ 'image.style.sh_108.yml',
115
+ 'image.style.sh_176.yml',
116
+ 'image.style.sh_216.yml',
117
+ 'responsive_image.styles.height_hero.yml'
118
+ ]);
119
+
120
+ const scaleYml = yaml.load(fs.readFileSync(syncFolder + 'image.style.sh_108.yml', 'utf8'));
121
+ expect(scaleYml).to.be.an('object');
122
+
123
+ const effect = Object.values(scaleYml.effects)[0];
124
+
125
+ expect(effect['id']).to.equal('image_scale');
126
+ expect(effect.data.height).to.equal(108);
127
+ });
128
+
93
129
  });
@@ -1,26 +0,0 @@
1
- uuid: 94309bf7-a6c9-491b-9d02-9f5a553abd9e
2
- langcode: de
3
- status: true
4
- dependencies:
5
- config:
6
- - crop.type.aspect_165x266
7
- module:
8
- - crop
9
- name: mc_1150_aspect_165x266
10
- label: Manual Crop and Scale 1150
11
- effects:
12
- fd420ed1-c9ee-4353-b84e-732f5ba251ce:
13
- uuid: fd420ed1-c9ee-4353-b84e-732f5ba251ce
14
- id: crop_crop
15
- weight: 1
16
- data:
17
- crop_type: aspect_165x266
18
- automatic_crop_provider: null
19
- 34e84fce-08d8-4c6f-a014-8076b1d5d6bc:
20
- uuid: 34e84fce-08d8-4c6f-a014-8076b1d5d6bc
21
- id: image_scale
22
- weight: 2
23
- data:
24
- width: 1150
25
- height: null
26
- upscale: false
@@ -1,26 +0,0 @@
1
- uuid: fb4ebd61-4255-49fa-b915-fc60ddff2e41
2
- langcode: de
3
- status: true
4
- dependencies:
5
- config:
6
- - crop.type.aspect_165x266
7
- module:
8
- - crop
9
- name: mc_1320_aspect_165x266
10
- label: Manual Crop and Scale 1320
11
- effects:
12
- 9ad2dc73-5ece-412e-9f7e-b7b3e558ae52:
13
- uuid: 9ad2dc73-5ece-412e-9f7e-b7b3e558ae52
14
- id: crop_crop
15
- weight: 1
16
- data:
17
- crop_type: aspect_165x266
18
- automatic_crop_provider: null
19
- 52c07d14-a4ac-497a-b08e-eb15706b2603:
20
- uuid: 52c07d14-a4ac-497a-b08e-eb15706b2603
21
- id: image_scale
22
- weight: 2
23
- data:
24
- width: 1320
25
- height: null
26
- upscale: false
@@ -1,26 +0,0 @@
1
- uuid: bfe921e0-c819-4b21-b0e2-6d930e465968
2
- langcode: de
3
- status: true
4
- dependencies:
5
- config:
6
- - crop.type.aspect_635x424
7
- module:
8
- - crop
9
- name: mc_290_aspect_635x424
10
- label: Manual Crop and Scale 290
11
- effects:
12
- c2e88340-30e0-417e-b7a1-e038df8964bf:
13
- uuid: c2e88340-30e0-417e-b7a1-e038df8964bf
14
- id: crop_crop
15
- weight: 1
16
- data:
17
- crop_type: aspect_635x424
18
- automatic_crop_provider: null
19
- dd58c164-bd4a-4279-9f2d-c5d15d6caf9a:
20
- uuid: dd58c164-bd4a-4279-9f2d-c5d15d6caf9a
21
- id: image_scale
22
- weight: 2
23
- data:
24
- width: 290
25
- height: null
26
- upscale: false
@@ -1,26 +0,0 @@
1
- uuid: 5cb45f65-ff19-4258-b01d-700fc3419bb2
2
- langcode: de
3
- status: true
4
- dependencies:
5
- config:
6
- - crop.type.aspect_165x266
7
- module:
8
- - crop
9
- name: mc_575_aspect_165x266
10
- label: Manual Crop and Scale 575
11
- effects:
12
- 5b2132b5-ad86-4e85-9de9-493f51077829:
13
- uuid: 5b2132b5-ad86-4e85-9de9-493f51077829
14
- id: crop_crop
15
- weight: 1
16
- data:
17
- crop_type: aspect_165x266
18
- automatic_crop_provider: null
19
- 23efa495-ce42-4a81-bcc5-00b59c5f6432:
20
- uuid: 23efa495-ce42-4a81-bcc5-00b59c5f6432
21
- id: image_scale
22
- weight: 2
23
- data:
24
- width: 575
25
- height: null
26
- upscale: false
@@ -1,26 +0,0 @@
1
- uuid: 43aca4e3-ca35-4494-947a-b768a20aebe8
2
- langcode: de
3
- status: true
4
- dependencies:
5
- config:
6
- - crop.type.aspect_635x424
7
- module:
8
- - crop
9
- name: mc_580_aspect_635x424
10
- label: Manual Crop and Scale 580
11
- effects:
12
- a3fdf392-5939-47a6-ac3c-69b468c07db8:
13
- uuid: a3fdf392-5939-47a6-ac3c-69b468c07db8
14
- id: crop_crop
15
- weight: 1
16
- data:
17
- crop_type: aspect_635x424
18
- automatic_crop_provider: null
19
- 4db37637-c7e9-47c0-bbf1-3adc22379da3:
20
- uuid: 4db37637-c7e9-47c0-bbf1-3adc22379da3
21
- id: image_scale
22
- weight: 2
23
- data:
24
- width: 580
25
- height: null
26
- upscale: false
@@ -1,26 +0,0 @@
1
- uuid: 14c92cbb-0118-40fa-b5e4-f81b7e841b46
2
- langcode: de
3
- status: true
4
- dependencies:
5
- config:
6
- - crop.type.aspect_165x266
7
- module:
8
- - crop
9
- name: mc_660_aspect_165x266
10
- label: Manual Crop and Scale 660
11
- effects:
12
- 44162a11-4f9a-404d-94ff-31ea41095194:
13
- uuid: 44162a11-4f9a-404d-94ff-31ea41095194
14
- id: crop_crop
15
- weight: 1
16
- data:
17
- crop_type: aspect_165x266
18
- automatic_crop_provider: null
19
- 12ee83a5-2763-47ee-941e-f36916f15bc9:
20
- uuid: 12ee83a5-2763-47ee-941e-f36916f15bc9
21
- id: image_scale
22
- weight: 2
23
- data:
24
- width: 660
25
- height: null
26
- upscale: false