What are some potential pitfalls when using PHP to output images, especially when trying to implement a print button?

Potential pitfalls when using PHP to output images include inefficient memory usage, slow loading times, and potential security vulnerabilities. When implementing a print button, make sure to properly handle image file paths and ensure that the image is displayed correctly in the print preview.

<?php
// Example code snippet for outputting an image with a print button

$imagePath = 'path/to/image.jpg';

// Output the image
echo '<img src="' . $imagePath . '" alt="Image">';

// Print button
echo '<button onclick="window.print()">Print</button>';
?>