{ "version": 3, "sources": ["libs/image-transformation/src/lib/image-transformation.service.ts", "libs/image-transformation/src/lib/image-transformation.module.ts", "libs/image-transformation/src/lib/image-transformation.ts"], "sourcesContent": ["/**\n * This file performs various transformations on provided images or image serving URLs.\n *\n * Usage:\n * In Typescript\n * private transformation: ImageTransformation = new ImageTransformation()\n * .crop()\n * .flipHorizontally(); // Can chain transformation functions indefinitely.\n * private sizes: number[] = [128, 256, 512];\n * private url: string = 'https://someurl.com';\n *\n * In HTML\n * \n */\nimport { Injectable } from '@angular/core';\nimport { ImageTransformation } from './image-transformation';\n\nexport const SERVING_URL_DOMAINS: string[] = ['lh3.googleusercontent.com'];\n\n@Injectable()\nexport class ImageTransformationService {\n /**\n * Determines whether the given URL is a Google Serving URL.\n * @param url The URL to check.\n * @returns True if it is a Google Serving URL, otherwise False.\n */\n public isServingUrl(url: string): boolean {\n if (url) {\n for (const s of SERVING_URL_DOMAINS) {\n const protocolIndex = url.indexOf('://');\n const domain = protocolIndex > -1 ? url.substring(protocolIndex + 3) : url;\n if (domain.startsWith(s)) {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * Generates and returns a new URL that applies the specified transformation(s) to the provided image. If the image\n * is not a Google Serving URL, it is returned unchanged.\n * @param baseUrl The URL of the image to apply transformations to.\n * @param transformation An object containing all of the transformation flags to apply.\n */\n public getTransformedImage(baseUrl: string, transformation: ImageTransformation): string {\n if (!baseUrl) {\n return null;\n }\n const isServingUrl: boolean = this.isServingUrl(baseUrl);\n if (!isServingUrl || !transformation) {\n return baseUrl;\n }\n const transformationString = transformation.hasFlags() ? `=${transformation.getFlags()}` : '';\n return `${baseUrl}${transformationString}`;\n }\n\n /**\n * Creates a string of URLs to use as srcset options. One option will be created for each size provided with each option\n * containing all of the additional flags specified by the ImageTransformation object. If no sizes are provided or if the\n * baseUrl is not a Google Serving URL, the original baseUrl is returned unchanged.\n * @param baseUrl The base URL of the image.\n * @param sizes An array of widths in pixels the image is to be made available in.\n * @param transformation An optional object containing a set of additional transformation flags to set.\n * Omit or use null to display the images with no transformations.\n */\n public getSrcSetForImage(\n baseUrl: string,\n sizes: number[] = null,\n transformation: ImageTransformation = null,\n ): string {\n if (!baseUrl) {\n return null;\n }\n\n const isServingUrl: boolean = this.isServingUrl(baseUrl);\n if (!isServingUrl || !sizes || sizes.length === 0) {\n return baseUrl;\n }\n\n let srcset = '';\n const transformationString = transformation ? transformation.getFlags() : '';\n sizes.forEach((size) => {\n if (srcset.length > 0) {\n srcset += ', ';\n }\n srcset += `${baseUrl}=s${size}${transformationString} ${size}w`;\n });\n return srcset;\n }\n}\n", "import { NgModule } from '@angular/core';\n\nimport { ImageTransformationService } from './image-transformation.service';\n\n@NgModule({\n providers: [ImageTransformationService],\n})\nexport class ImageTransformationModule {}\n", "/**\n * Helper object for building the flags for performing one or many various transformations on an image served by Google.\n * Intended to be used in conjunction with the ImageTransformationService.\n *\n * Google's image transformation API is not very well documented at the moment so all of these flags have come from\n * https://stackoverflow.com/questions/25148567/list-of-all-the-app-engine-images-service-get-serving-url-uri-options.\n *\n * Usage:\n * In Typescript\n * private transformation: ImageTransformation = new ImageTransformation()\n * .crop()\n * .flipHorizontally(); // Can chain transformation functions indefinitely.\n * private sizes: number[] = [128, 256, 512];\n * private url: string = 'https://someurl.com';\n *\n * In HTML\n * \n */\n\nexport class ImageTransformation {\n private flags: string;\n\n constructor() {\n this.flags = '';\n }\n\n /**\n * Adds a flag, specifying that the image should be resized using the provided size. The size will be applied to the\n * largest dimension (height for images in portrait and width for images in landscape).\n * @param size The size in pixels that the longest side should be set to.\n */\n resize(size: number): ImageTransformation {\n this.flags += `s${size}`;\n return this;\n }\n\n /**\n * Adds a flag, specifying that the image should be cropped to be a square whose size depends on the size of the shortest side.\n */\n crop(): ImageTransformation {\n this.flags += '-c';\n return this;\n }\n\n /**\n * Same as crop() except the image attempts to crop around faces.\n */\n smartCrop(): ImageTransformation {\n this.flags += '-p';\n return this;\n }\n\n /**\n * Same as crop() except the image is cropped as a circle instead of a square.\n */\n circularCrop(): ImageTransformation {\n this.flags += '-cc';\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should be flipped vertically.\n */\n flipVertically(): ImageTransformation {\n this.flags += '-fv';\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should be flipped horiztonally.\n */\n flipHorizontally(): ImageTransformation {\n this.flags += '-fh';\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should be rotated the specified number of degrees.\n * @param degrees How many degrees the image should be rotated by. Should be one of 90, 180 or 270.\n */\n rotate(degrees: 90 | 180 | 270): ImageTransformation {\n this.flags += `-r${degrees}`;\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should be rendered as a JPEG.\n */\n renderAsJpeg(): ImageTransformation {\n this.flags += '-rj';\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should be rendered as a PNG\n */\n renderAsPng(): ImageTransformation {\n this.flags += '-rp';\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should be rendered as a WEBP\n */\n renderAsWebP(): ImageTransformation {\n this.flags += '-rw';\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should be rendered as a GIF\n */\n renderAsGif(): ImageTransformation {\n this.flags += '-rg';\n return this;\n }\n\n /**\n * Adds a flag specifying that a GIF should be converted into and rendered as an MP4 movie.\n */\n makeMp4(): ImageTransformation {\n this.flags += '-rh';\n return this;\n }\n\n /**\n * Adds a flag specifying that a GIF should not be animated and show a static image instead.\n */\n killAnimation(): ImageTransformation {\n this.flags += '-k';\n return this;\n }\n\n /**\n * Adds a flag specifying that a border of the specified width should be added to the image.\n * @param width The width of the border in pixels.\n */\n addBorder(width: number): ImageTransformation {\n this.flags += `-b${width}`;\n return this;\n }\n\n /**\n * Adds a flag specifying what the colour of the border should be.\n * @param argbHex The hexadecimal representation of the colour, in the format AARRGGBB.\n */\n setBorderColour(argbHex: string): ImageTransformation {\n this.flags += `-c0x${argbHex}`;\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should include a header to cause the browser to download it.\n */\n makeDownloadable(): ImageTransformation {\n this.flags += '-d';\n return this;\n }\n\n /**\n * Adds a flag specifying that the quality of the rendered JPEG image should be set to the specified percent.\n * @param qualityPercent A number from 0-100 representing the percent of quality the JPEG should be.\n */\n setJpegQuality(qualityPercent: number): ImageTransformation {\n this.flags += `-l${qualityPercent}`;\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should be softened by the specified amount.\n * @param softenPct\n\n */\n soften(softenPct: number): ImageTransformation {\n this.flags += `-fSoften=1,${softenPct},0`;\n return this;\n }\n\n /**\n * Adds a flag specifying that a vignette should be added to the image with the specified size and colour.\n * @param gradientSize\n * @param argbHex\n */\n vignette(gradientSize: number, argbHex: string): ImageTransformation {\n this.flags += `-fVignette=1,${gradientSize},1.4,0,${argbHex}`;\n return this;\n }\n\n /**\n * Adds a flag specifying that the colours in the image should be inverted.\n */\n invert(): ImageTransformation {\n this.flags += `-fInvert=1`;\n return this;\n }\n\n /**\n * Adds a flag specifying that the image should be converted to black and white.\n */\n blackAndWhite(): ImageTransformation {\n this.flags += `-fbw=1`;\n return this;\n }\n\n /**\n * Returns the current set of flags that have been set as a single string that can be appended to a serving URL.\n */\n getFlags(): string {\n return this.flags;\n }\n\n /**\n * Gets a value indicating whether this transformation currently has any flags set.\n */\n hasFlags(): boolean {\n return this.flags.length > 0;\n }\n}\n"], "mappings": "yDAiBO,IAAMA,EAAgC,CAAC,2BAA2B,EAG5DC,GAA0B,IAAA,CAAjC,IAAOA,EAAP,MAAOA,CAA0B,CAM9BC,aAAaC,EAAW,CAC7B,GAAIA,EACF,QAAWC,KAAKJ,EAAqB,CACnC,IAAMK,EAAgBF,EAAIG,QAAQ,KAAK,EAEvC,IADeD,EAAgB,GAAKF,EAAII,UAAUF,EAAgB,CAAC,EAAIF,GAC5DK,WAAWJ,CAAC,EACrB,MAAO,EAEX,CAEF,MAAO,EACT,CAQOK,oBAAoBC,EAAiBC,EAAmC,CAC7E,GAAI,CAACD,EACH,OAAO,KAGT,GAAI,CAD0B,KAAKR,a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,CAAO,GACnB,IACT,CAKAC,cAAY,CACV,YAAKV,OAAS,MACP,IACT,CAKAW,aAAW,CACT,YAAKX,OAAS,MACP,IACT,CAKAY,cAAY,CACV,YAAKZ,OAAS,MACP,IACT,CAKAa,aAAW,CACT,YAAKb,OAAS,MACP,IACT,CAKAc,SAAO,CACL,YAAKd,OAAS,MACP,IACT,CAKAe,eAAa,CACX,YAAKf,OAAS,KACP,IACT,CAMAgB,UAAUC,EAAa,CACrB,YAAKjB,OAAS,KAAKiB,CAAK,GACjB,IACT,CAMAC,gBAAgBC,EAAe,CAC7B,YAAKnB,OAAS,OAAOmB,CAAO,GACrB,IACT,CAKAC,kBAAgB,CACd,YAAKpB,OAAS,KACP,IACT,CAMAqB,eAAeC,EAAsB,CACnC,YAAKtB,OAAS,KAAKsB,CAAc,GAC1B,IACT,CAOAC,OAAOC,EAAiB,CACtB,YAAKxB,OAAS,cAAcwB,CAAS,KAC9B,IACT,CAOAC,SAASC,EAAsBP,EAAe,CAC5C,YAAKnB,OAAS,gBAAgB0B,CAAY,UAAUP,CAAO,GACpD,IACT,CAKAQ,QAAM,CACJ,YAAK3B,OAAS,aACP,IACT,CAKA4B,eAAa,CACX,YAAK5B,OAAS,SACP,IACT,CAKA6B,UAAQ,CACN,OAAO,KAAK7B,KACd,CAKA8B,UAAQ,CACN,OAAO,KAAK9B,MAAM+B,OAAS,CAC7B", "names": ["SERVING_URL_DOMAINS", "ImageTransformationService", "isServingUrl", "url", "s", "protocolIndex", "indexOf", "substring", "startsWith", "getTransformedImage", "baseUrl", "transformation", "transformationString", "hasFlags", "getFlags", "getSrcSetForImage", "sizes", "length", "srcset", "forEach", "size", "factory", "\u0275fac", "_ImageTransformationService", "ImageTransformationModule", "ImageTransformationService", "_ImageTransformationModule", "ImageTransformation", "constructor", "flags", "resize", "size", "crop", "smartCrop", "circularCrop", "flipVertically", "flipHorizontally", "rotate", "degrees", "renderAsJpeg", "renderAsPng", "renderAsWebP", "renderAsGif", "makeMp4", "killAnimation", "addBorder", "width", "setBorderColour", "argbHex", "makeDownloadable", "setJpegQuality", "qualityPercent", "soften", "softenPct", "vignette", "gradientSize", "invert", "blackAndWhite", "getFlags", "hasFlags", "length"] }