Table of Contents

Class CPImageBaseClass

Namespace
Contensive.BaseClasses
Assembly
CPBase.dll

Image resizing, cropping, and padding methods.

ResizeAndCrop: Resize the image so its smallest dimension fills the target hole, then crop the overflow on the larger dimension (centered). The result completely fills the hole with no letterboxing.

ResizeAndPad: Resize the image so its largest dimension fits the target hole, then pad the remaining space with transparency. The entire image is visible.

holeWidth / holeHeight behavior:

  • Both > 0: Resize and crop (or pad) to the exact target dimensions.
  • One is 0: Resize proportionally using the non-zero dimension. No crop or pad is performed. Use this for "As-Is" aspect ratio where the image keeps its natural proportions.
  • Both are 0: No resize; the original image path is returned.

Images are never scaled up. If the target is larger than the source, the source is cropped (or padded) to the target proportions at its original resolution.

Methods ending in "NoTypeChange" preserve the source image format. Methods without that suffix convert to WebP format.

public abstract class CPImageBaseClass
Inheritance
CPImageBaseClass
Inherited Members

Methods

GetAvatarCdnPathFilename(int, int)

Return the avatar CDN pathFilename for the current user, resized to the provided dimensions. To use the returned pathFilename as a link, prefix it with CP.Http.CdnFilePathPrefixAbsolute. To access the file directly, use CP.CdnFiles.

public abstract string GetAvatarCdnPathFilename(int holeWidth, int holeHeight)

Parameters

holeWidth int

The width of the final image to be returned.

holeHeight int

The height of the final image to be returned.

Returns

string

GetAvatarCdnPathFilename(int, int, int)

Return the avatar CDN pathFilename for the provided user, resized to the provided dimensions. To use the returned pathFilename as a link, prefix it with CP.Http.CdnFilePathPrefixAbsolute. To access the file directly, use CP.CdnFiles.

public abstract string GetAvatarCdnPathFilename(int holeWidth, int holeHeight, int userId)

Parameters

holeWidth int

The width of the final image to be returned.

holeHeight int

The height of the final image to be returned.

userId int

The id of the user whose avatar is returned.

Returns

string

GetBestFit(string, int, int)

[Obsolete("Use ResizeAndCrop()", false)]
public abstract string GetBestFit(string imagePathFilename, int holeWidth, int holeHeight)

Parameters

imagePathFilename string
holeWidth int
holeHeight int

Returns

string

GetBestFit(string, int, int, List<string>)

[Obsolete("Use ResizeAndCrop()", false)]
public abstract string GetBestFit(string imagePathFilename, int holeWidth, int holeHeight, List<string> imageAltSizeList)

Parameters

imagePathFilename string
holeWidth int
holeHeight int
imageAltSizeList List<string>

Returns

string

GetBestFitWebP(string, int, int)

[Obsolete("Use ResizeAndCrop()", false)]
public abstract string GetBestFitWebP(string imagePathFilename, int holeWidth, int holeHeight)

Parameters

imagePathFilename string
holeWidth int
holeHeight int

Returns

string

GetBestFitWebP(string, int, int, List<string>)

[Obsolete("Use ResizeAndCrop()", false)]
public abstract string GetBestFitWebP(string imagePathFilename, int holeWidth, int holeHeight, List<string> imageAltSizeList)

Parameters

imagePathFilename string
holeWidth int
holeHeight int
imageAltSizeList List<string>

Returns

string

GetImgSrcSet(string, int, int, ref string)

Generate responsive img srcset/sizes attributes for the given image. Creates multiple resized WebP variants at standard breakpoints and returns the attribute values needed for a responsive img tag.

public abstract CPImageBaseClass.ImgSrcSetResult GetImgSrcSet(string imagePathFilename, int holeWidth, int holeHeight, ref string imageAltSizes)

Parameters

imagePathFilename string

CDN path to the original image (no prefix).

holeWidth int

The max display width in pixels (used as largest srcset size).

holeHeight int

The display height at holeWidth (0 = auto/proportional).

imageAltSizes string

JSON string tracking generated sizes. Save back if changed.

Returns

CPImageBaseClass.ImgSrcSetResult

ImgSrcSetResult with src, srcset, sizes, imageWidth, and imageHeight.

ResizeAndCrop(string, int, int)

Return an image in .webP format resized so its smallest dimension fits the hole, and the other dimension cropped (centered). If either holeWidth or holeHeight is 0, the image is resized proportionally by the non-zero dimension with no crop. The image is never scaled up.

public abstract string ResizeAndCrop(string imagePathFilename, int holeWidth, int holeHeight)

Parameters

imagePathFilename string

The source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).

holeWidth int

The width of the final image in pixels, or 0 for proportional sizing.

holeHeight int

The height of the final image in pixels, or 0 for proportional sizing.

Returns

string

ResizeAndCrop(string, int, int, ref string, out bool)

Return an image in .webP format resized so its smallest dimension fits the hole, and the other dimension cropped (centered). If either holeWidth or holeHeight is 0, the image is resized proportionally by the non-zero dimension with no crop. The image is never scaled up. If the hole is larger than the image, the original is cropped to target proportions.

public abstract string ResizeAndCrop(string imagePathFilename, int holeWidth, int holeHeight, ref string imageAltSizes, out bool isNewSize)

Parameters

imagePathFilename string

The source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).

holeWidth int

The width of the final image in pixels, or 0 for proportional sizing.

holeHeight int

The height of the final image in pixels, or 0 for proportional sizing.

imageAltSizes string

Comma-delimited list: first entry is the source filename, remaining entries are generated sizes in the format "widthxheight".

