PHP:
$contents = $msg;
$title = $th;
/*--------------------------------------------------------------------*/
$url = '/forum/';// du?ng d?n tuy?t d?i d?n thu m?c m? c?a thu m?c photo
$dir = 'photo';//thu m?c m?c d?nh ch?a ?nh, không nên s?a
$w=200;//chi?u r?ng c?n resize
$h=200;//chi?u cao c?n resize
function watermark($input,$source,$link,$w,$h,$rs){
preg_match ('#\.jpg$#i',$input) ? $im_input = imagecreatefromjpeg($input):'';
preg_match ('#\.png$#i',$input) ? $im_input = imagecreatefrompng($input):'';
preg_match ('#\.gif$#i',$input) ? $im_input = imagecreatefromgif($input):'';
$im_source = imagecreatefrompng($source);
imagecopy($im_input, $im_source, imagesx($im_input)-imagesx($im_source)-4, imagesy($im_input)-imagesy($im_source)-4, 0, 0,imagesx($im_source),imagesy($im_source));
if ($rs == 'yes') {
$thumb = imagecreatetruecolor($w, $h);
imagecopyresized($thumb, $im_input, 0, 0, 0, 0, $w, $h, imagesx($im_input), imagesy($im_input));
preg_match ('#\.jpg$#i',$input) ? imagejpeg($thumb,$link):'';
preg_match ('#\.png$#i',$input) ? imagepng($thumb,$link):'';
preg_match ('#\.gif$#i',$input) ? imagegif($thumb,$link):'';
} else {
preg_match ('#\.jpg$#i',$input) ? imagejpeg($im_input,$link):'';
preg_match ('#\.png$#i',$input) ? imagepng($im_input,$link):'';
preg_match ('#\.gif$#i',$input) ? imagegif($im_input,$link):'';
}
}
function get_link ($input) {
preg_match_all ('#\[img\](.+?)\[/img\]#i',$input,$regex);
return $regex[1];
}
function get_img ($link,$name) {
copy ($link,$name);
return $name;
}
function replace_link ($a_r,$b_r,$str) {
return str_replace ($a_r,$b_r,$str);
}
$list = get_link ($contents); // l?y danh sách link ?nh
$new = array ();
$d = date ('d',time());
$m = date ('m',time());
$y = date ('y',time());
@mkdir ("$dir/$y/$m/$d",0777,true);
foreach ($list as $key=>$link) {
$end = preg_match('#(\.jpg)$#i',$link) ? '.jpg' : (preg_match('#(\.gif)$#i',$link) ? '.gif':'.png');
//echo "$dir/$y/$m/$d/" . convert ($title) . "-$key-" . $end ;
// print_r ($link) . '<br />';
$new[] = get_img ($link,"$dir/$y/$m/$d/" . convert ($title) . "-$key-" . $end);
watermark ($new[$key],'wtm.png',$new[$key],$w,$h,$rs);
}
foreach ($new as $key=>$val) {
$new[$key] = $url . $val;
}
$contents = preg_replace ('#\[img\](.+?)\[/img\]#is','[img]$1[/img]',replace_link ($list,$new,$contents));
/*-------------------------------------------------------------------*/
$msg = $contents;
PHP:
if (!$error) {
unset($_SESSION['token']);
Xong