When working with GDLib for image processing in PHP, what strategies can be employed to avoid memory issues, such as creating thumbnails or working with large images?

When working with GDLib for image processing in PHP, memory issues can arise when working with large images or creating thumbnails. To avoid these problems, one strategy is to use the `imagecreatefromjpeg`, `imagecreatefrompng`, or `imagecreatefromgif` functions to create a resized version of the image rather than loading the entire image into memory.

// Example of creating a thumbnail using GDLib in PHP
function createThumbnail($source, $destination, $maxSize) {
    list($width, $height) = getimagesize($source);
    $ratio = $width / $height;

    if ($ratio > 1) {
        $newWidth = $maxSize;
        $newHeight = $maxSize / $ratio;
    } else {
        $newWidth = $maxSize * $ratio;
        $newHeight = $maxSize;
    }

    $sourceImage = imagecreatefromjpeg($source);
    $thumbnail = imagecreatetruecolor($newWidth, $newHeight);
    imagecopyresampled($thumbnail, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
    imagejpeg($thumbnail, $destination, 90);

    imagedestroy($sourceImage);
    imagedestroy($thumbnail);
}

// Usage example
createThumbnail('source.jpg', 'thumbnail.jpg', 100);