imagecopyresized 期望参数错误:尝试制作不失真的缩略图
我正在尝试将图像制作为具有一定尺寸且不失真的缩略图(如果图像是矩形)。
<?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;
时,它给我 imagecopyresized() 期望参数错误。
感谢您的帮助 :)
I'm trying to make an image into a thumbnail with a certain size without distortion (if image is rectangular).
<?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
}
?>
This is how my code looks right now and I need some help. I have a code:
<img src='<?php echo $imageName; ?>' style='height:150px;width:150px;'/>
just to see how it looks like with the height and width style, but of course this shows distortion.
When I echo $thumbnail;
it gives me imagecopyresized() expects parameter error.
Thank you for your help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您传入的
$imageName
看起来只是一个文件名。您必须为源参数和目标参数提供 GD 图像句柄:The
$imageName
you're passing in is just a filename, it appears. YOu have to provide a GD image handle for both the source AND destination arguments: