What potential issues could arise when trying to reduce the size of an image in PHP and save it to a different folder?

One potential issue that could arise when trying to reduce the size of an image in PHP and save it to a different folder is the loss of image quality. To solve this issue, you can use image compression techniques to reduce the file size while maintaining a good level of quality.

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

// Create a new image with reduced size
$width = imagesx($original_image) / 2;
$height = imagesy($original_image) / 2;
$resized_image = imagecreatetruecolor($width, $height);

// Resize the original image to the new size
imagecopyresampled($resized_image, $original_image, 0, 0, 0, 0, $width, $height, imagesx($original_image), imagesy($original_image));

// Save the resized image to a different folder
imagejpeg($resized_image, 'resized/resized.jpg');

// Free up memory
imagedestroy($original_image);
imagedestroy($resized_image);