Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/lib/ -> gdlib.php (source)

Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

gdlib.php - Collection of routines in Moodle related to processing images using GD

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 477 lines (18 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 7 functions


Functions that are not part of a class:

imagecopybicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)   X-Ref
Copies a rectangular portion of the source image to another rectangle in the destination image

This function calls imagecopyresampled() if it is available and GD version is 2 at least.
Otherwise it reimplements the same behaviour. See the PHP manual page for more info.

return: bool tru on success, false otherwise
param: resource $dst_img the destination GD image resource
param: resource $src_img the source GD image resource
param: int $dst_x vthe X coordinate of the upper left corner in the destination image
param: int $dst_y the Y coordinate of the upper left corner in the destination image
param: int $src_x the X coordinate of the upper left corner in the source image
param: int $src_y the Y coordinate of the upper left corner in the source image
param: int $dst_w the width of the destination rectangle
param: int $dst_h the height of the destination rectangle
param: int $src_w the width of the source rectangle
param: int $src_h the height of the source rectangle

process_new_icon($context, $component, $filearea, $itemid, $originalfile, $preferpng = false)   X-Ref
Stores optimised icon images in icon file area.

Since 2.9 this function will generate an icon in the same format as the original file when possible.
To counter that behaviour, you can use the argument $preferpng to generate a PNG icon.

return: mixed new unique revision number or false if not saved
param: context $context
param: string $component
param: string filearea
param: int $itemid
param: string $originalfile
param: boolean $preferpng When true, it will try to generate a PNG file regardless of the original file.

resize_image($filepath, $width, $height, $forcecanvas = false)   X-Ref
Resize an image from an image path.

This maintains the aspect ratio of the image.
This will not enlarge the image.

return: string|bool False if a problem occurs, else the resized image data.
param: string $filepath The full path to the original image file.
param: int|null $width The max width of the resized image, or null to only use the height.
param: int|null $height The max height of the resized image, or null to only use the width.
param: bool $forcecanvas Whether the final dimensions should be set to $width and $height.

resize_image_from_image($original, $imageinfo, $width, $height, $forcecanvas = false)   X-Ref
Resize an image from an image object.

return: string|bool False if a problem occurs, else the resized image data.
param: resource $original The image to work on.
param: array $imageinfo Contains [0] => originalwidth, [1] => originalheight.
param: int|null $width The max width of the resized image, or null to only use the height.
param: int|null $height The max height of the resized image, or null to only use the width.
param: bool $forcecanvas Whether the final dimensions should be set to $width and $height.

generate_image_thumbnail($filepath, $width, $height)   X-Ref
Generates a thumbnail for the given image

If the GD library has at least version 2 and PNG support is available, the returned data
is the content of a transparent PNG file containing the thumbnail. Otherwise, the function
returns contents of a JPEG file with black background containing the thumbnail.

return: string|bool false if a problem occurs, the thumbnail image data otherwise
param: string $filepath the full path to the original image file
param: int $width the width of the requested thumbnail
param: int $height the height of the requested thumbnail

generate_image_thumbnail_from_string($filedata, $width, $height)   X-Ref
Generates a thumbnail for the given image string.

If the GD library has at least version 2 and PNG support is available, the returned data
is the content of a transparent PNG file containing the thumbnail. Otherwise, the function
returns contents of a JPEG file with black background containing the thumbnail.

return: string|bool false if a problem occurs, the thumbnail image data otherwise
param: string $filedata The image content as a string
param: int $width the width of the requested thumbnail
param: int $height the height of the requested thumbnail

generate_image_thumbnail_from_image($original, $imageinfo, $width, $height)   X-Ref
Generates a thumbnail for the given image string.

If the GD library has at least version 2 and PNG support is available, the returned data
is the content of a transparent PNG file containing the thumbnail. Otherwise, the function
returns contents of a JPEG file with black background containing the thumbnail.

return: string|bool False if a problem occurs, the thumbnail image data otherwise.
param: resource $original The image to work on.
param: array $imageinfo Contains [0] => originalwidth, [1] => originalheight.
param: int $width The width of the requested thumbnail.
param: int $height The height of the requested thumbnail.