isNewSize bool

If true, a new size was added and you must save the imageAltSizes string back

Returns

string

ResizeAndCropNoTypeChange(string, int, int)

Return an image resized so its smallest dimension fits the hole, and the other dimension cropped (centered). Output preserves the source image format (no type conversion). If either holeWidth or holeHeight is 0, the image is resized proportionally by the non-zero dimension with no crop. The image is never scaled up.

public abstract string ResizeAndCropNoTypeChange(string imagePathFilename, int holeWidth, int holeHeight)

Parameters

imagePathFilename string

The source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).

holeWidth int

The width of the final image in pixels, or 0 for proportional sizing.

holeHeight int

The height of the final image in pixels, or 0 for proportional sizing.

Returns

string

ResizeAndCropNoTypeChange(string, int, int, ref string, out bool)

Return an image resized so its smallest dimension fits the hole, and the other dimension cropped (centered). Output preserves the source image format (no type conversion). If either holeWidth or holeHeight is 0, the image is resized proportionally by the non-zero dimension with no crop. The image is never scaled up. If the hole is larger than the image, the original is cropped to the target proportions. The source imagePathFilename is expected to be in the CdnFiles filesystem. The new image is saved back to the same path.

public abstract string ResizeAndCropNoTypeChange(string imagePathFilename, int holeWidth, int holeHeight, ref string imageAltSizes, out bool isNewSize)

Parameters

imagePathFilename string

The source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).

holeWidth int

The width of the final image in pixels, or 0 for proportional sizing.

holeHeight int

The height of the final image in pixels, or 0 for proportional sizing.

imageAltSizes string

A list of image sizes already created. Save this string with the original image URL.

isNewSize bool

If true, a new size was added and you must save the imageAltSize string back

Returns

string

ResizeAndCropWithDimensions(string, int, int, ref string)

Resize and crop an image, returning actual output dimensions along with the CDN path. Use this when you need to know the actual pixel dimensions of the resized image (e.g., to populate width/height attributes on an img tag).

public abstract CPImageBaseClass.ImageResizeResult ResizeAndCropWithDimensions(string imagePathFilename, int holeWidth, int holeHeight, ref string imageAltSizes)

Parameters

imagePathFilename string

The source image in CdnFiles.

holeWidth int

Target width in pixels, or 0 for proportional sizing.

holeHeight int

Target height in pixels, or 0 for proportional sizing.

imageAltSizes string

JSON string tracking generated sizes. Save back if isNewSize is true.

Returns

CPImageBaseClass.ImageResizeResult

ImageResizeResult with path, actual width, actual height, and isNewSize flag.

ResizeAndPad(string, int, int)

Return an image in .webP format resized so its largest dimension fits the hole, and the other dimension padded transparent. If either holeWidth or holeHeight is 0, the image is resized proportionally by the non-zero dimension with no pad. The image is never scaled up.

public abstract string ResizeAndPad(string imagePathFilename, int holeWidth, int holeHeight)

Parameters

imagePathFilename string

The source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).

holeWidth int

The width of the final image in pixels, or 0 for proportional sizing.

holeHeight int

The height of the final image in pixels, or 0 for proportional sizing.

Returns

string

ResizeAndPad(string, int, int, ref string, out bool)

Return an image in .webP format resized so its largest dimension fits the hole, and the other dimension padded transparent. If either holeWidth or holeHeight is 0, the image is resized proportionally by the non-zero dimension with no pad. The image is never scaled up.

public abstract string ResizeAndPad(string imagePathFilename, int holeWidth, int holeHeight, ref string imageAltSizes, out bool isNewSize)

Parameters

imagePathFilename string

The source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).

holeWidth int

The width of the final image in pixels, or 0 for proportional sizing.

holeHeight int

The height of the final image in pixels, or 0 for proportional sizing.

imageAltSizes string

Comma-delimited list: first entry is the source filename, remaining entries are generated sizes in the format "widthxheight".

isNewSize bool

If true, a new size was added and you must save the imageAltSizes string back

Returns

string

ResizeAndPadNoTypeChange(string, int, int)

Return an image resized so its largest dimension fits the hole, and the other dimension padded transparent. Output preserves the source image format (no type conversion). If either holeWidth or holeHeight is 0, the image is resized proportionally by the non-zero dimension with no pad. The image is never scaled up.

public abstract string ResizeAndPadNoTypeChange(string imagePathFilename, int holeWidth, int holeHeight)

Parameters

imagePathFilename string

The source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).

holeWidth int

The width of the final image in pixels, or 0 for proportional sizing.

holeHeight int

The height of the final image in pixels, or 0 for proportional sizing.

Returns

string

ResizeAndPadNoTypeChange(string, int, int, ref string, out bool)

Return an image resized so its largest dimension fits the hole, and the other dimension padded transparent. Output preserves the source image format (no type conversion). If either holeWidth or holeHeight is 0, the image is resized proportionally by the non-zero dimension with no pad. The image is never scaled up.

public abstract string ResizeAndPadNoTypeChange(string imagePathFilename, int holeWidth, int holeHeight, ref string imageAltSizes, out bool isNewSize)

Parameters

imagePathFilename string

The source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).

holeWidth int

The width of the final image in pixels, or 0 for proportional sizing.

holeHeight int

The height of the final image in pixels, or 0 for proportional sizing.

imageAltSizes string

Comma-delimited list: first entry is the source filename, remaining entries are generated sizes in the format "widthxheight".

isNewSize bool

If true, a new size was added and you must save the imageAltSizes string back

Returns

string