Я пытаюсь изменить размер изображения, которое загружается в Drupal через форму.Код, который у меня есть для этого:
//Image resizing
//Get file and if it's not the default one - resize it.
$img = file_load($form_state['values']['event_image']);
if($img->fid != 1) {
//Get the image size and calculate ratio
list($width, $height) = getimagesize($img->uri);
if($width/$height > 1) {
$new_width = 60;
$new_height = $height/($width/60);
} else if($width/$height < 1) {
$new_height = 60;
$new_width = $width/($height/60);
} else {
$new_width = 60;
$new_height = 60;
}
//Create image
$image_p = imagecreatetruecolor($new_width, $new_height);
$ext = strtolower(pathinfo($img->uri, PATHINFO_EXTENSION));
if($ext == 'jpeg' || $ext == 'jpg') {
$image = imagecreatefromjpeg($img->uri);
} else {
$image = imagecreatefrompng($img->uri);
}
//Resize image
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//Save image as jpeg
imagejpeg($image_p, file_create_url($img->uri), 80);
//Clean up
imagedestroy($image_p);
//Store the image permanently.
$img->status = FILE_STATUS_PERMANENT;
}
file_save($img);
Итак, я пытаюсь добиться сохранения нового файла (с меньшим размером) поверх старого загруженного файла.
Проблема, которую я получаю, заключается в том, что PHP выдает предупреждение на imagejpeg($image_p, file_create_url($img->uri), 80);
, говоря:
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'http://localhost:8888/drupal/sites/default/files/pictures/myimage.png' for writing: No such file or directory in event_creation_form_submit()
Из-за этого размер изображения не изменяется.Кто-нибудь знает, что я делаю не так?
Спасибо,