LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
Transform, scale and rotate

Data Structures

struct  gdAutoCropOptions
 Options for automatic cropping. More...
 
struct  gdScaleOptions
 

Macros

#define GD_SCALE_INTERPOLATION_AUTO   -1
 Let gdImageScaleWithOptions choose the interpolation method from the scale direction.
 

Enumerations

enum  gdInterpolationMethod {
  GD_DEFAULT = 0 , GD_BELL , GD_BESSEL , GD_BILINEAR_FIXED ,
  GD_BICUBIC , GD_BICUBIC_FIXED , GD_BLACKMAN , GD_BOX ,
  GD_BSPLINE , GD_CATMULLROM , GD_GAUSSIAN , GD_GENERALIZED_CUBIC ,
  GD_HERMITE , GD_HAMMING , GD_HANNING , GD_MITCHELL ,
  GD_NEAREST_NEIGHBOUR , GD_POWER , GD_QUADRATIC , GD_SINC ,
  GD_TRIANGLE , GD_WEIGHTED4 , GD_LINEAR , GD_LANCZOS3 ,
  GD_LANCZOS8 , GD_BLACKMAN_BESSEL , GD_BLACKMAN_SINC , GD_QUADRATIC_BSPLINE ,
  GD_CUBIC_SPLINE , GD_COSINE , GD_WELSH , GD_METHOD_COUNT = 30
}
 gdInterpolationMethod More...
 
enum  gdCropMode {
  GD_CROP_DEFAULT = 0 , GD_CROP_TRANSPARENT , GD_CROP_BLACK , GD_CROP_WHITE ,
  GD_CROP_SIDES , GD_CROP_THRESHOLD
}
 
enum  gdScaleFit {
  GD_SCALE_FIT_COVER , GD_SCALE_FIT_CONTAIN , GD_SCALE_FIT_FILL , GD_SCALE_FIT_INSIDE ,
  GD_SCALE_FIT_OUTSIDE
}
 
enum  gdScaleGravity {
  GD_SCALE_GRAVITY_NORTHWEST , GD_SCALE_GRAVITY_NORTH , GD_SCALE_GRAVITY_NORTHEAST , GD_SCALE_GRAVITY_WEST ,
  GD_SCALE_GRAVITY_CENTER , GD_SCALE_GRAVITY_EAST , GD_SCALE_GRAVITY_SOUTHWEST , GD_SCALE_GRAVITY_SOUTH ,
  GD_SCALE_GRAVITY_SOUTHEAST
}
 
enum  gdScaleStrategy { GD_SCALE_STRATEGY_NONE , GD_SCALE_STRATEGY_ENTROPY , GD_SCALE_STRATEGY_ATTENTION }
 
enum  gdInterestingMethod { GD_INTERESTING_ENTROPY , GD_INTERESTING_ATTENTION }
 Methods used to find an interesting crop region. More...
 
enum  gdAffineStandardMatrix {
  GD_AFFINE_TRANSLATE = 0 , GD_AFFINE_SCALE , GD_AFFINE_ROTATE , GD_AFFINE_SHEAR_HORIZONTAL ,
  GD_AFFINE_SHEAR_VERTICAL
}
 Standard affine matrix operations. More...
 

Functions

void gdImageFlipHorizontal (gdImagePtr im)
 Flip an image vertically.
 
void gdImageFlipVertical (gdImagePtr im)
 Flip an image horizontally.
 
void gdImageFlipBoth (gdImagePtr im)
 Flip an image vertically and horizontally.
 
gdImagePtr gdImageCrop (gdImagePtr src, const gdRect *crop)
 Crop an image to a given rectangle.
 
gdImagePtr gdImageCropAuto (gdImagePtr im, const unsigned int mode)
 Crop an image automatically.
 
gdImagePtr gdImageCropThreshold (gdImagePtr im, const unsigned int color, const float threshold)
 Crop an image using a given color.
 
gdImagePtr gdImageAutoCropWithOptions (gdImagePtr src, const gdAutoCropOptions *options)
 Crop an image automatically with options.
 
int gdImageSetInterpolationMethod (gdImagePtr im, gdInterpolationMethod id)
 Set the interpolation method stored on an image.
 
