=($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]; } if ($g_type=="jpg") $img_src=@imagecreatefromjpeg($g_srcfile); if ($g_type=="gif") $img_src=@imagecreatefromgif($g_srcfile); if ($g_type=="png") $img_src=@imagecreatefrompng($g_srcfile); if (!$img_src) { @imagedestroy($img_src); @imagedestroy($img_dst); return false; } if ($g_type=="gif") { $img_dst=imagecreate($g_iw,$g_ih); imagecopyresized($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]); } else { $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 ($g_type=="jpg") imagejpeg($img_dst, $g_dstfile, $g_imgcomp); if ($g_type=="gif") imagegif($img_dst, $g_dstfile); if ($g_type=="png") imagepng($img_dst, $g_dstfile); @imagedestroy($img_src); @imagedestroy($img_dst); return true; } else { @imagedestroy($img_src); @imagedestroy($img_dst); return false; } } function img_crop($src, $dst, $x, $y, $w, $h){ $g_type=""; if (strpos($src,".jpg")) $g_type="jpg"; else if (strpos($src,".jpeg")) $g_type="jpg"; else if (strpos($src,".gif")) $g_type="gif"; else if (strpos($src,".png")) $g_type="png"; else if (strpos($src,".JPG")) $g_type="jpg"; else if (strpos($src,".JPEG")) $g_type="jpg"; else if (strpos($src,".GIF")) $g_type="gif"; else if (strpos($src,".PNG")) $g_type="png"; else return "invalid file type(not jpg, gif, or png)!".$src; if(file_exists($src)) { $g_is=getimagesize($src); //SOURCE RESOURCE (img_src) if ($g_type=="jpg") $img_src=imagecreatefromjpeg($src); if ($g_type=="gif") $img_src=imagecreatefromgif($src); if ($g_type=="png") $img_src=imagecreatefrompng($src); //DESTINATION RESOURCE (img_dst) if ($g_type=="gif") $img_dst=imagecreate($w,$h); else $img_dst=imagecreatetruecolor($w,$h); imagecopyresized($img_dst, $img_src, 0, 0, $x, $y, $w, $h, $w, $h); if ($g_type=="jpg") imagejpeg($img_dst, $dst, 100); if ($g_type=="gif") imagegif($img_dst, $dst); if ($g_type=="png") imagepng($img_dst, $dst); imagedestroy($img_dst); return true; } else return false; } ?>