imagecopyresized expects parameter error: trying to make thumbnail without distortion
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 imagecopyres开发者_Go百科ized() expects parameter error.
Thank you for your help :)
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:
$src = imagecreatefromjpeg('somepicture.jpg');
$dst = imagecreatetruecolor(150,150);
$status = imagecopyresampled($dst, $src, etc....);
精彩评论