[SOLVED]problem with thumbnail creation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

[SOLVED]problem with thumbnail creation

Post by dull1554 »

ok i user this function to create thumbnails

Code: Select all

function makethumb($sourcefile, $destfile, $imgcomp = 0)
{
$g_srcfile=$sourcefile;
$g_dstfile=$destfile;
if(file_exists($g_srcfile))
{
$g_is=getimagesize($g_srcfile);
$g_fw=$g_isї0]/4;
$g_fh=$g_isї1]/4;
if(($g_isї0]-$g_fw)>=($g_isї1]-$g_fh))
{
$g_iw=$g_fw;
$g_ih=($g_fw/$g_isї0])*$g_isї1];
}
else
{
$g_ih=$g_fh;
$g_iw=($g_ih/$g_isї1])*$g_isї0];
}
$img_src=imagecreatefromjpeg($g_srcfile);
$img_dst=imagecreate($g_iw,$g_ih);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_isї0], $g_isї1]);
imagejpeg($img_dst, $g_dstfile);
imagedestroy($img_dst);
return true;
}
else
return false;
}
well it kinda works, it makes the thumbnail at the correct size, the only problem i face is that it screws up the images color, it doesent pixelate it just makes it look like crap....

im not very expierenced with GDlib and i could not find anyother people that have had a similar problem so if ne one can help thanks a bunch
~dull1554
Last edited by dull1554 on Sun Mar 06, 2005 1:10 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

imagecreatetruecolor() instead of imagecreate()
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

thanks, works perfectly :)
Post Reply