php圖片處理:加水印、縮略圖的實(shí)現(xiàn)(自定義函數(shù):watermark、thumbnail)
Jun 13, 2016 pm 12:12 PM
廢話不說(shuō)了,貼代碼:
復(fù)制代碼 代碼如下:
/************************************
//函數(shù): watermark($bigimg, $smallimg, $coord = 1)
//作用: 添加水印
//參數(shù):
$bigimg 必選。大圖片--要加上水印的圖片
$smallimg 必選。小圖片
$coord 可選。水印在大圖中的位置,
1 左上角; 2 右上角; 3 右下角; 4 左下角; 5 中間
//示例: watermark('datu.png', 'xiaotu.png', 3); //給datu.png打上水印,水印位置在右下角
*************************************/
function watermark($bigimg, $smallimg, $coord = 1){
//載入兩張圖片,并轉(zhuǎn)成php識(shí)別的編碼格式,
//等同于 imagecreate 函數(shù),只不過(guò)這里創(chuàng)建的不是一個(gè)空?qǐng)D片。
$bi = getimagesize($bigimg);
switch($bi[2]){
case 1:
$im1 = imagecreatefromgif($bigimg);break;
case 2;
$im1 = imagecreatefromjpeg($bigimg);break;
case 3;
$im1 = imagecreatefrompng($bigimg);break;
}
$si = getimagesize($smallimg);
switch($si[2]){
case 1:
$im2 = imagecreatefromgif($smallimg);break;
case 2;
$im2 = imagecreatefromjpeg($smallimg);break;
case 3;
$im2 = imagecreatefrompng($smallimg);break;
}
// 創(chuàng)建水印--原理:復(fù)制小圖到大圖上。這里注意坐標(biāo)值的計(jì)算
switch($coord){
case 1:
imagecopy ( $im1, $im2, 0, 0, 0, 0, $si[0], $si[1] ); break;
case 2:
imagecopy ( $im1, $im2, $bi[0]-$si[0], 0, 0, 0, $si[0], $si[1] ); break;
case 3:
imagecopy ( $im1, $im2, $bi[0]-$si[0], $bi[1]-$si[1], 0, 0, $si[0], $si[1] ); break;
case 4:
imagecopy ( $im1, $im2, 0, $bi[1]-$si[1], 0, 0, $si[0], $si[1] ); break;
case 5:
imagecopy ( $im1, $im2, ($bi[0]-$si[0])/2, ($bi[1]-$si[1])/2, 0, 0, $si[0], $si[1] ); break;
}
//根據(jù)后綴名生成不同格式的圖片文件
switch($bi[2]){
case 1:
imagegif($im1);break;
case 2;
imagejpeg($im1);break;
case 3;
imagepng($im1);break;
}
imagedestroy($im1);
}
/************************************************
//函數(shù): thumbnail($srcimg, $multiple)
//作用: 生成一張縮略圖
//參數(shù):
// $srcimg 必選。源圖片文件名
// $multiple 可選??s略倍數(shù),默認(rèn)為2倍,即縮小為原來(lái)的1/2
//注意: 只支持gif、jpg、png的格式圖片。
//示例: thumbnail('我的圖片.jpg', 5);
*************************************************/
function thumbnail($srcimg, $multiple = 2){
//載入圖片并保存其信息到數(shù)組
$srcimg_arr = getimagesize($srcimg);
//計(jì)算縮略倍數(shù)
$thumb_width = $srcimg_arr[0] / $multiple;
$thumb_height = $srcimg_arr[1] / $multiple;
//判斷:要建立什么格式的圖片(轉(zhuǎn)成php識(shí)別的編碼)
switch($srcimg_arr[2]){
case 1:
$im = imagecreatefromgif($srcimg);break;
case 2;
$im = imagecreatefromjpeg($srcimg);break;
case 3;
$im = imagecreatefrompng($srcimg);break;
}
//開(kāi)始縮略操作
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresized($thumb, $im, 0, 0, 0 ,0, $thumb_width, $thumb_height, $srcimg_arr[0], $srcimg_arr[1]);
switch($srcimg_arr[2]){
case 1:
imagegif($thumb); break;
case 2;
imagejpeg($thumb); break;
case 3;
imagepng($thumb); break;
}
imagepng($thumb);
imagedestroy($thumb);
}
//測(cè)試 時(shí)不要同時(shí)使用這兩個(gè)函數(shù)。
//watermark('datu.png','xiaotu.png',5);
thumbnail('abc.png',3);
?>

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ?? ??? ??? ?? JavaScript? MediareCorder API? ?? PHP ???? ???? ?????. 2. PHP? ???? ?? ??? ???? STTAPI (? : Google ?? Baidu ?? ??)? ???? ???? ?????. 3. PHP? ???? AI ??? (? : OpenAigpt)? ????. 4. ?? ?? PHP? TTSAPI (? : Baidu ?? Google ?? ??)? ???? ??? ?? ??? ?????. 5. PHP? ?? ??? ??? ??? ??? ?? ?? ??? ?????. ?? ????? PHP? ?? ???? ?? ?? ?? ??? ??? ?????.

