圖片+文字水印

*注意:路徑問題

class Listinfo extends BaseController
{
public $path = "/workspace/smar_xd/backend/resources/img/";
public $font_path = "/workspace/smar_xd/backend/resources/font/Degrassi.ttf";
public $font_size = 30;
public $water_mark_text_2 = 'SHUIYIN';
public function __construct()
{
parent::__construct();
}


public function index(){
$path = "/workspace/smar_xd/backend/resources/img/";
$valid_formats = array("jpg", "bmp","jpeg");
if( $this->input->post('createmark') && $this->input->post('createmark') == 'submit'){
$name = $_FILES['imgfile']['name'];
if( strlen( $name)){
list($txt, $ext) = explode(".", $name);
// if( in_array( $ext, $valid_formats) && $_FILES['imgfile']['size'] <= 256*1024){
//*注:$path必須爲絕對路徑!
$upload_status = move_uploaded_file($_FILES['imgfile']['tmp_name'], $path.$_FILES['imgfile']['name']);
if( $upload_status){
$new_name = time().".".$ext;
if( $this->water_mark_text($path.$name,$new_name)){
echo "ok";
}
}else{
echo 'error';
}
// }
}
}
$this->load->view('upload');
}

public function water_mark_text( $oldImageName, $newImageName ){
$path = $this->path;
$font_size = $this->font_size;
$font_path = $this->font_path;
$water_mark_text_2 = $this->water_mark_text_2;
list($owidth, $oheight) = getimagesize( $oldImageName);
$width = $height = 300;
$image = imagecreatetruecolor($width, $height);
$imageSrc = imagecreatefromjpeg( $oldImageName);
imagecopyresampled($image, $imageSrc, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
$blue = imagecolorallocate($image, 79, 166, 185);
imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2);
imagejpeg($image, $path.$newImageName, 100);
imagedestroy( $image);
unlink( $oldImageName);
return true;
}
}

發佈了95 篇原創文章 · 獲贊 11 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章