gdInterpolationMethod gdImageGetInterpolationMethod (gdImagePtr im)
 Return the interpolation method currently stored on an image.
 
gdImagePtr gdImageScale (const gdImagePtr src, const unsigned int new_width, const unsigned int new_height)
 Scale an image to an exact width and height using the source image's current gdInterpolationMethod.
 
gdImagePtr gdImageScaleWithOptions (const gdImagePtr src, const unsigned int new_width, const unsigned int new_height, const gdScaleOptions *options)
 Scale an image using aspect-ratio, gravity, crop-strategy and interpolation options.
 
int gdImageInterestingCropRegion (const gdImagePtr src, unsigned int target_width, unsigned int target_height, gdInterestingMethod method, gdRectPtr crop)
 Find a source crop region with the requested aspect ratio using an interesting-region method.
 
int gdImageEntropyCropRegion (const gdImagePtr src, unsigned int target_width, unsigned int target_height, gdRectPtr crop)
 Find a high-entropy source crop region with the requested aspect ratio.
 
gdImagePtr gdImageRotateInterpolated (const gdImagePtr src, const float angle, int bgcolor)
 Rotate an image by an arbitrary angle using the source image's current gdInterpolationMethod.
 
int gdAffineApplyToPointF (gdPointFPtr dst, const gdPointFPtr src, const double affine[6])
 Apply an affine matrix to a floating-point point.
 
int gdAffineInvert (double dst[6], const double src[6])
 Invert an affine matrix.
 
int gdAffineFlip (double dst_affine[6], const double src_affine[6], const int flip_h, const int flip_v)
 Build a horizontal and/or vertical flip from an affine matrix.
 
int gdAffineConcat (double dst[6], const double m1[6], const double m2[6])
 Concatenate two affine matrices.
 
int gdAffineIdentity (double dst[6])
 Store an identity affine matrix.
 
int gdAffineScale (double dst[6], const double scale_x, const double scale_y)
 Store a scale affine matrix.
 
int gdAffineRotate (double dst[6], const double angle)
 Store a rotation affine matrix.
 
int gdAffineShearHorizontal (double dst[6], const double angle)
 Store a horizontal shear affine matrix.
 
int gdAffineShearVertical (double dst[6], const double angle)
 Store a vertical shear affine matrix.
 
int gdAffineTranslate (double dst[6], const double offset_x, const double offset_y)
 Store a translation affine matrix.
 
double gdAffineExpansion (const double src[6])
 Return the linear expansion factor of an affine matrix.
 
int gdAffineRectilinear (const double src[6])
 Test whether an affine matrix preserves axis-aligned rectangles.
 
int gdAffineEqual (const double matrix1[6], const double matrix2[6])
 Compare two affine matrices.
 
int gdTransformAffineGetImage (gdImagePtr *dst, const gdImagePtr src, gdRectPtr src_area, const double affine[6])
 Apply an affine transform to a source region and create an image containing the complete transformed result.
 
int gdTransformAffineCopy (gdImagePtr dst, int dst_x, int dst_y, const gdImagePtr src, gdRectPtr src_region, const double affine[6])
 Apply an affine transform to a source region and copy the transformed pixels into an existing destination image.
 
int gdTransformAffineBoundingBox (gdRectPtr src, const double affine[6], gdRectPtr bbox)
 Compute the bounding box of a source rectangle after applying an affine transform.
 

Detailed Description

Image transformation APIs for interpolation, scaling, rotation and affine mapping.

Affine matrices use a six-element double array:

matrix[0] == xx matrix[1] == yx matrix[2] == xy matrix[3] == yy matrix[4] == x0 matrix[5] == y0

A point (x, y) is transformed as:

x_new = xx * x + xy * y + x0 y_new = yx * x + yy * y + y0

Matrix functions to initialize, transform and combine affine matrices used by transform, scale and rotate APIs.

They can be used with gdTransformAffineCopy and are also used in various transformation functions in GD.

Matrices use a six-element double array:

matrix[0] == xx matrix[1] == yx matrix[2] == xy matrix[3] == yy matrix[4] == x0 matrix[5] == y0

