What are the potential pitfalls of using PHP to load images from a source, add framing, and output them?

One potential pitfall of using PHP to load images from a source, add framing, and output them is the risk of running into memory issues when processing large images. To solve this, you can use PHP's `imagecreatefromjpeg`, `imagecreatefrompng`, or `imagecreatefromgif` functions to create a new image resource from the source image, then apply the framing and output the final image.

// Load the source image
$source = imagecreatefromjpeg('source.jpg');

// Create a blank canvas for the framed image
$framed = imagecreatetruecolor(imagesx($source) + 20, imagesy($source) + 20);

// Add framing to the image
$frameColor = imagecolorallocate($framed, 255, 255, 255);
imagefilledrectangle($framed, 0, 0, imagesx($framed), imagesy($framed), $frameColor);

// Copy the source image onto the framed canvas
imagecopy($framed, $source, 10, 10, 0, 0, imagesx($source), imagesy($source));

// Output the final image
header('Content-Type: image/jpeg');
imagejpeg($framed);

// Free up memory
imagedestroy($source);
imagedestroy($framed);