<?php
/**
* ¸Ä±äͼƬµÄ¿í¸ß
*
* @author flynetcn (2009-12-16)
*
* @param string $img_src ÔͼƬµÄ´æ·ÅµØÖ·»òurl
* @param string $new_img_path ÐÂͼƬµÄ´æ·ÅµØÖ·
* @param int $new_width ÐÂͼƬµÄ¿í¶È
* @param int $new_height ÐÂͼƬµÄ¸ß¶È
* @return bool ³É¹¦true, ʧ°Üfalse
*/
function resize_image($img_src, $new_img_path, $new_width, $new_height)
{
$img_info = @getimagesize($img_src);
if (!$img_info || $new_width < 1 || $new_height < 1 || empty($new_img_path)) {
return false;
}
if (strpos($img_info['mime'], 'jpeg') !== false) {
$pic_obj = imagecreatefromjpeg($img_src);
} else if (strpos($img_info['mime'], 'gif') !== false) {
$pic_obj = imagecreatefromgif($img_src);
} else if (strpos($img_info['mime'], 'png') !== false) {
$pic_obj = imagecreatefrompng($img_src);
} else {
return false;
}
$pic_width = imagesx($pic_obj);
$pic_height = imagesy($pic_obj);
if (function_exists("imagecopyresampled")) {
$new_img = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($new_img, $pic_obj, 0, 0, 0, 0, $new_width, $new_height, $pic_width, $pic_height);
} else {
$new_img = imagecreate($new_width, $new_height);
imagecopyresized($new_img, $pic_obj, 0, 0, 0, 0, $new_width, $new_height, $pic_width, $pic_height);
}
if (preg_match('~.([^.]+)$~', $new_img_path, $match)) {
$new_type = strtolower($match[1]);
switch ($new_type) {
case 'jpg':
imagejpeg($new_img, $new_img_path);
break;
case 'gif':
imagegif($new_img, $new_img_path);
break;
case 'png':
imagepng($new_img, $new_img_path);
break;
default:
imagejpeg($new_img, $new_img_path);
}
} else {
imagejpeg($new_img, $new_img_path);
1. ¶ÔÓÚPHP magic_quotes_gpc=onµÄÇé¿ö£¬ ÎÒÃÇ¿ÉÒÔ²»¶ÔÊäÈëºÍÊä³öÊý¾Ý¿âµÄ×Ö·û´®Êý¾Ý×÷
addslashes()ºÍstripslashes()µÄ²Ù×÷,Êý¾ÝÒ²»áÕý³£ÏÔʾ¡£ Èç¹û´ËʱÄã¶ÔÊäÈëµÄÊý¾Ý×÷ÁËaddslashes()´¦Àí£¬
ÄÇôÔÚÊä³öµÄʱºò¾Í±ØÐëʹÓÃstripslashes()È¥µô¶àÓàµÄ·´Ð±¸Ü¡£ 2. ¶ÔÓÚPHP magic_quotes_gpc=off µÄÇé¿ö ±ØÐëÊ¹Ó ......
ÎÒÃǵĵ绰±¨ÃûϵͳÖУ¬ºô½ÐÖÐÐÄÊÕ¼¯ÁËÓû§µÄÒøÐÐÐÅÏ¢£¬È»ºóÇëÇóÒøÐеÄÖ§¸¶½Ó¿ÚµÄwebservice£¬ÐèÒª½øÐг¬Ê±ÉèÖã¬ÒòΪ²»ÄÜÒ»Ö±ÈÃѧԱµÈ´ý
½â¾ö·½·¨ÊÇ
1:Ê×ÏÈÏÈÒª¿´Ò»ÏÂphp.iniÀïµÄĬÈϳ¬Ê±Ê±¼ä£¬Ò»°ãÊÇ120Ãë
2£ºÔÚphp´úÂëÀï¼ÓÉÏ
ini_set('default_socket_timeout', 10);//ÉèÖó¬Ê±Ê±¼ä
ÈçÏÂͼ
......