where the transformation of a point (x, y) is:

x_new = xx * x + xy * y + x0 y_new = yx * x + yy * y + y0

Macro Definition Documentation

◆ GD_SCALE_INTERPOLATION_AUTO

#define GD_SCALE_INTERPOLATION_AUTO   -1

Let gdImageScaleWithOptions choose the interpolation method from the scale direction.

Automatic selection uses GD_LANCZOS3 for downscales or mixed-axis scales, and GD_CATMULLROM for pure upscales.

Enumeration Type Documentation

◆ gdAffineStandardMatrix

Standard affine matrix operations.

Enumerator
GD_AFFINE_TRANSLATE 

Translation matrix.

GD_AFFINE_SCALE 

Scale matrix.

GD_AFFINE_ROTATE 

Rotation matrix.

GD_AFFINE_SHEAR_HORIZONTAL 

Horizontal shear matrix.

GD_AFFINE_SHEAR_VERTICAL 

Vertical shear matrix.

◆ gdCropMode

enum gdCropMode

Group: Crop

See also
gdImageCropAuto gdImageCropThreshold gdCrop
Enumerator
GD_CROP_DEFAULT 

Same as GD_CROP_TRANSPARENT

GD_CROP_TRANSPARENT 

Crop using the transparent color

GD_CROP_BLACK 

Crop black borders

GD_CROP_WHITE 

Crop white borders

GD_CROP_SIDES 

Crop using colors of the 4 corners

GD_CROP_THRESHOLD 

Crop using a threshold

◆ gdInterestingMethod

Methods used to find an interesting crop region.

See also
gdImageInterestingCropRegion gdImageScaleWithOptions
Enumerator
GD_INTERESTING_ENTROPY 

Prefer regions with higher image entropy.

GD_INTERESTING_ATTENTION 

Prefer regions with likely visual attention.

◆ gdInterpolationMethod

gdInterpolationMethod

Interpolation kernels used by image scaling, rotation and affine transformation functions. Newly-created images use GD_BILINEAR_FIXED by default. Call gdImageSetInterpolationMethod on the source image before using APIs that read the image's current interpolation method.

gdImageScaleWithOptions can either use one of these values explicitly or use GD_SCALE_INTERPOLATION_AUTO to choose a method from the requested scale direction.

Note
GD_WEIGHTED4 is not supported by gdImageScale. For downscales or mixed-axis scales, gdImageScale maps the fixed compatibility methods (GD_DEFAULT, GD_BILINEAR_FIXED, GD_LINEAR, GD_BICUBIC_FIXED and GD_BICUBIC) to GD_TRIANGLE to avoid the blur and aliasing of the old fixed scalers.
See also
gdImageSetInterpolationMethod gdImageScale gdImageScaleWithOptions gdImageRotateInterpolated gdTransformAffineCopy
Enumerator
GD_DEFAULT 

Compatibility default. Setting this resolves to GD_LINEAR

GD_BELL 

Bell filter.

GD_BESSEL 

Bessel filter.

GD_BILINEAR_FIXED 

Compatibility bilinear scaler.

GD_BICUBIC 

Bicubic interpolation.

GD_BICUBIC_FIXED 

Compatibility bicubic scaler.

GD_BLACKMAN 

Blackman filter.

GD_BOX 

Box filter.

GD_BSPLINE 

B-spline filter.

GD_CATMULLROM 

Catmull-Rom filter.

GD_GAUSSIAN 

Gaussian filter.

GD_GENERALIZED_CUBIC 

Generalized cubic filter.

GD_HERMITE 

Hermite filter.

GD_HAMMING 

Hamming filter.

GD_HANNING 

Hanning filter.

GD_MITCHELL 

Mitchell filter.

GD_NEAREST_NEIGHBOUR 

Nearest-neighbour interpolation.

GD_POWER 

Power filter.

GD_QUADRATIC 

Quadratic filter.

GD_SINC 

Sinc filter.

GD_TRIANGLE 

Triangle filter.

GD_WEIGHTED4 

Four-pixel weighted interpolation for rotation and affine sampling.

GD_LINEAR 

