", $stext); return $stext; } function sprint($stext){ return htmlspecialchars(stripslashes($stext)); } function chi_sprint($stext){ $my_stext = stripslashes($stext); $my_stext = str_replace ('\'', ''', $my_stext ); $my_stext = str_replace ('"', '"', $my_stext ); return $my_stext; } function check_email($str) { //returns 1 if valid email, 0 if not if(ereg("^.+@.+\\..+$", $str)) return 1; else return 0; } function ImageResize_X(&$src, $x, $y){ $dst = imagecreatetruecolor($x, $y); $pals = ImageColorsTotal($src); for ($i = 0; $i < $pals; $i++){ $colors = ImageColorsForIndex ($src, $i); ImageColorAllocate($dst, $colors['red'], $colors['green'], $colors['blue']); } $scX = (imagesx($src) - 1) / $x; $scY = (imagesy($src) - 1) / $y; $scX2 = intval($scX / 2); $scY2 = intval($scY / 2); for ($j = 0; $j < ($y); $j++){ $sY = intval($j * $scY); $y13 = $sY + $scY2; for ($i = 0; $i < ($x); $i++){ $sX = intval($i * $scX); $x34 = $sX + $scX2; $c1 = ImageColorsForIndex($src, ImageColorAt($src, $sX, $y13)); $c2 = ImageColorsForIndex($src, ImageColorAt($src, $sX, $sY)); $c3 = ImageColorsForIndex($src, ImageColorAt($src, $x34,$y13)); $c4 = ImageColorsForIndex($src, ImageColorAt($src, $x34,$sY)); $r = ($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4; $g = ($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4; $b = ($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4; ImageSetPixel ($dst, $i, $j, ImageColorClosest($dst, $r, $g, $b)); } } return ($dst); } function makeImage($filepath, $width, $height, $targetfile){ // $imB = ImageCreate($width, $height); $im = imagecreatefromjpeg($filepath); if ($height == 0 && $width == 0) return false; else{ if ($height == 0){ $scX = (imagesx($im) - 1) / $width; $height = (imagesy($im) - 1) / $scX; } if ($width == 0){ $scY = (imagesy($im) - 1) / $height; $width = (imagesx($im) - 1) / $scY; } $imB = ImageCreate($width, $height); $imB = ImageResize_X($im, $width, $height); imagejpeg($imB, $targetfile, 100); return true; } } function spic_upload($product_image, $width, $height, $destination, $watermark="N", $wmfile=""){ $img = ImageCreateFromJpeg($product_image); $y = ImageSY($img); $x = ImageSX($img); if (($y != "") && ($x != "")){ if($y * $width >= $x * $height){ if ($y >= $height) makeImage($product_image, 0, $height, $destination) or die("Cannot upload the image"); else makeImage($product_image, 0, $y, $destination) or die("Cannot upload the image"); } else{ if ($x >= $width) makeImage($product_image, $width, 0, $destination) or die("Cannot upload the image"); else makeImage($product_image, $x, 0, $destination) or die("Cannot upload the image"); } if($watermark == "Y") waterMark($destination, "../../upload/$wmfile"); return true; } else return false; } function showimage($imagepath, $imagewidth, $imageheight, $error_msg="No image", $imageid=""){ if(is_file($imagepath)){ $img = ImageCreateFromJpeg($imagepath); $y = ImageSY($img); $x = ImageSX($img); if($y >= $x){ if($y > $imageheight) $myphoto = ""; else $myphoto = ""; }else{ if($x > $imagewidth) $myphoto = ""; else $myphoto = ""; } } else $myphoto = "$error_msg"; if($myphoto != "") echo "$myphoto"; } function waterMark($fileInHD, $wmFile, $transparency = 50, $jpegQuality = 90, $margin = 20) { $wmImg = imageCreateFromGIF($wmFile); $jpegImg = imageCreateFromJPEG($fileInHD); // Water mark random position $wmX = (imagesx($jpegImg) - imagesx($wmImg)) / 2; $wmY = imagesy($jpegImg) + $margin; // Water mark process imageCopyMerge($jpegImg, $wmImg, $wmX, $wmY, 0, 0, imageSX($wmImg), imageSY($wmImg), $transparency); // Overwriting image ImageJPEG($jpegImg, $fileInHD, $jpegQuality); } function substr_big5($str,$ct) { if(strlen($str) > $ct) { for($i=0;$i<$ct;$i++) { $ch=substr($str,$i,1); if(ord($ch)>127) $i++; } $str= substr($str,0,$i); } return $str; } ?>