$dp = opendir($url);
while($aa = readdir($dp)) {
fonts($aa,"xx公司",'./aa/');
}
close($dp);
}
function fonts($image,$fonts,$newpath,$position=9,$color=2,$size=16) {
//第壹個參數是圖片
//第二個參數是要寫的文字
//第三個參數是存儲的路徑
//第四個參數是顯示文字的位置(可選)
//第五個參數是顏色(可選 壹是黑色 二是白色)
//第六個參數是字體大小(可選)
$img = imagecreatefromjpeg($image);
if($color==1) {
$fontColor = imagecolorallocate($img,33,33,33);
}else{
$fontColor = imagecolorallocate($img,255,255,255);
}
$img_w = imagesx($img);
$img_h = imagesy($img);
$box = imagettfbbox($size,0,'STXINGKA.TTF',$fonts);
$box_w = $box[2]-$box[0];
$box_h = $box[7]-$box[1];
switch($position){
case 1:
$x = 10; $y = 36;
break;
case 2:
$x = ($img_w - $box_w)/2; $y = 36;
break;
case 3:
$x = $img_w - $box_w - 170; $y = 36;
break;
case 4:
$x = 10; $y = ($img_h - $box_h)/2;
break;
case 5:
$x = ($img_w - $box_w)/2; $y = ($img_h - $box_h)/2;
break;
case 6:
$x = $img_w - $box_w - 200; $y = ($img_h - $box_h)/2;
break;
case 7:
$x = 20; $y = ($img_h - $box_h)-60;
break;
case 8:
$x = ($img_w - $box_w)/2; $y = $img_h - $box_h-60;
break;
case 9:
$x = $img_w - $box_w-300 ; $y = $img_h - $box_h-60;
break;
}
imagettftext($img,30,0,$x,$y,$fontColor,'STXINGKA.TTF',$fonts);
//header('Content-Type:image/jpg');
imagejpeg($img,$newpath);
}
function reduce($oldpath,$newpath,$new_w) {
//第壹個參數是原圖片的路徑
//第二個參數是縮小圖片的路徑
//第三個參數是縮小圖片的寬度
$old = imagecreatefromjpeg($oldpath); //原圖片
$old_w = imagesx($old); //得到原圖片的寬
$old_h = imagesy($old); //得到原圖片的高
$new_h = $old_h/$old_w * $new_w;
$new = imagecreatetruecolor($new_w,$new_h); //新圖片
imagecopyresampled($new,$old,0,0,0,0,$new_w,$new_h,$old_w,$old_h);
//header('Content-Type:image/jpg');
imagejpeg($new,$newpath);
}
function water($bigpath,$smallpath,$newpath,$position=9) {
//第壹個參數大圖片
//第二個參數小圖片
//第三個參數是新圖片的路徑
//第四個參數是設置小圖片出現的位置
$big = imagecreatefromjpeg($bigpath); //得到大圖片
$small = imagecreatefromjpeg($smallpath); //得到小圖片
$small_w = imagesx($small); //得到小圖片的寬
$small_h = imagesy($small); //得到小圖片的高
$big_w = imagesx($big); //得到小圖片的寬
$big_h = imagesy($big); //得到小圖片的寬
switch($position) {
case 1:$x=2;$y=2;break;
case 2:$x=($big_w-$small_w)/2;$y=0;break;
case 3:$x=$big_w-$small_w;$y=0;break;
case 4:$x=0;$y=($big_h-$small_h)/2;break;
case 5:$x=($big_w-$small_w)/2;$y=($big_h-$small_h)/2;break;
case 6:$x=$big_w-$small_w;$y=($big_h-$small_h)/2;break;
case 7:$x=0;$y=$big_h-$small_h;break;
case 8:$x=($big_w-$small_w)/2;$y=$big_h-$small_h;break;
case 9:$x=$big_w-$small_w-2;$y=$big_h-$small_h-2;break;
}
imagecopymerge($big,$small,$x,$y,0,0,$small_w,$small_h,100); //合並兩個圖片 1> 大圖片資源 2> 小圖片資源 3,4>大圖片的坐標 5,6> 小圖片的坐標 7,8> 小圖片的寬和高 9>透明度
//header("Content-Type:image/jpg");
imagejpeg($big,$newpath);
}
只供參考 如果有興趣 可加761084316 我也是初學者