Bilinear interpolation.

GD_LANCZOS3 

Lanczos filter with radius 3.

GD_LANCZOS8 

Lanczos filter with radius 8.

GD_BLACKMAN_BESSEL 

Blackman-windowed Bessel filter.

GD_BLACKMAN_SINC 

Blackman-windowed sinc filter.

GD_QUADRATIC_BSPLINE 

Quadratic B-spline filter.

GD_CUBIC_SPLINE 

Cubic spline filter.

GD_COSINE 

Cosine filter.

GD_WELSH 

Welsh filter.

◆ gdScaleFit

enum gdScaleFit

Constants: gdScaleFit

Controls how gdImageScaleWithOptions maps the source aspect ratio into the requested output size.

Defaults: When gdImageScaleWithOptions receives NULL options, the fit defaults to GD_SCALE_FIT_COVER.

Enumerator
GD_SCALE_FIT_COVER 

Preserve aspect ratio, fill requested size, crop overflow.

GD_SCALE_FIT_CONTAIN 

Preserve aspect ratio, fit inside requested size, pad the rest.

GD_SCALE_FIT_FILL 

Stretch to requested size without preserving aspect ratio.

GD_SCALE_FIT_INSIDE 

Preserve aspect ratio; output is no larger than requested size.

GD_SCALE_FIT_OUTSIDE 

Preserve aspect ratio; output is no smaller than requested size.

◆ gdScaleGravity

Chooses the anchor used when gdImageScaleWithOptions pads or crops an image. North and south refer to the top and bottom of the output; west and east refer to the left and right.

Defaults: When gdImageScaleWithOptions receives NULL options, gravity defaults to GD_SCALE_GRAVITY_CENTER.

Enumerator
GD_SCALE_GRAVITY_NORTHWEST 

Anchor to the top-left corner.

GD_SCALE_GRAVITY_NORTH 

Anchor to the top edge.

GD_SCALE_GRAVITY_NORTHEAST 

Anchor to the top-right corner.

GD_SCALE_GRAVITY_WEST 

Anchor to the left edge.

GD_SCALE_GRAVITY_CENTER 

Anchor to the center.

GD_SCALE_GRAVITY_EAST 

Anchor to the right edge.

GD_SCALE_GRAVITY_SOUTHWEST 

Anchor to the bottom-left corner.

GD_SCALE_GRAVITY_SOUTH 

Anchor to the bottom edge.

GD_SCALE_GRAVITY_SOUTHEAST 

Anchor to the bottom-right corner.

◆ gdScaleStrategy

Constants: gdScaleStrategy

Optional crop strategy for GD_SCALE_FIT_COVER in gdImageScaleWithOptions.

Notes: Entropy and attention strategies are valid only with GD_SCALE_FIT_COVER. If a strategy cannot find an interesting crop, gdImageScaleWithOptions falls back to the normal gravity-based cover crop.

Defaults: When gdImageScaleWithOptions receives NULL options, strategy defaults to GD_SCALE_STRATEGY_NONE.

Enumerator
GD_SCALE_STRATEGY_NONE 

Crop using gravity only.

GD_SCALE_STRATEGY_ENTROPY 

Prefer a high-entropy crop region.

GD_SCALE_STRATEGY_ATTENTION 

Prefer a likely visual-attention crop region.

Function Documentation

◆ gdAffineApplyToPointF()

int gdAffineApplyToPointF ( gdPointFPtr  dst,
const gdPointFPtr  src,
const double  affine[6] 
)

Apply an affine matrix to a floating-point point.

Parameters
dst- Receives the transformed point.
src- Source point.
affine- Matrix in gd's six-value affine form.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdAffineConcat()

int gdAffineConcat ( double  dst[6],
const double  m1[6],
const double  m2[6] 
)

Concatenate two affine matrices.

The result is equivalent to applying m1 and then m2. The destination may be the same array as either input.

Parameters
dst- Receives the concatenated matrix.
m1- First matrix.
m2- Second matrix.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdAffineEqual()

int gdAffineEqual ( const double  matrix1[6],
const double  matrix2[6] 
)

Compare two affine matrices.

