0
我正在尝试调整通过表单上传到Drupal的图像大小。我有它的代码是:在Drupal中使用imagecopyresampled调整上传图像的大小
//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()
正因为如此,图像不调整。有谁知道我做错了什么?
谢谢,
Drupal的图像大小调整功能内置的权利有没有任何理由,你不能使用这些? – Clive 2012-02-22 19:25:18
嗨克莱夫,我不知道Drupal有这些 - 它只是你在谈论的http://api.drupal.org/api/drupal/includes%21image.inc/function/image_resize/7? – KerrM 2012-02-22 19:29:24
有不少,['image_scale'](http://api.drupal.org/api/drupal/includes%21image.inc/function/image_scale/7),['image_crop'](http:// api.drupal.org/api/drupal/includes%21image.inc/function/image_crop/7),['image_scale_and_crop'](http://api.drupal.org/api/drupal/includes%21image.inc/function/image_scale_and_crop/7),['image_rotate'](http://api.drupal.org/api/drupal/includes%21image.inc/function/image_rotate/7),我想其他几个人 – Clive 2012-02-22 19:33:09