akamai-filerobot-converter
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -39,3 +39,8 @@ "use strict"; | ||
var imageResizingInstruction = (0, _filerobotToAkamai.imageResizingSchema)(props); | ||
var watermarkInstruction = (0, _filerobotToAkamai.watermarkSchema)(props); | ||
if (watermarkInstruction.shouldProcess(queryString)) { | ||
resultOperations = [].concat(_toConsumableArray(resultOperations), _toConsumableArray(watermarkInstruction.process(queryString))); | ||
} | ||
if (imageResizingInstruction.shouldProcess(queryString)) { | ||
@@ -58,3 +63,3 @@ resultOperations = [].concat(_toConsumableArray(resultOperations), _toConsumableArray(imageResizingInstruction.process(queryString))); | ||
}); | ||
return noQueryString ? url : (type === 'akamai-to-filerobot' ? url.replace('im=', '') : url.replace('?', '?im=')).replace(queryString, resultOperations.join(type === 'akamai-to-filerobot' ? '&' : ';')); | ||
return noQueryString || resultOperations.length === 0 ? url : (type === 'akamai-to-filerobot' ? url.replace('im=', '') : url.replace('?', '?im=')).replace(queryString, resultOperations.join(type === 'akamai-to-filerobot' ? '&' : ';')); | ||
}; | ||
@@ -61,0 +66,0 @@ }; |
@@ -13,3 +13,3 @@ "use strict"; | ||
if (to === 'filerobot') { | ||
return value ? value.toLowerCase() : 'NorthWest'; | ||
return value ? value.toLowerCase() : 'northwest'; | ||
} else if (to === 'akamai') { | ||
@@ -16,0 +16,0 @@ switch (value) { |
@@ -15,2 +15,5 @@ "use strict"; | ||
WATERMARK_IMAGE: /image=\(url=(.*)\)/, | ||
WATERMARK_TEXT: /text=([^,]*)(?=(,|\)))/, | ||
WATERMARK_TEXT_SIZE: /size=(\d*)/, | ||
WATERMARK_TEXT_COLOR: /fill=([0-9a-f]{6})/, | ||
WATERMARK_X_POSITION: /xPosition=(\d*)/, | ||
@@ -17,0 +20,0 @@ WATERMARK_Y_POSITION: /yPosition=(\d*)/, |
@@ -13,4 +13,11 @@ "use strict"; | ||
FUNC: /func=(bound|fit|crop|cover|face|cropfit)/, | ||
GRAVITY: /gravity=(northwest|northeast|southwest|southeast|north|west|center|centre|east|south)|gravity=(\d*),(\d*)/ | ||
GRAVITY: /gravity=(northwest|northeast|southwest|southeast|north|west|center|centre|east|south)|gravity=(\d*),(\d*)/, | ||
WATERMARK: /wat=1/, | ||
WATERMARK_IMAGE: /wat_url=([^&]*)(?=(|))/, | ||
WATERMARK_TEXT: /wat_text=([^&]*)(?=(|))/, | ||
WATERMARK_TEXT_SIZE: /wat_fontsize=(\d*)/, | ||
WATERMARK_SCALE: /wat_scale=(\d*)/, | ||
WATERMARK_TEXT_COLOR: /wat_color=([0-9a-f]{6})|wat_colour=([0-9a-f]{6})/, | ||
WATERMARK_POSITION: /wat_pad=(\d*),(\d*)|wat_pad=(\d*)/ | ||
}; | ||
exports.default = _default; |
@@ -20,16 +20,23 @@ "use strict"; | ||
process: function process(param) { | ||
var _param$match, _param$match2, _param$match3; | ||
var _param$match, _param$match2, _param$match3, _param$match4, _param$match5, _param$match6, _param$match7; | ||
var watermarkImage = param.match(_akamaiRegexHandbook.default.WATERMARK_IMAGE)[1]; | ||
var xPosition = ((_param$match = param.match(_akamaiRegexHandbook.default.WATERMARK_X_POSITION)) === null || _param$match === void 0 ? void 0 : _param$match[1]) || 0; | ||
var yPosition = ((_param$match2 = param.match(_akamaiRegexHandbook.default.WATERMARK_Y_POSITION)) === null || _param$match2 === void 0 ? void 0 : _param$match2[1]) || 0; | ||
var scaleMatch = (_param$match3 = param.match(_akamaiRegexHandbook.default.WATERMARK_SCALE)) === null || _param$match3 === void 0 ? void 0 : _param$match3[1]; | ||
var watermarkImage = (_param$match = param.match(_akamaiRegexHandbook.default.WATERMARK_IMAGE)) === null || _param$match === void 0 ? void 0 : _param$match[1]; | ||
var watermarkText = (_param$match2 = param.match(_akamaiRegexHandbook.default.WATERMARK_TEXT)) === null || _param$match2 === void 0 ? void 0 : _param$match2[1]; | ||
var watermarkTextSize = (_param$match3 = param.match(_akamaiRegexHandbook.default.WATERMARK_TEXT_SIZE)) === null || _param$match3 === void 0 ? void 0 : _param$match3[1]; | ||
var watermarkTextColor = (_param$match4 = param.match(_akamaiRegexHandbook.default.WATERMARK_TEXT_COLOR)) === null || _param$match4 === void 0 ? void 0 : _param$match4[1]; | ||
var xPosition = ((_param$match5 = param.match(_akamaiRegexHandbook.default.WATERMARK_X_POSITION)) === null || _param$match5 === void 0 ? void 0 : _param$match5[1]) || 0; | ||
var yPosition = ((_param$match6 = param.match(_akamaiRegexHandbook.default.WATERMARK_Y_POSITION)) === null || _param$match6 === void 0 ? void 0 : _param$match6[1]) || 0; | ||
var scaleMatch = (_param$match7 = param.match(_akamaiRegexHandbook.default.WATERMARK_SCALE)) === null || _param$match7 === void 0 ? void 0 : _param$match7[1]; | ||
var gravityMatch = param.match(_akamaiRegexHandbook.default.GRAVITY); | ||
var scale = parseFloat(scaleMatch, 10) * 100; | ||
var scale = parseFloat(scaleMatch, 10) * 500; | ||
var gravity = (0, _normalizers.normalizeGravity)(gravityMatch && gravityMatch[1]); | ||
var params = ['wat=1', "wat_url=".concat(watermarkImage)]; | ||
if (xPosition || yPosition) params.push("wat_pad=".concat(xPosition, ",").concat(yPosition)); | ||
if (scaleMatch) params.push("wat_scale=".concat(scale)); | ||
if (gravityMatch) params.push("wat_gravity=".concat(gravity)); | ||
return params; | ||
var filerobotQueryParams = ['wat=1']; | ||
if (watermarkImage) filerobotQueryParams.push("wat_url=".concat(watermarkImage)); | ||
if (watermarkText) filerobotQueryParams.push("wat_text=".concat(watermarkText)); | ||
if (watermarkTextSize) filerobotQueryParams.push("wat_fontsize=".concat(watermarkTextSize)); | ||
if (watermarkTextColor) filerobotQueryParams.push("wat_color=".concat(watermarkTextColor)); | ||
if (xPosition || yPosition) filerobotQueryParams.push("wat_pad=".concat(xPosition, ",").concat(yPosition)); | ||
if (scaleMatch) filerobotQueryParams.push("wat_scale=".concat(scale)); | ||
filerobotQueryParams.push("wat_gravity=".concat(gravity)); | ||
return filerobotQueryParams; | ||
} | ||
@@ -36,0 +43,0 @@ }; |
@@ -12,2 +12,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "watermarkSchema", { | ||
enumerable: true, | ||
get: function get() { | ||
return _watermarkSchema.default; | ||
} | ||
}); | ||
exports.getFilerobotInstructions = void 0; | ||
@@ -21,2 +27,4 @@ | ||
var _watermarkSchema = _interopRequireDefault(require("./watermark-schema")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -23,0 +31,0 @@ |
{ | ||
"name": "akamai-filerobot-converter", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "", | ||
@@ -11,3 +11,5 @@ "private": false, | ||
"clean-dist": "rm -rf dist", | ||
"dist": "npm run clean-dist && npx babel src --out-dir dist --copy-files" | ||
"dist": "npm run clean-dist && npx babel src --out-dir dist --copy-files", | ||
"deploy": "gh-pages -d build", | ||
"publish-demo": "npm run build && npm run deploy" | ||
}, | ||
@@ -29,4 +31,5 @@ "keywords": [], | ||
"@babel/preset-env": "^7.12.17", | ||
"babel-loader": "^8.1.0" | ||
"babel-loader": "^8.1.0", | ||
"gh-pages": "^2.2.0" | ||
} | ||
} |
137
README.md
@@ -1,2 +0,2 @@ | ||
[![Release](https://img.shields.io/badge/release-v0.1.0-blue.svg)](https://github.com/scaleflex/akamai-filerobot-converter) | ||
[![Release](https://img.shields.io/badge/release-v0.1.4-blue.svg)](https://github.com/scaleflex/akamai-filerobot-converter) | ||
[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)](#contributing) | ||
@@ -6,12 +6,131 @@ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) | ||
<p align="center"> | ||
<a href="https://www.filerobot.com/en/home">Learn more about Filerobot</a> | ||
<p align="center"> | ||
<a href="https://www.filerobot.com/en/home">Learn more about Filerobot</a> | ||
</p> | ||
<h1 align="center"> | ||
Akamai to Filerobot Connector | ||
</h1> | ||
<h1 align="center">Akamai to Filerobot Connector</h1> | ||
<h5 align="center"> | ||
Converts Akamai URl image transformation parameters to Filerobot and vice versa. | ||
</h5> | ||
<h5 align="center"> | ||
Converts Akamai URl image transformation parameters to Filerobot and vice versa. | ||
</h5> | ||
### <a name="installation_react"></a>Installation | ||
``` | ||
$ npm install --save akamai-filerobot-converter | ||
``` | ||
### <a name="usage"></a>Usage | ||
There are two available methods: **akamaiToFilerobot**, **filerobotToAkamai**. | ||
```javascript | ||
akamaiToFilerobot('<URL>?im=Rotate,degrees=50;BackgroundColor=00ff00') | ||
// '<URL>?r=-50&bg_colour=00ff00' | ||
``` | ||
```javascript | ||
filerobotToAkamai('<URL>?r=50&bg_colour=ff00ff') | ||
// '<URL>?im=Rotate,degrees=-50;BackgroundColor,color=ff00ff' | ||
``` | ||
### <a name="supported_options"></a>Supported Options | ||
#### Akamai to Filerobot | ||
- **Rotate** | ||
- syntax: [ImageURL]?im=Rotate,degrees=[number_of_degrees]) | ||
- **Auto Crop** | ||
- syntax #1: [ImageURL]?im=Crop,width=[width_to_crop],height=[height_to_crop] | ||
- syntax #2: [ImageURL]?im=Crop,size=([width_to_crop],[height_to_crop] | ||
- **Positionable Crop** | ||
- syntax: [ImageURL]?im=Crop,rect=([xPostion],[yPosition],[width_to_crop],[height_to_crop]) | ||
- **Region of interest Crop** | ||
- syntax: [ImageURL]?im=RegionOfInterestCrop,width=[value],height=[value],regionOfInterest=width=[value],height=[value] | ||
- **Resize** | ||
- syntax #1: [ImageURL]?im=Resize,width=[resized_width],height=[resized_height] | ||
- syntax #2: [ImageURL]?im=Resize=([resized_width],[resized_height]) | ||
- syntax #3: [ImageURL]?im=Resize,width=[resized_width] | ||
- syntax #3: [ImageURL]?im=Resize,height=[resized_height] | ||
- **Watermark** | ||
- syntax minimum: [ImageURL]?im=Composite,image=(url=[url_to_the_image_text_or_shape]) | ||
- syntax position: [ImageURL]?im=Composite,xPosition=[value],yPosition=[value],image=(url=[url_to_the_image_text_or_shape]) | ||
- syntax scaling: [ImageURL]?im=Composite,scaleDimension=[height/width],scale=[value],image=(url=[url_to_the_image_text_or_shape]) | ||
- **Text Watermark** | ||
- syntax minimum: [ImageURL]?im=Composite,image=(type=Text,text=[URL_encoded_string]) | ||
- syntax position: [ImageURL]?im=Composite,xPosition=[value],yPosition=[value],gravity=[direction],image=(type=Text,text=[URL_encoded_string]) | ||
- syntax scale and color : [ImageURL]?im=Composite,image=(type=Text,text=[URL_encoded_string],size=[font_size],fill=[hex_color_value]) | ||
- **Background Color** | ||
- syntax: [ImageURL]?im=BackgroundColor,color=[hex_color_value] | ||
#### Filerobot to Akamai | ||
- **Rotate** | ||
- syntax: [ImageURL]?r=[number_of_degrees]) | ||
- **Auto Crop** | ||
- syntax #1: [ImageURL]?w=[width_to_crop]&h=[height_to_crop] | ||
- **Positionable Crop** | ||
- syntax: [ImageURL]?tl=[x1Position],[y1Position]&br[x2Position],[y2Position] | ||
- **Region of interest Crop** | ||
- syntax: [ImageURL]?w=[width_to_crop]&h=[height_to_crop]&gravity=[xPosition],[yPosition] | ||
- **Resize** | ||
- syntax #1: [ImageURL]?w=[resized_width]&h=[resized_height] | ||
- syntax #2: [ImageURL]?w=[resized_width] | ||
- syntax #3: [ImageURL]?h=[resized_height] | ||
- **Watermark** | ||
- syntax minimum: [ImageURL]?=wat=1&wat_url=[url_to_the_image_text_or_shape] | ||
- syntax position: [ImageURL]?=wat=1&wat_url=[url_to_the_image_text_or_shape]&wat_pad=[xPosition],[yPosition]&gravity=[direction] | ||
- syntax scaling: [ImageURL]?=wat=1&wat_url=[url_to_the_image_text_or_shape]&wat_scale=[scale_valuetion] | ||
- **Text Watermark** | ||
- syntax minimum: [ImageURL]?=wat=1&wat_text=[URL_encoded_string] | ||
- syntax position: [ImageURL]?=wat=1&wat_text=[URL_encoded_string]&wat_pad=[xPosition],[yPosition]&gravity=[direction] | ||
- syntax scaling and coloring: [ImageURL]?=wat=1&wat_text=[URL_encoded_string]&wat_fontsize=[font_size]&wat_color=[hex_color_value] | ||
- **Background Color** | ||
- syntax: [ImageURL]?bg_colour=[hex_color_value] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37742
25
565
135
13