In PHP, what considerations should be taken into account when passing variables to functions for tasks like image resizing and thumbnail creation?

When passing variables to functions for tasks like image resizing and thumbnail creation in PHP, it is important to ensure that the variables are properly sanitized and validated to prevent any security vulnerabilities such as code injection. Additionally, it is crucial to check the type and format of the variables being passed to the function to avoid any unexpected errors or issues during the image processing.

// Example of passing variables to a function for image resizing and thumbnail creation
function createThumbnail($sourceImage, $thumbnailWidth, $thumbnailHeight) {
    // Sanitize and validate input variables
    $sourceImage = filter_var($sourceImage, FILTER_SANITIZE_STRING);
    $thumbnailWidth = filter_var($thumbnailWidth, FILTER_VALIDATE_INT);
    $thumbnailHeight = filter_var($thumbnailHeight, FILTER_VALIDATE_INT);

    // Check if input variables are of the correct type and format
    if(!is_string($sourceImage) || !is_int($thumbnailWidth) || !is_int($thumbnailHeight)) {
        throw new Exception('Invalid input variables');
    }

    // Perform image resizing and thumbnail creation tasks here
}