php水印图类
php
图片
标签
水印
图片加上标签 无 ?phprequire( './WaterMark.class.php' );$water = new WaterMark( './images/psb.jpg', './images/200(1).jpg' );$water-Exec( './images/w.jpg', 'center-center' );? ?php/** * Add water stain to specified image * @author pankai53091
图片加上标签
<?php require( './WaterMark.class.php' ); $water = new WaterMark( './images/psb.jpg', './images/200(1).jpg' ); $water->Exec( './images/w.jpg', 'center-center' ); ?>
登录后复制
<?php /** * Add water stain to specified image * @author pankai<530911044@qq.com> * @date 2013-09-27 */ class WaterMark { /* Image source path */ private $_src_path = NULL; private $_image_source = NULL; /* Water-Stain image source path */ private $_water_path = NULL; private $_water_source = NULL; private $_extension = NULL; public function __construct( $_src_path, $_water_path ) { $this->_src_path = $_src_path; $this->_water_path = $_water_path; } /** * Get image source form image designated path * @param $_img_path * @return resource */ private function getImageSource( $_img_path ) { $_path = explode( ".", strtolower( $_img_path ) ); $_bak = strtoupper( $_path[ sizeof( $_path ) - 1 ] ); $_img_source = NULL; $this->_extension = $_bak; switch( $_bak ) { case "GIF": $_img_source = @imagecreatefromgif( $_img_path ); break; case "JPG": case "JPEG": $_img_source = @imagecreatefromjpeg( $_img_path ); break; case "PNG": $_img_source = @imagecreatefrompng( $_img_path ); break; case "WBMP": $_img_source = @imagecreatefromwbmp( $_img_path ); break; } return $_img_source; } /** * Count coordinate * @param $direction string * @return array */ private function countArgs( &$_src, &$_water, $_direction ) { $_args = NULL; /** * Count the image's width and image's height * which are used to show Water-Stain image arbitrarily */ $src_x = imagesx( $_src ); $src_y = imagesy( $_src ); $water_x = imagesx( $_water ); $water_y = imagesy( $_water ); switch( strtolower( $_direction ) ) { case 'top-left': $_args = array( 0, 0 ); break; case 'top-center': $_args = array( floor( ( $src_x - $water_x ) / 2 ), 0 ); break; case 'top-right': $_args = array( $src_x - $water_x, 0 ); break; case 'center-left': $_args = array( 0, floor( ( $src_y - $water_y ) / 2 ) ); break; case 'center-center': $_args = array( floor( ( $src_x - $water_x ) / 2 ), floor( ( $src_y - $water_y ) / 2 ) ); break; case 'center-right': $_args = array( $src_x - $water_x, floor( ( $src_y - $water_y ) / 2 ) ); break; case 'bottom-left': $_args = array( 0, $src_y - $water_y ); break; case 'bottom-center': $_args = array( floor( ( $src_x - $water_x ) / 2 ), $src_y - $water_y ); break; case 'bottom-right': $_args = array( $src_x - $water_x, $src_y - $water_y ); break; } return $_args; } /** * The main programmer: copy Water-Stain image source into specified image source, * then save this into appointed path * @param $dst_name * @return bool */ public function Exec( $dst_name, $direction = 'bottom-right' ) { $this->_image_source = &$this->getImageSource( $this->_src_path ); $this->_water_source = &$this->getImageSource( $this->_water_path ); $water_x = imagesx( $this->_water_source ); $water_y = imagesy( $this->_water_source ); $_args = $this->countArgs( $this->_image_source, $this->_water_source, $direction ); $_copy = imagecopy( $this->_image_source, $this->_water_source, abs( $_args[ 0 ] ), abs( $_args[ 1 ] ), 0, 0, $water_x, $water_y ); $_out = true; /* imagejpeg( $this->img_dst, $dst_name, 100 ); */ switch ( $this->_extension ) { case 'GIF': $_out = imagegif( $this->_image_source, $dst_name ); break; case 'JPG': case 'JPEG': $_out = imagejpeg( $this->_image_source, $dst_name, 100 ); break; case 'PNG': $_out = imagepng( $this->_image_source, $dst_name ); break; case 'WBMP': $_out = imagewbmp( $this->_image_source, $dst_name ); } return $_copy && $_out; } } ?>
登录后复制
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
3 周前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保护它?
3 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu

Visual Studio Code,也称为 VS Code,是一个免费的源代码编辑器 - 或集成开发环境 (IDE) - 可用于所有主要操作系统。 VS Code 拥有针对多种编程语言的大量扩展,可以轻松编写
