UNPKG

@cloudinary/url-gen

Version:

Cloudinary URL-Gen SDK ========================= [![Build Status](https://api.travis-ci.com/cloudinary/js-url-gen.svg?branch=master)](https://app.travis-ci.com/github/cloudinary/js-url-gen) ## About The Cloudinary URL-Gen SDK allows you to quickly and eas

71 lines (67 loc) 2.72 kB
'use strict'; var QualifierValue = require('./QualifierValue-e770d619.cjs'); var Action = require('./Action-34aa7481.cjs'); var Qualifier = require('./Qualifier-6633a22f.cjs'); /** * @description - This Action, while belonging to Effect, acts as a modified overlay. * The class implements the Builder pattern, where strength() and preserveColor() * are applied to the instance, and toString() is responsible to combining them into the right result. * @extends SDK.Action * @memberOf Actions.Effect * @see Visit {@link Actions.Effect|Effect} for an example */ class StyleTransfer extends Action.Action { /** * The Image Source used to create the style transfer, * Use the Image Source builder to quickly create a source: * </br>Import: {@link Qualifiers.Source|import Sources from '@cloudinary/url-gen/qualifiers/sources';} * </br>Create: `Source.image('dog')` * @param {ImageSource} imageSource */ constructor(imageSource) { super(); this.imageSource = imageSource; } /** * Determines the strength in which the styleTransfer is applied. * @param {number} [effectStrength] - The strength level, 1-100, default: 100 * @return {this} */ strength(effectStrength = null) { this.effectStrength = effectStrength; return this; } /** * More aggressively preserves the colors of the the target photo, * Can be used with `strength()` to enhance this behaviour * @param {boolean} bool * @return {this} */ preserveColor(bool = true) { this.preserve = bool; return this; } /** * The `build` phase of the Action, used internally to concat all the options received into a single string. * The result of this method is the toString() of the imageLayer provided in the constructor. * @return {string} */ toString() { const NAME = 'style_transfer'; const PRES = this.preserve ? 'preserve_color' : null; const STRENGTH = this.effectStrength; // Create the style effect const styleEffect = new Qualifier.Qualifier('e', new QualifierValue.QualifierValue([NAME, PRES, STRENGTH])); // Handle the source for publicID, const sourceOpenString = this.imageSource.getOpenSourceString('l'); // Handle source transformation const imgTx = this.imageSource.getTransformation(); const sourceTransformation = imgTx ? imgTx.toString() : ''; return [ sourceOpenString, sourceTransformation, `${styleEffect},fl_layer_apply` ].filter((a) => a).join('/'); } } exports.StyleTransfer = StyleTransfer;