|
LibGd 2.4.0-dev
GD Graphics library
|
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. | |
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. | |
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
| #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.
| enum gdCropMode |
Group: Crop
| enum gdInterestingMethod |
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.
| 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. |
| 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.
| enum 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.
| enum 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. |
| int gdAffineApplyToPointF | ( | gdPointFPtr | dst, |
| const gdPointFPtr | src, | ||
| const double | affine[6] | ||
| ) |
Apply an affine matrix to a floating-point point.
| dst | - Receives the transformed point. |
| src | - Source point. |
| affine | - Matrix in gd's six-value affine form. |
| 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.
| dst | - Receives the concatenated matrix. |
| m1 | - First matrix. |
| m2 | - Second matrix. |
| int gdAffineEqual | ( | const double | matrix1[6], |
| const double | matrix2[6] | ||
| ) |
Compare two affine matrices.
| matrix1 | - First matrix. |
| matrix2 | - Second matrix. |
| 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.
| src | - Source 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.
| dst_affine | - Receives the flipped matrix. |
| src_affine | - Source matrix. |
| flip_h | - Non-zero to flip horizontally. |
| flip_v | - Non-zero to flip vertically. |
| int gdAffineIdentity | ( | double | dst[6] | ) |
Store an identity affine matrix.
| dst | - Receives the identity matrix. |
| int gdAffineInvert | ( | double | dst[6], |
| const double | src[6] | ||
| ) |
Invert an affine matrix.
| dst | - Receives the inverse matrix. |
| src | - Source matrix. |
| int gdAffineRectilinear | ( | const double | src[6] | ) |
Test whether an affine matrix preserves axis-aligned rectangles.
| src | - Source matrix. |
| 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.
| dst | - Receives the rotation matrix. |
| angle | - Rotation angle in degrees. |
| int gdAffineScale | ( | double | dst[6], |
| const double | scale_x, | ||
| const double | scale_y | ||
| ) |
Store a scale affine matrix.
| dst | - Receives the scale matrix. |
| scale_x | - Horizontal scale factor. |
| scale_y | - Vertical scale factor. |
| int gdAffineShearHorizontal | ( | double | dst[6], |
| const double | angle | ||
| ) |
Store a horizontal shear affine matrix.
| dst | - Receives the shear matrix. |
| angle | - Shear angle in degrees. |
| int gdAffineShearVertical | ( | double | dst[6], |
| const double | angle | ||
| ) |
Store a vertical shear affine matrix.
| dst | - Receives the shear matrix. |
| angle | - Shear angle in degrees. |
| int gdAffineTranslate | ( | double | dst[6], |
| const double | offset_x, | ||
| const double | offset_y | ||
| ) |
Store a translation affine matrix.
| dst | - Receives the translation matrix. |
| offset_x | - Horizontal offset. |
| offset_y | - Vertical offset. |
| gdImagePtr gdImageAutoCropWithOptions | ( | gdImagePtr | src, |
| const gdAutoCropOptions * | options | ||
| ) |
Crop an image automatically with options.
This function detects the cropping area according to the given options.
| src | The image. |
| options | The cropping options, gdAutoCropOptions. |
| gdImagePtr gdImageCrop | ( | gdImagePtr | src, |
| const gdRect * | crop | ||
| ) |
Crop an image to a given rectangle.
| src | The image. |
| crop | The cropping rectangle, gdRect. |
| gdImagePtr gdImageCropAuto | ( | gdImagePtr | im, |
| const unsigned int | mode | ||
| ) |
Crop an image automatically.
This function detects the cropping area according to the given mode.
| im | The image. |
| mode | The cropping mode, gdCropMode. |
| 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.
| im | The image. |
| color | The crop color. |
| threshold | The crop threshold. |
| 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.
| 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. |
| void gdImageFlipBoth | ( | gdImagePtr | im | ) |
Flip an image vertically and horizontally.
The image is mirrored upside-down and left-right.
| im | The image. |
| void gdImageFlipHorizontal | ( | gdImagePtr | im | ) |
Flip an image vertically.
The image is mirrored upside-down.
| im | The image. |
| void gdImageFlipVertical | ( | gdImagePtr | im | ) |
Flip an image horizontally.
The image is mirrored left-right.
| im | The image. |
File: Transformations
| gdInterpolationMethod gdImageGetInterpolationMethod | ( | gdImagePtr | im | ) |
Return the interpolation method currently stored on an image.
Parameters: im - The image.
Returns: The current interpolation method.
See also:
| 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.
| 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. |
| 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.
| src | - The source image. |
| angle | - Rotation angle in degrees. |
| bgcolor | - Background color for uncovered pixels. For palette sources, this may be a palette index. |
| 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:
| 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.
| src | - The source image. |
| new_width | - The requested width. |
| new_height | - The requested height. |
| options | - Scaling options, or NULL for the default options. |
| 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:
Compute the bounding box of a source rectangle after applying an affine transform.
| src | - Source rectangle. |
| affine | - Matrix in gd's six-value affine form. |
| bbox | - Receives the transformed bounding box. |
| 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.
| 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. |
| 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.
| 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. |