|
Posted by Mitul on 03/08/06 11:10
Hello Schraalhans,
Please use following function which was developed by me you can use it
directly.
If u have any problem Please contact me on mitul[at]siliconinfo[dot]com
function thumbgenerator($forcedwidth, $forcedheight, $sourcefile,
$destfile, $imgcomp)
{
$g_imgcomp=100-$imgcomp;
$g_srcfile=$sourcefile;
$g_dstfile=$destfile;
$g_fw=$forcedwidth;
$g_fh=$forcedheight;
if(file_exists($g_srcfile))
{
$g_is=getimagesize($g_srcfile);
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];
}
$src=explode(".",$g_srcfile);
$var=count($src);
if($src[$var-1]=='gif' || $src[$var-1]=='GIF')
{
$img_src=ImageCreateFromGIF($g_srcfile);
//$img_src= ImageColorAllocate($img_src, 250, 250, 250);
$img_dst=imagecreate($g_iw,$g_ih);
$img_dst1 = ImageColorAllocate($img_dst, 255, 255, 255);
}
if($src[$var-1]=='png')
{
$img_src=ImageCreateFromPNG($g_srcfile);
$img_dst=imagecreate($g_iw,$g_ih);
$img_dst1 = ImageColorAllocate($img_dst,255, 255, 255);
}
if($src[$var-1]=='jpg' || $src[$var-1]=='JPG')
{
$img_src=imagecreatefromjpeg($g_srcfile);
$img_dst=imagecreate($g_iw,$g_ih);
$img_dst = &imageCreateTrueColor( $g_iw, $g_ih);
}
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih,
$g_is[0], $g_is[1]);
if($src[$var-1]=='jpg' || $src[$var-1]=='JPG')
{
imagejpeg($img_dst, $g_dstfile, $g_imgcomp);
}
if($src[$var-1]=='png')
{
imagepng($img_dst, $g_dstfile, $g_imgcomp);
}
if($src[$var-1]='gif' || $src[$var-1]=='GIF')
{
imagegif($img_dst, $g_dstfile, $g_imgcomp);
}
imagedestroy($img_dst);
return true;
}
else
return false;
}
[Back to original message]
|