<?php
//图片添加文字水印
/*$bigImgPath = 'background.png';
$img = imagecreatefromstring(file_get_contents($bigImgPath)); $font = 'MSYH.TTF';//字体,字体文件需保存到相应文件夹下
$black = imagecolorallocate($img, 0, 0, 0);//字体颜色 RGB $fontSize = 12; //字体大小
$circleSize = 60; //旋转角度
$left = 50; //左边距
$top = 120; //顶边距 imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, 'zhix.net| 智昕网络'); list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
switch ($bgType) {
case 1: //gif
header('Content-Type:image/gif');
imagegif($img);
break;
case 2: //jpg
header('Content-Type:image/jpg');
imagejpeg($img);
break;
case 3: //png
header('Content-Type:image/png');
//imagepng($img,"images/circle.png"); //在 images 目录下就会生成一个 circle.png 文件,上面也可设置相应的保存目录及文件名。
imagepng($img);
break;
default:
break;
}
imagedestroy($img);
*/ //图片合成
/*$bigImgPath = 'background.png';
$qCodePath = 'code.png'; $bigImg = imagecreatefromstring(file_get_contents($bigImgPath));
$qCodeImg = imagecreatefromstring(file_get_contents($qCodePath));
imagesavealpha($bigImg,true);//假如是透明PNG图片,这里很重要 意思是不要丢了图像的透明<code class="php spaces"></code>
list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);
// imagecopymerge使用注解
imagecopymerge($bigImg, $qCodeImg, 50, 50, 0, 0, $qCodeWidth, $qCodeHight, 100);
list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath); switch ($bigType) {
case 1: //gif
header('Content-Type:image/gif');
imagegif($bigImg);
break;
case 2: //jpg
header('Content-Type:image/jpg');
imagejpeg($bigImg);
break;
case 3: //jpg
header('Content-Type:image/png');
//imagepng($bigImg,"images/circle.png"); //在 images 目录下就会生成一个 circle.png 文件,上面也可设置相应的保存目录及文件名。
imagepng($bigImg);
break;
default:
# code...
break;
}
imagedestroy($bigImg);
imagedestroy($qcodeImg);
*/ //如果感觉上面的二维码太大 那么可以先生成一张小的二维码图片,下面是处理的方法
//等比例生成图片
//$filepath图片路径,$percent缩放百分比
function imagepress($filepath,$percent='0.5'){
// 图片类型,这里的二维码是PNG的 所以使用PNG类型
header('Content-Type: image/png');
// 获得新的图片大小
list($width, $height) = getimagesize($filepath); //取图片信息
$new_width = $width * $percent;
$new_height = $height * $percent;
// 重新取样
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($filepath);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// 输出
return imagejpeg($image_p, 'code1.png', 100); //这里的名命可根据需要设置
} $bigImgPath = 'background.png';
$qCodePath = 'code.png';
imagepress($qCodePath);
$qCodePath = 'code1.png';
$bigImg = imagecreatefromstring(file_get_contents($bigImgPath));
$qCodeImg = imagecreatefromstring(file_get_contents($qCodePath)); list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);
// imagecopymerge使用注解
imagecopymerge($bigImg, $qCodeImg, 90, 90, 0, 0, $qCodeWidth, $qCodeHight, 100);
list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath); switch ($bigType) {
case 1: //gif
header('Content-Type:image/gif');
imagegif($bigImg);
break;
case 2: //jpg
header('Content-Type:image/jpg');
imagejpeg($bigImg);
break;
case 3: //jpg
header('Content-Type:image/png');
//imagepng($bigImg,"images/circle.png"); //在 images 目录下就会生成一个 circle.png 文件,上面也可设置相应的保存目录及文件名。
imagepng($bigImg);
break;
default:
# code...
break;
}
imagedestroy($bigImg);
imagedestroy($qcodeImg);