Parameters
matrix1- First matrix.
matrix2- Second matrix.
Returns
GD_TRUE if the matrices are equal within gd's affine tolerance, otherwise GD_FALSE.

◆ gdAffineExpansion()

double gdAffineExpansion ( const double  src[6])

Return the linear expansion factor of an affine matrix.

This is the square root of the factor by which the matrix changes area.

Parameters
src- Source matrix.
Returns
The expansion factor.

◆ gdAffineFlip()

int gdAffineFlip ( double  dst_affine[6],
const double  src_affine[6],
const int  flip_h,
const int  flip_v 
)

Build a horizontal and/or vertical flip from an affine matrix.

Parameters
dst_affine- Receives the flipped matrix.
src_affine- Source matrix.
flip_h- Non-zero to flip horizontally.
flip_v- Non-zero to flip vertically.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdAffineIdentity()

int gdAffineIdentity ( double  dst[6])

Store an identity affine matrix.

Parameters
dst- Receives the identity matrix.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdAffineInvert()

int gdAffineInvert ( double  dst[6],
const double  src[6] 
)

Invert an affine matrix.

Parameters
dst- Receives the inverse matrix.
src- Source matrix.
Returns
GD_TRUE on success, or GD_FALSE if the matrix cannot be inverted.

◆ gdAffineRectilinear()

int gdAffineRectilinear ( const double  src[6])

Test whether an affine matrix preserves axis-aligned rectangles.

Parameters
src- Source matrix.
Returns
GD_TRUE if the matrix is rectilinear, otherwise GD_FALSE.

◆ gdAffineRotate()

int gdAffineRotate ( double  dst[6],
const double  angle 
)

Store a rotation affine matrix.

In gd's image coordinate system, increasing y moves downward; positive angles rotate counterclockwise in that system.

Parameters
dst- Receives the rotation matrix.
angle- Rotation angle in degrees.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdAffineScale()

int gdAffineScale ( double  dst[6],
const double  scale_x,
const double  scale_y 
)

Store a scale affine matrix.

Parameters
dst- Receives the scale matrix.
scale_x- Horizontal scale factor.
scale_y- Vertical scale factor.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdAffineShearHorizontal()

int gdAffineShearHorizontal ( double  dst[6],
const double  angle 
)

Store a horizontal shear affine matrix.

Parameters
dst- Receives the shear matrix.
angle- Shear angle in degrees.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdAffineShearVertical()

int gdAffineShearVertical ( double  dst[6],
const double  angle 
)

Store a vertical shear affine matrix.

Parameters
dst- Receives the shear matrix.
angle- Shear angle in degrees.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdAffineTranslate()

int gdAffineTranslate ( double  dst[6],
const double  offset_x,
const double  offset_y 
)

Store a translation affine matrix.

Parameters
dst- Receives the translation matrix.
offset_x- Horizontal offset.
offset_y- Vertical offset.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdImageAutoCropWithOptions()

gdImagePtr gdImageAutoCropWithOptions ( gdImagePtr  src,
const gdAutoCropOptions options 
)

Crop an image automatically with options.

This function detects the cropping area according to the given options.

Parameters
srcThe image.
optionsThe cropping options, gdAutoCropOptions.
Returns
The newly created cropped image, or NULL on failure.

◆ gdImageCrop()

gdImagePtr gdImageCrop ( gdImagePtr  src,
const gdRect crop 
)

Crop an image to a given rectangle.

Parameters
srcThe image.
cropThe cropping rectangle, gdRect.
Returns
The newly created cropped image, or NULL on failure.
See also
gdImageCrop gdImageCropThreshold gdImageAutoCropWithOptions

◆ gdImageCropAuto()

gdImagePtr gdImageCropAuto ( gdImagePtr  im,
const unsigned int  mode 
)

Crop an image automatically.

This function detects the cropping area according to the given mode.

Parameters
imThe image.
modeThe cropping mode, gdCropMode.
Returns
The newly created cropped image, or NULL on failure.
See also
gdImageCrop gdImageCropThreshold gdImageAutoCropWithOptions

◆ gdImageCropThreshold()

