I had a problem with denied permissions when trying to upload AND resize an image having safe_mode on. This caused that I couldn't create the new file in which I wanted to resampled the image with nor with imagejpeg() nor with touch() and imagejpeg() after it.
Here is my solution, I didn't test, but it's possible, it is biting some memory:
<?php
function resize($image, $target_file) {
list($width, $height) = getimagesize($image['tmp_name']);
$ratio = $width/$height;
$new_height = 500;
$new_width = $new_height * $ratio;
move_uploaded_file($image['tmp_name'], $target_file);
$new_image = imagecreatetruecolor($new_width, $new_height);
$old_image = imagecreatefromjpeg($target_file);
imagecopyresampled($new_image,$old_image,0,0,0,0,$new_width, $new_height, $width, $height);
imagejpeg($new_image, $target_file, 100);
}
?>
As you can see, the function moves the uploaded file where you want to save the resampled image (move_uploaded_file is not restricted by safe_mode) and then you can resample the image, because it was created by moving it already.
Note: the directory where you want to save the file must have permissions set to 0777.