PHP ??? ???? ??
???? ??? ?? ?? ? ?? ??? ?????. ????? ??? ???? ?? ???? ??? ?? ???? ??? ?????.
?? ???? ??? ?? ??? ?????. ????? ??? ?? ??? ?? ??? ????.
??? ?? ???? ??:
1. ??? ??
2. ???? ???? ??
3. ??? ??? ??
?? ???? ??? ??? ? ?? ??, ? ? ?? ??? ?? ?? ??? ?????. ? ??? ?? ???? ?? ???? ?????.
???? ??? ? ? ?? ??? ?????.
1. ?? ???(?? ?? ?????? ?)? ???.
2. ???? ??? ?? (???? ?? ?????? ?)
3. imagecopymerge? ???? ?? ???? ? ???? ??? ??? ??
4. ??? ??
.5 ??? ??
1. ?? ??? ????
????? ??? ?? ???(d:/? ???? ??? ??) www/img/meinv.jpg ? ???), ??? ??? ????.
???? ? ?? ??(d:/? ???? ??? ??) www/img/logo.png ? ???) ??? ??? ????.
?? ??? ?? ? ??? ???? ????.
bool imagecopymerge (resource $ target image, resources $ source image, int $ target start x, int $target start y, int $source x, int $source y, int $source width, int $source height, int $transparency )
??:
??? ?? 0~100? ?????. imagecopy? imagecopymerge? ???? ??? ???? ?? ?? ??? ???? ??? ????.
??? ??? ?? ??? ??? ?????.
<?php //打開目標圖片 $dst = imagecreatefrompng('/upload/course/000/000/002/5833ebba648cf229.png'); //打開Logo來源圖片 $src = imagecreatefrompng('/upload/course/000/000/002/5833ebe90cc11285.png'); //得到目標圖片的寬高 $dst_info = getimagesize('5833ebba648cf229.png'); //得到logo圖片的寬高 $src_info = getimagesize('5833ebe90cc11285.png'); //放到最右下腳可得出圖片水印圖片需要開始的位置即: //x點位置:需要大圖的寬 - 小圖的寬; //y點位置:放大圖的高 - 小圖的高 $dst_x = $dst_info[0] - $src_info[0]; $dst_y = $dst_info[1] - $src_info[1]; //要將圖片加在右下腳 imagecopymerge($dst, $src, $dst_x, $dst_y, 0, 0, $src_info[0], $src_info[1], 100); header('Content-type:image/png'); imagepng($dst); imagedestroy($dst); imagedestroy($src); ?>
??? ?? ?? ??? ?????.
2. A? ???. ??? ??? ???? ??
1. ???? ???? ?? ??? ?? ? ????
??? ??? ??? ?? ?? ??? ?? ??? ?? ?????.
1.
2.imagecreatetruecolor
3.imagecreatefromjpeg ?
??? ???. ???? MIME ??? ?? ??? ?? ? ??? MIME ??? ???? ??? ?? ??? ?? ? ????.
??? ? ??? ? ???? ????.
1. ?? MIME ??? ?? ??? ?????.
2. ??? ????, ??? ??, ???? ?????.
???? ?? ? ??? ? ?? ???? ?? ? ????.
??? ??? ????, ???? ??, ??, MIME ??? ??? ????, ??? ? ?? ????? ?????.
$data? ?? ?? ??? MIME ??? ??? ? ????. ??? ??? ????.
function getImageInfo($path) { $info = getimagesize($path); $data['width'] = $info[0]; $data['height'] = $info[1]; $data['type'] = $info['mime']; return $data; }
??? ?? ??? ??? ???? ??? ??? ???? ???? ??? ??? ??? ???? ?????.
?? ???? $type? switch...case? ???? ?????. imagejpeg? ?? $path? ??? ??? ??? ??? ?? ? imagecreatefromjpeg? ?????. ????? ??? ??? ?????.
function openImg($path, $type) { switch ($type) { case 'image/jpeg': case 'image/jpg': case 'image/pjpeg': $img = imagecreatefromjpeg($path); break; case 'image/png': case 'image/x-png': $img = imagecreatefrompng($path); break; case 'image/gif': $img = imagecreatefromgif($path); break; case 'image/wbmp': $img = imagecreatefromwbmp($path); break; default: exit('圖片類型不支持'); } return $img; }
?? ?? ??:
??? 0~9 ??? 10? ??? ?? ? ????.
??? ???? ??? ?????.
??:
0? ??? ???? ??? ? ????. ???? ?? ????. ??? ??? ??? ??? ?? ????.
0? ??:
x = 0 至 (大圖寬 - 小圖寬) y = 0 至 (大圖高 - 小圖高)
1? ??:
x = 0 y = 0
2? ??:
x = (大圖寬 - 小圖寬) /2 y = 0
3? ??: :
x = 大圖寬 - 小圖寬 y = 0
4? ???
x = 0 y = (大圖高 - 小圖高) / 2
... ...????.
0~9? ?? ??? ?? ??? ?????.
switch($pos){ case 1: $x=0; $y=0; break; case 2: $x=ceil(($info['width']-$logo['width'])/2); $y=0; break; case 3: $x=$info['width']-$logo['width']; $y=0; break; case 4: $x=0; $y=ceil(($info['height']-$logo['height'])/2); break; case 5: $x=ceil(($info['width']-$logo['width'])/2); $y=ceil(($info['height']-$logo['height'])/2); break; case 6: $x=$info['width']-$logo['width']; $y=ceil(($info['height']-$logo['height'])/2); break; case 7: $x=0; $y=$info['height']-$logo['height']; break; case 8: $x=ceil(($info['width']-$logo['width'])/2); $y=$info['height']-$logo['height']; break; case 9: $x=$info['width']-$logo['width']; $y=$info['height']-$logo['height']; break; case 0: default: $x=mt_rand(0,$info['width']-$logo['width']); $y=mt_rand(0,$y=$info['height']-$logo['height']); break; }
????? ??? ??, ?? ? ?? ??? ?????.
imagecopymerge($dst,$src,$x,$y,0,0,$logo['width'],$logo['height'],$tm);
? ? ?? ??? ?????. , ??? ? ? ?? ??? ?????:
rree? ?? ?? ???? ?? ?? ??? ??, ??? ?? ????.
? ??? ??? ???:
??? ?? ??? ??? ??? ???? ????. ?? ???? Fan Bingbing ??? ?? ??? ????.
? ?? ??? ??? ???? ?????.
??? ?????!