Custom Image Helpers

December 13, 2018 ยท View on GitHub

These helpers provide some ability to manage existing image urls.


Helpers.Image.BuildImageUrl

SummaryConstructs a new image url with supplied parameter values
ReturnsA new image url
RemarksIf first argument is not an image url, it will return an empty string
Parameters
inputImage url to manipulate
argumentsList of available arguments are below

Available Arguments

Flags
c, cropCrop the image to width and height specified. Acceptable values are 1 or 0.
cc, cropCenterCenter the crop rectangle before cropping. Acceptable values are 1 or 0.
f, fillInstead of resizing, fill any overflow. Default color if not specified is transparent if the image has an Alpha channel, otherwise white. Acceptable values are 1 or 0.
fz, fillZoomResize image first, then fill any overflow. Using this requires using both width/height and maxWidth/maxHeight. Acceptable values are 1 or 0.
Options
fc, fillColorHex code that corresponds to the html color code used when overflows are being filled.
q, qualityQuality [0-100] of the resized image. Applies when resizing.
Dimensions
w, widthWidth of the image. Aspect ratio will be maintained if no height is specified. If max height is specified but is smaller than the resized yet maintained aspect ratio, the image will resize to a height of maxHeight.
h, heightHeight of the image. Aspect ratio will be maintained if no width is specified. If max width is specified but is smaller than the resized yet maintained aspect ratio, the image will resize to a width of maxWidth.
mw, maxWidthMax width of the image. This sets and upper bound to the size of the image.
mh, maxHeightMax height of the image. This sets and upper bound to the size of the image.

Example

Context

{
    "url": "//cdnmedia.endeavorsuite.com/images/ThumbGenerator/Thumb.aspx?img=%2f%2fcdnmedia.endeavorsuite.com%2fimages%2forganizations%2f2c3b7a35-5cb3-49f2-a511-9764f98f9fce%2finventory%2f2538342%2fDSC02149.JPG&mw=100&mh=100"
}

Usage

<img src="{{Helpers.Image.BuildImageUrl url width=400 height=400 c=1}}" />

Returns

<img src="//cdnmedia.endeavorsuite.com/images/ThumbGenerator/Thumb.aspx?img=%2F%2Fcdnmedia.endeavorsuite.com%2Fimages%2Forganizations%2F2c3b7a35-5cb3-49f2-a511-9764f98f9fce%2Finventory%2F2538342%2FDSC02149.JPG&c=1&h=400&w=400" />

Helpers.Image.GetBaseImageUrl

SummaryAttempt to extract the base url from an existing image path. For example, you can use this to pull the original url out of a thumbGenerator path
ReturnsThe base image url
RemarksIf first argument is not an image url, it will return an empty string
Parameters
inputImage url to extract the base url from

Example

Context

{
    "url": "//cdnmedia.endeavorsuite.com/images/ThumbGenerator/Thumb.aspx?img=%2f%2fcdnmedia.endeavorsuite.com%2fimages%2forganizations%2f2c3b7a35-5cb3-49f2-a511-9764f98f9fce%2finventory%2f2538342%2fDSC02149.JPG&mw=100&mh=100"
}

Usage

<img src="{{Helpers.Image.BuildImageUrl url}}" />

Returns

<img src="//cdnmedia.endeavorsuite.com/images/organizations/2c3b7a35-5cb3-49f2-a511-9764f98f9fce/inventory/2538342/DSC02149.JPG" />