Imagecopyresized预期参数错误:试图使缩略图不失真


imagecopyresized expects parameter error: trying to make thumbnail without distortion

我正在尝试将图像制作成具有一定尺寸而不失真的缩略图(如果图像是矩形)。

<?php
$sql = mysql_query("SELECT * FROM images ORDER BY date DESC LIMIT 30");
$img = 'img/'; //this is where my files are.
while($row = mysql_fetch_array($sql))
{
$imageName = $img.$row['images'];
$tempImage = imagecreatetruecolor(150,150);
$thumbnail = imagecopyresampled($tempImage,$imageName,0,0,0,0,150,150,150,150);
echo $thumbnail;
?>
<div id='<?php echo $imageID; ?>' class='images' style=''>
<img src='<?php echo $imageName; ?>' style='height:150px;width:150px;'/>
</div>
<?php
}
?>

这是我的代码现在的样子,我需要一些帮助。我有一个代码:

<img src='<?php echo $imageName; ?>' style='height:150px;width:150px;'/>

只是为了看看高度和宽度样式是什么样子,但当然这显示了失真。

当我输入echo $thumbnail;时,它给我imagecopyresize()预期参数错误。

谢谢你的帮助

您正在传递的$imageName只是一个文件名,它看起来。您必须为source和destination参数提供一个GD图像句柄:

$src = imagecreatefromjpeg('somepicture.jpg');
$dst = imagecreatetruecolor(150,150);
$status = imagecopyresampled($dst, $src, etc....);