What are the best practices for handling image source changes on client-side versus server-side in PHP?

When handling image source changes, it is often more efficient to handle them on the client-side using JavaScript to dynamically update the image source without needing to reload the page. However, if there are security concerns or the changes need to be processed server-side, PHP can be used to handle the image source changes. PHP Code Snippet:

<?php
// Client-side image source change using JavaScript
?>
<script>
    // Update image source on client-side
    document.getElementById('image').src = 'new_image.jpg';
</script>

<?php
// Server-side image source change using PHP
$image_src = 'new_image.jpg';
?>
<img src="<?php echo $image_src; ?>" alt="New Image">