PHP给图片增多水印得类
PHP给图片增加水印得类
<?php/*+--------------------------------------| 生成加水印的图片类 (支持水印为图片或者文字)| ============================| by JackMing (感谢Dash和其他不知道姓名的朋友支持,本类在这些朋友作品的基础上创建)+--------------------------------------*/Class Gimage{var $src_image_name = ""; //输入图片的文件名(必须包含路径名)var $jpeg_quality = 90; //jpeg图片质量var $save_image_file = ''; //输出文件名var $wm_image_name = ""; //水印图片的文件名(必须包含路径名)var $wm_image_pos = 1; //水印图片放置的位置// 0 = middle// 1 = top left// 2 = top right// 3 = bottom right// 4 = bottom left// 5 = top middle// 6 = middle right// 7 = bottom middle// 8 = middle left//other = 3var $wm_image_transition = 20; //水印图片与原图片的融合度 (1=100)var $wm_text = ""; //水印文字(支持中英文以及带有\r\n的跨行文字)var $wm_text_size = 20; //水印文字大小var $wm_text_angle = 4; //水印文字角度,这个值尽量不要更改var $wm_text_pos = 3; //水印文字放置位置var $wm_text_font = ""; //水印文字的字体var $wm_text_color = "#cccccc"; //水印字体的颜色值function create($filename=""){if ($filename) $this->src_image_name = strtolower(trim($filename));$src_image_type = $this->get_type($this->src_image_name);$src_image = $this->createImage($src_image_type,$this->src_image_name);if (!$src_image) return;$src_image_w=ImageSX($src_image);$src_image_h=ImageSY($src_image);if ($this->wm_image_name){$this->wm_image_name = strtolower(trim($this->wm_image_name));$wm_image_type = $this->get_type($this->wm_image_name);$wm_image = $this->createImage($wm_image_type,$this->wm_image_name);$wm_image_w=ImageSX($wm_image);$wm_image_h=ImageSY($wm_image);$temp_wm_image = $this->getPos($src_image_w,$src_image_h,$this->wm_image_pos,$wm_image);$wm_image_x = $temp_wm_image["dest_x"];$wm_image_y = $temp_wm_image["dest_y"];imageCopyMerge($src_image, $wm_image,$wm_image_x,$wm_image_y,0,0,$wm_image_w,$wm_image_h,$this->wm_image_transition);}if ($this->wm_text){$this->wm_text = $this->gb2utf8($this->wm_text);$temp_wm_text = $this->getPos($src_image_w,$src_image_h,$this->wm_text_pos);$wm_text_x = $temp_wm_text["dest_x"];$wm_text_y = $temp_wm_text["dest_y"];if(preg_match("/([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i", $this->wm_text_color, $color)){$red = hexdec($color[1]);$green = hexdec($color[2]);$blue = hexdec($color[3]);$wm_text_color = imagecolorallocate($src_image, $red,$green,$blue);}else{$wm_text_color = imagecolorallocate($src_image, 255,255,255);}imagettftext($src_image, $this->wm_text_size, $this->wm_angle, $wm_text_x, $wm_text_y, $wm_text_color,$this->wm_text_font,$this->wm_text);}if ($this->save_file){switch ($this->output_type){case 'gif':$src_img=ImagePNG($src_image, $this->save_file); break;case 'jpeg':$src_img=ImageJPEG($src_image, $this->save_file, $this->jpeg_quality); break;case 'png':$src_img=ImagePNG($src_image, $this->save_file); break;default:$src_img=ImageJPEG($src_image, $this->save_file, $this->jpeg_quality); break;}}else{if ($src_image_type = "jpg") $src_image_type="jpeg";header("Content-type: image/{$src_image_type}");switch ($src_image_type){case 'gif':$src_img=ImagePNG($src_image); break;case 'jpg':$src_img=ImageJPEG($src_image, "", $this->jpeg_quality);break;case 'png':$src_img=ImagePNG($src_image);break;default:$src_img=ImageJPEG($src_image, "", $this->jpeg_quality);break;}}imagedestroy($src_image);}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/*createImage 根据文件名和类型创建图片内部函数$type: 图片的类型,包括gif,jpg,png$img_name:图片文件名,包括路径名,例如 " ./mouse.jpg"*/function createImage($type,$img_name){if (!$type){$type = $this->get_type($img_name);}switch ($type){case 'gif':if (function_exists('imagecreatefromgif'))[email protected]($img_name);break;case 'jpg':$tmp_img=ImageCreateFromJPEG($img_name);break;case 'png':$tmp_img=ImageCreateFromPNG($img_name);break;default:$tmp_img=ImageCreateFromString($img_name);break;}return $tmp_img;}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++getPos 根据源图像的长、宽,位置代码,水印图片id来生成把水印放置到源图像中的位置内部函数$sourcefile_width: 源图像的宽$sourcefile_height: 原图像的高$pos: 位置代码// 0 = middle// 1 = top left// 2 = top right// 3 = bottom right// 4 = bottom left// 5 = top middle// 6 = middle right// 7 = bottom middle// 8 = middle left$wm_image: 水印图片ID*/function getPos($sourcefile_width,$sourcefile_height,$pos,$wm_image=""){if($wm_image){$insertfile_width = ImageSx($wm_image);$insertfile_height = ImageSy($wm_image);}else {$lineCount = explode("\r\n",$this->wm_text);$fontSize = imagettfbbox($this->wm_text_size,$this->wm_text_angle,$this->wm_text_font,$this->wm_text);$insertfile_width = $fontSize[2] - $fontSize[0];$insertfile_height = count($lineCount)*($fontSize[1] - $fontSize[3]);}switch ($pos){case 0:$dest_x = ( $sourcefile_width / 2 ) - ( $insertfile_width / 2 );$dest_y = ( $sourcefile_height / 2 ) - ( $insertfile_height / 2 );break;case 1:$dest_x = 0;if ($this->wm_text){$dest_y = $insertfile_height;}else{$dest_y = 0;}break;case 2:$dest_x = $sourcefile_width - $insertfile_width;if ($this->wm_text){$dest_y = $insertfile_height;}else{$dest_y = 0;}break;case 3:$dest_x = $sourcefile_width - $insertfile_width;$dest_y = $sourcefile_height - $insertfile_height;break;case 4:$dest_x = 0;$dest_y = $sourcefile_height - $insertfile_height;break;case 5:$dest_x = ( ( $sourcefile_width - $insertfile_width ) / 2 );if ($this->wm_text){$dest_y = $insertfile_height;}else{$dest_y = 0;}break;case 6:$dest_x = $sourcefile_width - $insertfile_width;$dest_y = ( $sourcefile_height / 2 ) - ( $insertfile_height / 2 );break;case 7:$dest_x = ( ( $sourcefile_width - $insertfile_width ) / 2 );$dest_y = $sourcefile_height - $insertfile_height;break;case 8:$dest_x = 0;$dest_y = ( $sourcefile_height / 2 ) - ( $insertfile_height / 2 );break;default:$dest_x = $sourcefile_width - $insertfile_width;$dest_y = $sourcefile_height - $insertfile_height;break;}return array("dest_x"=>$dest_x,"dest_y"=>$dest_y);}/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++gb2utf8 指定的文字转换为UTF-8格式,包括中英文混合内部函数*/function gb2utf8($gb){if(!trim($gb))return $gb;$filename="./gb2312.txt";$tmp=file($filename);$codetable=array();while(list($key,$value)=each($tmp))$codetable[hexdec(substr($value,0,6))]=substr($value,7,6);$utf8="";while($gb){if (ord(substr($gb,0,1))>127){$tthis=substr($gb,0,2);$gb=substr($gb,2,strlen($gb)-2);$utf8.=$this->u2utf8(hexdec($codetable[hexdec(bin2hex($tthis))-0x8080]));}else{$tthis=substr($gb,0,1);$gb=substr($gb,1,strlen($gb)-1);$utf8.=$this->u2utf8($tthis);}}return $utf8;}function u2utf8($c){$str="";if ($c < 0x80){$str.=$c;}else if ($c < 0x800){$str.=chr(0xC0 | $c>>6);$str.=chr(0x80 | $c & 0x3F);}else if ($c < 0x10000){$str.=chr(0xE0 | $c>>12);$str.=chr(0x80 | $c>>6 & 0x3F);$str.=chr(0x80 | $c & 0x3F);}else if ($c < 0x200000){$str.=chr(0xF0 | $c>>18);$str.=chr(0x80 | $c>>12 & 0x3F);$str.=chr(0x80 | $c>>6 & 0x3F);$str.=chr(0x80 | $c & 0x3F);}return $str;}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++get_type 获得图片的格式,包括jpg,png,gif内部函数$img_name: 图片文件名,可以包括路径名*/function get_type($img_name)//获取图像文件类型{$name_array = explode(".",$img_name);if (preg_match("/\.(jpg|jpeg|gif|png)$/", $img_name, $matches)){$type = strtolower($matches[1]);}else{$type = "string";}return $type;}}?>
使用方法:
$img = new Gimage();
$img->wm_text = "www.discuz.com";
$img->wm_text_font = "./STXINWEI.TTF";
$img->create("./mouse.jpg");
就可以了,其中
mouse.jpg是你要在其上添加水印的图片名称,注意包含路径名
STXINWEI.TTF是字体文件的路径名+文件名
这就是一个简单的测试。如果要调整更复杂的显示效果,只要修改一下类中的属性就可以了,例如把字体放大就可以
$img->wm_text_size = 20;
增加水印图片就可以
$img->wm_image_name="文件名";

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











이 기사에서는 무료 BingImageCreator를 사용하여 고품질 출력을 얻는 7가지 방법을 소개합니다. BingImageCreator(현재 Microsoft Designer용 ImageCreator로 알려짐)는 훌륭한 온라인 인공 지능 아트 생성기 중 하나입니다. 사용자 프롬프트를 기반으로 매우 사실적인 시각 효과를 생성합니다. 프롬프트가 더 구체적이고 명확하며 창의적일수록 결과는 더 좋아질 것입니다. BingImageCreator는 고품질 이미지 생성에 있어 상당한 진전을 이루었습니다. 이제 Dall-E3 트레이닝 모드를 사용하여 더 높은 수준의 디테일과 현실감을 보여줍니다. 그러나 일관되게 HD 결과를 생성하는 능력은 빠른 속도를 포함한 여러 요인에 따라 달라집니다.

Xiaomi 휴대폰에서 이미지를 삭제하는 방법 Xiaomi 휴대폰에서 이미지를 삭제할 수 있지만 대부분의 사용자는 이미지 삭제 방법을 모릅니다. 다음은 편집자가 가져온 Xiaomi 휴대폰에서 이미지 삭제 방법에 대한 튜토리얼입니다. 와서 우리와 함께 보자! Xiaomi 휴대폰에서 이미지를 삭제하는 방법 1. 먼저 Xiaomi 휴대폰에서 [앨범] 기능을 엽니다. 2. 그런 다음 불필요한 사진을 확인하고 오른쪽 하단에 있는 [삭제] 버튼을 클릭합니다. 상단의 특수 영역에 들어가려면 [휴지통]을 선택합니다. 4. 그런 다음 아래 그림과 같이 [휴지통 비우기]를 직접 클릭합니다. 5. 마지막으로 [영구 삭제]를 직접 클릭하여 완료합니다.

LINUX는 유연성과 사용자 정의 가능성으로 인해 많은 개발자와 시스템 관리자가 가장 먼저 선택하는 운영 체제입니다. LINUX 시스템에서 이미지 처리는 매우 중요한 작업이며 Imagemagick과 Image는 매우 인기 있는 이미지 처리 도구입니다. 이 기사에서는 Centos 시스템에 Imagemagick 및 Image를 설치하는 방법을 소개하고 자세한 설치 튜토리얼을 제공합니다. Imagemagic 설치 Centos 튜토리얼 Imagemagick은 명령줄에서 다양한 이미지 작업을 수행할 수 있는 강력한 이미지 처리 도구 세트입니다. 다음은 Centos 시스템에 Imagemagick을 설치하는 단계입니다.

1. this 키워드 1. this 유형: 호출되는 개체는 해당 개체의 참조 유형입니다. 2. 사용법 요약 1. this.data;//Access 속성 2. this.func();//Access 메서드 3.this ( );//이 클래스의 다른 생성자를 호출합니다. 3. 사용법 설명 1.this.data가 멤버 메서드에 사용됩니다. 이것이 추가되지 않으면 어떻게 되는지 살펴보겠습니다. classMyDate{publicintyear;publicintmonth;publicintday; 월,월){예

Vue2의 이 포인팅 문제로 인해 동료가 버그로 인해 화살표 기능이 사용되어 해당 소품을 얻을 수 없게 되었습니다. 제가 그에게 소개했을 때 그는 그것을 몰랐고, 그래서 저는 일부러 프론트엔드 커뮤니케이션 그룹을 살펴보았습니다. 지금까지 적어도 70%의 프론트엔드 프로그래머들은 오늘 그것을 이해하지 못하고 있습니다. 모든 것이 불분명하다면 이 링크를 아직 배우지 않았다면 큰 소리로 말해주세요.

jQuery는 웹 개발에서 DOM 조작 및 이벤트 처리에 널리 사용되는 인기 있는 JavaScript 라이브러리입니다. 중요한 개념 중 하나는 이 키워드를 사용하는 것입니다. jQuery에서 이는 현재 작동 중인 DOM 요소를 나타내지만, 다른 컨텍스트에서는 이것의 포인터가 다를 수 있습니다. 이 기사에서는 특정 코드 예제를 통해 jQuery에서 이에 대한 사용 기술을 분석합니다. 먼저 간단한 예를 살펴보겠습니다.

JavaScript의 화살표 함수는 자체 this 키워드가 없는 비교적 새로운 구문입니다. 반대로 화살표 함수의 this는 이를 포함하는 범위 개체를 가리킵니다. 1. 화살표 함수의 This는 다음과 같습니다. 2. 화살표 함수는 생성자로 사용할 수 없습니다. 3. 화살표 함수는 메서드로 사용할 수 없습니다.

이게 뭔가요? 다음 기사에서는 JavaScript에서 이에 대해 소개하고 다양한 함수 호출 방법의 차이점에 대해 설명하겠습니다. 도움이 되기를 바랍니다.
