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
holeWidthintThe width of the final image to be returned.
holeHeightintThe height of the final image to be returned.
Returns
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
holeWidthintThe width of the final image to be returned.
holeHeightintThe height of the final image to be returned.
userIdintThe id of the user whose avatar is returned.
Returns
GetBestFit(string, int, int)
[Obsolete("Use ResizeAndCrop()", false)]
public abstract string GetBestFit(string imagePathFilename, int holeWidth, int holeHeight)
Parameters
Returns
GetBestFit(string, int, int, List<string>)
[Obsolete("Use ResizeAndCrop()", false)]
public abstract string GetBestFit(string imagePathFilename, int holeWidth, int holeHeight, List<string> imageAltSizeList)
Parameters
Returns
GetBestFitWebP(string, int, int)
[Obsolete("Use ResizeAndCrop()", false)]
public abstract string GetBestFitWebP(string imagePathFilename, int holeWidth, int holeHeight)
Parameters
Returns
GetBestFitWebP(string, int, int, List<string>)
[Obsolete("Use ResizeAndCrop()", false)]
public abstract string GetBestFitWebP(string imagePathFilename, int holeWidth, int holeHeight, List<string> imageAltSizeList)
Parameters
Returns
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
imagePathFilenamestringCDN path to the original image (no prefix).
holeWidthintThe max display width in pixels (used as largest srcset size).
holeHeightintThe display height at holeWidth (0 = auto/proportional).
imageAltSizesstringJSON 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
imagePathFilenamestringThe source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).
holeWidthintThe width of the final image in pixels, or 0 for proportional sizing.
holeHeightintThe height of the final image in pixels, or 0 for proportional sizing.
Returns
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
imagePathFilenamestringThe source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).
holeWidthintThe width of the final image in pixels, or 0 for proportional sizing.
holeHeightintThe height of the final image in pixels, or 0 for proportional sizing.
imageAltSizesstringComma-delimited list: first entry is the source filename, remaining entries are generated sizes in the format "widthxheight".
isNewSizeboolIf true, a new size was added and you must save the imageAltSizes string back
Returns
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
imagePathFilenamestringThe source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).
holeWidthintThe width of the final image in pixels, or 0 for proportional sizing.
holeHeightintThe height of the final image in pixels, or 0 for proportional sizing.
Returns
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
imagePathFilenamestringThe source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).
holeWidthintThe width of the final image in pixels, or 0 for proportional sizing.
holeHeightintThe height of the final image in pixels, or 0 for proportional sizing.
imageAltSizesstringA list of image sizes already created. Save this string with the original image URL.
isNewSizeboolIf true, a new size was added and you must save the imageAltSize string back
Returns
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
imagePathFilenamestringThe source image in CdnFiles.
holeWidthintTarget width in pixels, or 0 for proportional sizing.
holeHeightintTarget height in pixels, or 0 for proportional sizing.
imageAltSizesstringJSON 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
imagePathFilenamestringThe source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).
holeWidthintThe width of the final image in pixels, or 0 for proportional sizing.
holeHeightintThe height of the final image in pixels, or 0 for proportional sizing.
Returns
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
imagePathFilenamestringThe source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).
holeWidthintThe width of the final image in pixels, or 0 for proportional sizing.
holeHeightintThe height of the final image in pixels, or 0 for proportional sizing.
imageAltSizesstringComma-delimited list: first entry is the source filename, remaining entries are generated sizes in the format "widthxheight".
isNewSizeboolIf true, a new size was added and you must save the imageAltSizes string back
Returns
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
imagePathFilenamestringThe source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).
holeWidthintThe width of the final image in pixels, or 0 for proportional sizing.
holeHeightintThe height of the final image in pixels, or 0 for proportional sizing.
Returns
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
imagePathFilenamestringThe source image. Expected to be in CdnFiles (accessible with CP.CdnFiles methods).
holeWidthintThe width of the final image in pixels, or 0 for proportional sizing.
holeHeightintThe height of the final image in pixels, or 0 for proportional sizing.
imageAltSizesstringComma-delimited list: first entry is the source filename, remaining entries are generated sizes in the format "widthxheight".
isNewSizeboolIf true, a new size was added and you must save the imageAltSizes string back