PHP?? ?? ?? ??? ???? ?? ??? ? ???? ?? ??? ???? ?? ??? ???? ???? ????. 1. ?? ?? ??? ?? ??? URL ? ?? ??? ????. 2. UrlenCode? ???? ?? ??? ???????. 3. ? ???? ????? ?? ?? ??? ? ?? ??? ?????. 4. ???? ???? ?? ? ? ??? ??? ??? ??? ?????. 5. ??? ?? ??? ????? ?? ????? OG ??? ???? ?????. 6. XSS ??? ???? ?? ??? ??? ?????. ? ???? ??? ??? ???? ??? ?? ?? ??? ??? ???? ??? ?? ??? ?????.

AI? ??? ??? ?? ?? ? ?? ???? ????? ?? ??? ??????. 1. Baidu, Tencent API ?? ?? ?? NLP ?????? ?? ??? AI ?? ?? API? ??????. 2. PHP? ? ?? guzzle? ?? API? ???? ?? ??? ??????. 3. ?? ????? ?? ?? ??? ???? ???? ???? ??? ??? ? ????. 4. ?? ?? ? ?? ???? ?? PHP-L ? PHP_CODESNIFFER? ??????. 5. ???? ????? ???? ?? ?? ??? ?????? ??? ??????. AIAPI? ??? ? ???, ?? ??, ?? ? PHP ?? ??? ??? ???. ?? ???? PSR ??? ???, ??? ????? ????, ?? ??? ???, ????? ??? ????, X? ???????.

1. ?? ???? ??? ??? ?????? ?? ?? ??? ??, ??? ?? ???? ??? (? : ?? ???, ? ? ??), ?? ??? ?? ???? ???? ? ?? ?? ??? ??? ?? ??? ????????. 2. ?? ??? ??? ?? ? ??? ???? ?? ?? ?? ???? ?? ? ?? AUDIT ?? ??? ??? ? ????? ????? ??? ???????. 3. ?? ?? ??? ?? ??? ???????. Recaptchav3 ???? ??, ??? ?? ?? ?? ?? ??, IP ? ?? ??? ??? ??? ?? ???? ??? ?? ??? ????? ??? ???? ????? ??? ?????.

PHP? ?????? ????? ?? ?? ?? ???? ???? ?? ???? ???? ?? ?? ???? ?????. 2. ?? ??? ???? ???? ?? ??? ?? ? ??? ??? ???? ?? API/Webhook ??? ??? ?? ???? ??? ??? ??? ??? ?????. 3. ?? ????? ?? ??, ??/???? ????, ???? ??, ???? ? ??? ?????? ????? ?? ??? ???? ???? ?? Dingtalk, SMS ?? ??? ???? ??? ?????? ???? ?? ? ??? ??? ????? ?? ??? ???? ???????.

PhpisstillRelevantinmodernenterpriseenvironments.1. Modernphp (7.xand8.x)? ??? ??, ??? ??, jitcompilation ? modernsyntax, mateitsuilableforlarge-scalepplications

MAC ?? ???? ? ??? ?? ??? ????? ?? ? ??? ????? ????. 1. ???? ???? ???? ???? ??? ?? ? ?? ????? ??? ???? ??????. 2. ????? ?? ?? ? ??? ???? ???? ?? ?? ????? ??? ???? ?????. 3. ??? ?? ??? ???? ?? ???? ?? ???? ?? ???? ?? ? ? ????. 4. ??? ????? ????? ? ?? ?? ? ??? ?? ? ??? ??????.

N 1 ?? ??? ??? ?? ???? ?????? ?????? ?? ?? ????. 2. ???? ???? ???? ?? ??? ???????? ??? ??? ?? ? ??????. 3. ??? 2 ? ?? ?? Redis ?? ??? ?? ??? ?? ?? ??? ????? ??????. 4. ??? ????? ????? ????? Clear ()? ???? ???? ?????? ??? ????? ?????. 5. ?????? ??? ????? ???? ???? ? ??? ??? ?? ?? ? SQL ?? ??????. 6. ?? ??? ???? ?? ?????? ?? ?? ??? ?????? ?? ?? ?? ??? ???? ??? ??????. ORM? ???? ????? ?? ??? ????? ?? ???? ??? ???? ?? SQL ????, ??, ?? ?? ? ??? ???? ???????.
