我是facebook应用程序开发的新手,正在开发我的第一个应用程序。我正试图使用imagecopyresampled()函数调整图像大小,但却出现了以下错误:
警告:imagecopyrasampled():提供的参数不是…中的有效图像资源
$url = "http://graph.facebook.com/{$userId}/picture?type=large";
$img = "udp.gif";
file_put_contents($img, file_get_contents($url));
if (exif_imagetype($img) != IMAGETYPE_GIF) {
$imgFile = 'temp/' . $userId . '_fdp_' . rand() . '.gif';
if (exif_imagetype($img) == IMAGETYPE_JPEG)
$imageObject = imagecreatefromjpeg($img);
if (exif_imagetype($img) == IMAGETYPE_PNG)
$imageObject = imagecreatefrompng($img);
$imagegif($imageObject, $imgFile);
$imgFile1='temp/' . $userId . '_fdp_.gif';
$imagecopyresampled($imgFile1, $imgFile, 0, 0, 0, 0, 200, 280, 180, 252);
$img = $imgFile1;
}
}
}
您误解了参数类型。resource
是一种PHP类型,与string
或float
类似。需要创建具有适当相关功能的资源。在您的情况下,您需要原始图像的一个resource
(使用类似imagecreatefromjpeg
的函数创建)和另一个类似的resource
来将图像复制到,很可能是使用imagecreatetruecolor
创建的空白图像。
引用手册中的例子:
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
取而代之的是一个不存在的变量和一个字符串,这不是必需的输入。