@base-cms/image
Advanced tools
| class CropRectangle { | ||
| constructor({ | ||
| x, | ||
| y, | ||
| width, | ||
| height, | ||
| } = {}) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.width = width; | ||
| this.height = height; | ||
| } | ||
| isCropped() { | ||
| return !this.notCropped(); | ||
| } | ||
| notCropped() { | ||
| return this.x === 0 && this.y === 0; | ||
| } | ||
| toString() { | ||
| return ['x', 'y', 'width', 'height'].map(key => this[key]).join(','); | ||
| } | ||
| } | ||
| /** | ||
| * Generates a crop rectangle for the given image width, height | ||
| * and crop dimensions. | ||
| * | ||
| * Uses the same scaling logic as Base Platform to properly calculate | ||
| * the crop area. | ||
| */ | ||
| module.exports = ({ width, height, cropDimensions }) => { | ||
| if (!cropDimensions) { | ||
| return new CropRectangle({ | ||
| x: 0, | ||
| y: 0, | ||
| width, | ||
| height, | ||
| }); | ||
| } | ||
| // @see Cygnus\ApplicationBundle\Apps\Management\Controller::cropImageAction | ||
| const scale = width / 640; | ||
| const { | ||
| x1, | ||
| x2, | ||
| y1, | ||
| y2, | ||
| } = ['x1', 'x2', 'y1', 'y2'].reduce((o, key) => { | ||
| const v = Math.round(cropDimensions[key] * scale); | ||
| return { ...o, [key]: v }; | ||
| }, {}); | ||
| return new CropRectangle({ | ||
| x: x1, | ||
| y: y1, | ||
| width: x2 - x1, | ||
| height: y2 - y1, | ||
| }); | ||
| }; |
+2
-2
| { | ||
| "name": "@base-cms/image", | ||
| "version": "1.6.3", | ||
| "version": "1.32.0", | ||
| "description": "Common image utilities for BaseCMS projects.", | ||
@@ -20,3 +20,3 @@ "main": "src/index.js", | ||
| }, | ||
| "gitHead": "e592ac4b793855f4ea18936d2eb2bbacba81f555" | ||
| "gitHead": "bf136f96a4216f803c2925ace715c7102cdcc487" | ||
| } |
@@ -57,2 +57,3 @@ const { camelize } = require('@base-cms/inflector'); | ||
| 'fill-mode', // Fill Mode | ||
| 'fill', // Fill | ||
@@ -59,0 +60,0 @@ // Focal Point Crop |
+2
-0
@@ -5,2 +5,3 @@ const buildImgixUrl = require('./build-imgix-url'); | ||
| const createSrcFor = require('./create-src-for'); | ||
| const cropRectangle = require('./crop-rectangle'); | ||
@@ -12,2 +13,3 @@ module.exports = { | ||
| createSrcFor, | ||
| cropRectangle, | ||
| }; |
8744
16.46%8
14.29%265
28.64%