gdImagePtr gdImageCropThreshold ( gdImagePtr  im,
const unsigned int  color,
const float  threshold 
)

Crop an image using a given color.

The threshold defines the tolerance to be used while comparing the image color and the color to crop. The method used to calculate the color difference is based on the color distance in the RGB(A) cube.

Parameters
imThe image.
colorThe crop color.
thresholdThe crop threshold.
Returns
The newly created cropped image, or NULL on failure.
See also
gdImageCrop gdImageCropThreshold gdImageAutoCropWithOptions

◆ gdImageEntropyCropRegion()

int gdImageEntropyCropRegion ( const gdImagePtr  src,
unsigned int  target_width,
unsigned int  target_height,
gdRectPtr  crop 
)

Find a high-entropy source crop region with the requested aspect ratio.

Parameters
src- The source image.
target_width- The target width used to compute the crop aspect ratio.
target_height- The target height used to compute the crop aspect ratio.
crop- Receives the crop rectangle on success.
Returns
GD_TRUE on success, or GD_FALSE on failure.
See also
gdImageInterestingCropRegion

◆ gdImageFlipBoth()

void gdImageFlipBoth ( gdImagePtr  im)

Flip an image vertically and horizontally.

The image is mirrored upside-down and left-right.

Parameters
imThe image.
See also
gdImageFlipVertical, gdImageFlipHorizontal

◆ gdImageFlipHorizontal()

void gdImageFlipHorizontal ( gdImagePtr  im)

Flip an image vertically.

The image is mirrored upside-down.

Parameters
imThe image.
See also
gdImageFlipHorizontal, gdImageFlipBoth

◆ gdImageFlipVertical()

void gdImageFlipVertical ( gdImagePtr  im)

Flip an image horizontally.

The image is mirrored left-right.

Parameters
imThe image.
See also
gdImageFlipVertical, gdImageFlipBoth

File: Transformations

◆ gdImageGetInterpolationMethod()

gdInterpolationMethod gdImageGetInterpolationMethod ( gdImagePtr  im)

Return the interpolation method currently stored on an image.

Parameters: im - The image.

Returns: The current interpolation method.

See also:

◆ gdImageInterestingCropRegion()

int gdImageInterestingCropRegion ( const gdImagePtr  src,
unsigned int  target_width,
unsigned int  target_height,
gdInterestingMethod  method,
gdRectPtr  crop 
)

Find a source crop region with the requested aspect ratio using an interesting-region method.

Parameters
src- The source image.
target_width- The target width used to compute the crop aspect ratio.
target_height- The target height used to compute the crop aspect ratio.
method- The interesting-region method.
crop- Receives the crop rectangle on success.
Returns
GD_TRUE on success, or GD_FALSE on failure.
See also
gdInterestingMethod gdImageEntropyCropRegion gdImageScaleWithOptions

◆ gdImageRotateInterpolated()

gdImagePtr gdImageRotateInterpolated ( const gdImagePtr  src,
const float  angle,
int  bgcolor 
)

Rotate an image by an arbitrary angle using the source image's current gdInterpolationMethod.

The returned image is newly allocated and must be destroyed with gdImageDestroy. Palette sources are converted to truecolor internally for arbitrary-angle rotation. Angles that are multiples of 90 degrees use the optimized rotate paths.

Parameters
src- The source image.
angle- Rotation angle in degrees.
bgcolor- Background color for uncovered pixels. For palette sources, this may be a palette index.
Returns
The rotated image on success, or NULL on failure.
Note
bgcolor must be non-negative. The source interpolation method must be a valid concrete method; GD_DEFAULT is not accepted by this function.
See also
gdImageSetInterpolationMethod gdImageRotate90 gdImageRotate180 gdImageRotate270

◆ gdImageScale()

gdImagePtr gdImageScale ( const gdImagePtr  src,
const unsigned int  new_width,
const unsigned int  new_height 
)

Scale an image to an exact width and height using the source image's current gdInterpolationMethod.

The returned image is newly allocated and must be destroyed with gdImageDestroy. If the requested dimensions match the source dimensions, this function returns a clone of the source image. Width and height must be greater than zero.