PHP图片加水印文字及图片合成缩放的更多相关文章

  1. 火车头dede采集接口,图片加水印,远程图片本地化,远程无后缀的无图片本地化

    <?php /* [LocoySpider] (C)2005-2010 Lewell Inc. 火车采集器 DedeCMS 5.7 UTF8 文章发布接口 Update content: 图片加 ...

  2. 图片加水印文字,logo。生成缩略图

    简单JSP代码 图片加水银文字 try { String path = request.getRealPath("images\\01.jpg"); out.print(path) ...

  3. php 图片加水印文字水印

    /*给图片加文字水印的方法*/ $dst_path = 'http://f4.topitme.com/4/15/11/1166351597fe111154l.jpg';//保证路径正确 $dst = ...

  4. 使用Html5对图片加水印及多图合成

                                                                             转载请注明原地址:                   ...

  5. android图片加水印,文字

    两种方法: 1.直接在图片上写文字 String str = "PICC要写的文字"; ImageView image = (ImageView) this.findViewByI ...

  6. php对图片加水印--将文字作为水印加到图片

    方法代码: /**  * 图片加水印(适用于png/jpg/gif格式)  *  * @author flynetcn  *  * @param $srcImg  原图片  * @param $wat ...

  7. C#给图片加水印,可设置透明度

    C#给图片加水印,可设置透明度,设置水印的位置可以看一下上一篇哈 /// <summary> /// Creating a Watermarked Photograph with GDI+ ...

  8. thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印

    今天分享一下thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印.博主是新手,在这里卡住了很久(>_<) thinkphp 3.2.3整合ueditor 1.4 下载 ...

  9. php 分享两种给图片加水印的方法

    本文章向码农们介绍 php 给图片加水印的两种方法,感兴趣的码农可以参考一下本文章的源代码. 方法一:PHP最简单的加水印方法 <?php // http://www.manongjc.com ...

随机推荐

  1. sqlserver存储过程分页

    create  procedure [dbo].[SqlPager]@sqlstr nvarchar(4000), --查询字符串@currentpage int, --第N页@pagesize in ...

  2. SCWS中文分词PHP扩展详细安装说明

    因最近写的一段代码,需要用到中文分词,在网上找了一下,发现了scws这个不错的插件,故根据文档安装使用,下面记录下安装的全过程 系统:centos 安装scws wget http://www.xun ...

  3. java实现的18位身份证格式验证算法

    公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成.排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码.1.地址码表示编码对象常住户口所在县(市. ...

  4. 【hive】分组求排名

    分组求排名 相信好多使用Mysql的用户一定对分组求排名的需求感到发怵. 但是在hive或者oracle来说就能简单实现. 采用窗口函数:rank() over() / row_number() ov ...

  5. Jquery表单清空

    虽然reset方法可以做到一部分,但是如果你有个元素是这样的 <input name="percent" value="50"/> 那么点击rese ...

  6. HP-UX 下用户被锁

    /usr/lbin/getprpw -m lockout root 如果返回lockout=0000000 该帐号是非锁定的,如果是其它的如:lockout=0001000则表示该帐号被锁定 如果是测 ...

  7. BigDecimal 、BigInteger

    package com.BigDecimal; public class BigDecimalDemo { /* * 下面的运算的结果出乎我们的意料,有些准确,有些不准确 * 这是为什么呢? * 我们 ...

  8. 第11课 enum,sizeof,typedef分析

    枚举类型的使用方法: enum的地位和struct是相等的,enum主要用来根据需要定义一些离散的值. 枚举类型的特殊意义: 工程中常用无名枚举来定义常量. 程序示例: #include <st ...

  9. 在win10下安装双系统ubuntu16.04.3教程

    闲暇了两天,终于想起来要装一个Liunx系统了.于是捣鼓了一番,实现了在Win10下安装Ubuntu16.04.3版本. 一.准备工作 下载Ubuntu 16.04.3镜像 准备一个2G以上的U盘 下 ...

  10. BZOJ1568: [JSOI2008]Blue Mary开公司【李超树】

    Description Input 第一行 :一个整数N ,表示方案和询问的总数. 接下来N行,每行开头一个单词"Query"或"Project". 若单词为Q ...