Using the following function I am trying to resize some JPG files to be thumbnail sized. The thumbnail sized images turn out with weird colors or all black with a gray outline of the picture. Any ideas on how I can fix this? I am using the gd2 library on Windows PHP 4.3.2:
<?php
function resampimagejpg($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];
}
$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, $g_imgcomp);
imagedestroy($img_dst);
return true;
} else {
return false;
}
}
resampimagejpg("500", "300", "c:\\testdir\\test.jpg", "c:\\testdir\\test-thumb.jpg", "0");
resampimagejpg("500", "300", "c:\\testdir\\test2.jpg", "c:\\testdir\\test2-thumb.jpg", "0");
?>
I have posted the example images at http://www.netlobo.com/badpics/ Please let me know if you have any ideas on this one.