Notes: GD_WEIGHTED4 is not supported by this function. For downscales and mixed-axis scales, the fixed compatibility methods are sampled with GD_TRIANGLE for better filtering.

Parameters: src - The source image. new_width - The requested output width. new_height - The requested output height.

Returns: The scaled image on success, or NULL on failure.

See also:

◆ gdImageScaleWithOptions()

gdImagePtr gdImageScaleWithOptions ( const gdImagePtr  src,
const unsigned int  new_width,
const unsigned int  new_height,
const gdScaleOptions options 
)

Scale an image using aspect-ratio, gravity, crop-strategy and interpolation options.

Scale an image using aspect-ratio, gravity, crop-strategy and interpolation options.

This is the higher-level scaling API. It can stretch, contain, cover, pad or return an inside/outside size while preserving the source aspect ratio. The returned image is newly allocated and must be destroyed with gdImageDestroy.

Parameters
src- The source image.
new_width- The requested width.
new_height- The requested height.
options- Scaling options, or NULL for the default options.
Returns
The scaled image on success, or NULL on failure. Caller owns the returned image and must call gdImageDestroy when done. Returns NULL if src is NULL, either dimension is zero, interpolation is invalid, or an entropy/attention strategy is used with a fit other than GD_SCALE_FIT_COVER.
See also
gdScaleOptions gdImageScale gdImageInterestingCropRegion

◆ gdImageSetInterpolationMethod()

int gdImageSetInterpolationMethod ( gdImagePtr  im,
gdInterpolationMethod  id 
)

Set the interpolation method stored on an image.

Scaling, rotation and affine transformation functions use this value when they sample pixels from the image. Newly-created images default to GD_BILINEAR_FIXED. Passing GD_DEFAULT is accepted and stores GD_LINEAR.

Some transform APIs have optimized paths for specific methods. In particular, gdImageScale uses GD_TRIANGLE when downscaling or doing a mixed-axis scale with the fixed compatibility methods.

Parameters: im - The image. id - The interpolation method.

Returns: Non-zero on success, zero on failure.

See also:

◆ gdTransformAffineBoundingBox()

int gdTransformAffineBoundingBox ( gdRectPtr  src,
const double  affine[6],
gdRectPtr  bbox 
)

Compute the bounding box of a source rectangle after applying an affine transform.

Parameters
src- Source rectangle.
affine- Matrix in gd's six-value affine form.
bbox- Receives the transformed bounding box.
Returns
GD_TRUE on success, or GD_FALSE on failure.

◆ gdTransformAffineCopy()

int gdTransformAffineCopy ( gdImagePtr  dst,
int  dst_x,
int  dst_y,
const gdImagePtr  src,
gdRectPtr  src_region,
const double  affine[6] 
)

Apply an affine transform to a source region and copy the transformed pixels into an existing destination image.

The source image's current gdInterpolationMethod controls sampling. Transparent samples are skipped. Destination bounds and alpha-blending settings are honored.

Parameters
dst- Destination image.
dst_x- Destination x offset.
dst_y- Destination y offset.
src- Source image.
src_region- Source rectangle to transform.
affine- Matrix in gd's six-value affine form.
Returns
GD_TRUE on success, or GD_FALSE on failure.
See also
gdTransformAffineGetImage gdTransformAffineBoundingBox gdImageSetInterpolationMethod

◆ gdTransformAffineGetImage()

int gdTransformAffineGetImage ( gdImagePtr *  dst,
const gdImagePtr  src,
gdRectPtr  src_area,
const double  affine[6] 
)

Apply an affine transform to a source region and create an image containing the complete transformed result.

The new image is truecolor with alpha saving enabled. Areas not covered by the transformed source are transparent. The source image's current gdInterpolationMethod controls sampling. Palette sources may be converted to truecolor internally.

Parameters
dst- Receives the newly-created destination image.
src- Source image.
src_area- Source rectangle, or NULL to transform the full image.
affine- Matrix in gd's six-value affine form.
Returns
GD_TRUE on success, or GD_FALSE on failure. On failure, *dst is NULL.
See also
gdTransformAffineCopy gdTransformAffineBoundingBox gdImageSetInterpolationMethod