<?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. python批量修改ssh密码

    由于工作需要本文主结合了excel表格,对表格中的ssh密码进行批量修改 以下是详细代码(python3): #!/usr/bin/env python#-*-coding:utf-8-*- impo ...

  2. sqlserver存储过程分页

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

  3. UVA-127 "Accordian" Patience (模拟)

    题目大意:一种纸牌游戏,将52张扑克牌排成一列,每次操作可将一张扑克牌移到它的前一张或前面第三张上当牌的点数或花色匹配时.每次都移动最靠左的扑克牌,并且能移动三格就移动三格.求最终扑克牌状态. 题目分 ...

  4. Xcode 7.0 Could not find developer disk image

    在使用Xcode 7的真机运行的时候, 出现Could not find developer disk image. 解决方法:先关闭Xcode.再从Xcode 6.4中,拷贝8.4 (12H141) ...

  5. 关于父类私有属性在子类构造函数中super调用的解释

    package test; public class Car { private int carMoney; //汽车租金 private String carName; //汽车名字 private ...

  6. New Concept English Two 33 91

    $课文89 口误 981. People will do anything to see a free show -- even if it is a bad one. 人们总要想尽办法看不花钱的演出 ...

  7. Haproxy的负载均衡和高可用配置

    一.Haproxy的理解    Haproxy是一个使用c语言编写的自由开发源代码软件,它提供高可用性.负载均衡.以及基于http和tcp的应用程序代理.    Haproxy特别使用于那些负载特别大 ...

  8. HDU 3667

    http://acm.hdu.edu.cn/showproblem.php?pid=3667 最小费用最大流 本题流量和费用不是线性关系,fee=a*flow*flow,所以常规套模板spfa无法得到 ...

  9. 2018-2019-1 20165212 《信息安全系统设计基础》第八周学习总结(pwd)

    2018-2019-1 20165212 <信息安全系统设计基础>第八周学习总结 一.知识点总结 1.三种并发方式 构造并发程序的方法有三种: 进程 线程 I/O多路复用 进程:用内核来调 ...

  10. 2018-2019-2 《网络对抗技术》Exp4 恶意代码分析 20165222李勖

    1.系统运行监控 (1)使用如计划任务,每隔一分钟记录自己的电脑有哪些程序在联网,连接的外部IP是哪里.运行一段时间并分析该文件,综述一下分析结果.目标就是找出所有连网的程序,连了哪里,大约干了什么( ...