Alternatively, you can have a single PHP script generate the image dynamically and output it directly to the browser, which is useful if you don't want to save the file permanently: 

// dynamic_preview.php
header('Content-Type: image/jpeg'); // Set the content type header
$filename = 'original_image.jpg';
$desired_width = 200;
if (file_exists($filename)) {
$source_image = imagecreatefromjpeg($filename); // resizing logic as in the function above
$width = imagesx($source_image);
$height = imagesy($source_image);
$desired_height = floor($height * ($desired_width / $width));
$virtual_image = imagecreatetruecolor($desired_width, $desired_height); 
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
imagejpeg($virtual_image, NULL, 80); // Output to browser (file parameter is NULL) 
imagedestroy($source_image);
imagedestroy($virtual_image);
}

