PHP图片加水印文字及图片合成缩放
<?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图片加水印文字及图片合成缩放的更多相关文章
- 火车头dede采集接口,图片加水印,远程图片本地化,远程无后缀的无图片本地化
<?php /* [LocoySpider] (C)2005-2010 Lewell Inc. 火车采集器 DedeCMS 5.7 UTF8 文章发布接口 Update content: 图片加 ...
- 图片加水印文字,logo。生成缩略图
简单JSP代码 图片加水银文字 try { String path = request.getRealPath("images\\01.jpg"); out.print(path) ...
- php 图片加水印文字水印
/*给图片加文字水印的方法*/ $dst_path = 'http://f4.topitme.com/4/15/11/1166351597fe111154l.jpg';//保证路径正确 $dst = ...
- 使用Html5对图片加水印及多图合成
转载请注明原地址: ...
- android图片加水印,文字
两种方法: 1.直接在图片上写文字 String str = "PICC要写的文字"; ImageView image = (ImageView) this.findViewByI ...
- php对图片加水印--将文字作为水印加到图片
方法代码: /** * 图片加水印(适用于png/jpg/gif格式) * * @author flynetcn * * @param $srcImg 原图片 * @param $wat ...
- C#给图片加水印,可设置透明度
C#给图片加水印,可设置透明度,设置水印的位置可以看一下上一篇哈 /// <summary> /// Creating a Watermarked Photograph with GDI+ ...
- thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印
今天分享一下thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印.博主是新手,在这里卡住了很久(>_<) thinkphp 3.2.3整合ueditor 1.4 下载 ...
- php 分享两种给图片加水印的方法
本文章向码农们介绍 php 给图片加水印的两种方法,感兴趣的码农可以参考一下本文章的源代码. 方法一:PHP最简单的加水印方法 <?php // http://www.manongjc.com ...
随机推荐
- [转]Cryengine渲染引擎剖析
转篇Napoleon314 大牛的分析,排版好乱,见谅,耐心读,这是个好东西,注意看他自己的实现,是个技术狂人啊,Ogre焕发次时代的光芒啊~~~努力 ------------------------ ...
- 【转】Java面试题合集
2013年年底的时候,我看到了网上流传的一个叫做<Java面试题大全>的东西,认真的阅读了以后发现里面的很多题目是重复且没有价值的题目,还有不少的参考答案也是错误的,于是我花了半个月时间对 ...
- Java IO流-NIO简介
2017-11-05 22:09:04 NIO NIO:new IO就是新IO的意思,JDK4开始出现新IO,新IO和传统的IO有相同的目的,都是用于进行输入输出的,但是新IO使用了不同的方式来处理输 ...
- JS学习笔记(模态框JS传参)
博主最近基于django框架的平台第一版差不多完成了 今天整理下开发过程中遇到的前端知识 基于前端bootstrap框架模态框传参问题 上前端html代码: <div class="m ...
- 使用PMD进行代码审查(转)
原文地址:使用PMD进行代码审查 很久没写博客了,自从上次写的设计模式的博客被不知名的鹳狸猿下架了一次之后兴趣大减,那时候就没什么兴致写博客了,但是这段时间还没有停下来,最近也在研究一些其他的东西,目 ...
- 017PHP基础知识——流程控制语句(五)
<?php /** * break;退出循环: * 语法结构:break int;可以指定跳过几级循环: * while do_while for foreach switch */ /*$i= ...
- specialized English for automation-Lesson 2 Basic Circuits of Operational Amplifiers
排版有点乱.... ========================================================================= Operational Ampl ...
- HBase查询优化——持续更新
Scan:setBatch,setCaching,setCacheBlocks public void setBatch(int batch) public void setCaching(int c ...
- 中国的 Python 量化交易工具链有哪些
摘抄自知乎:https://www.zhihu.com/question/28557233 如题,提问的范围限于适合中国大陆金融市场使用的工具链,所以IbPy和Quotopian之类主要面向欧美市场的 ...
- CUDA 安装完成以后如何判断安装是否成功
最近在家里过寒假,可能这是还在学校里带着最大的福利了,无意之中翻出了多年前买的几本关于CUDA编程的书,于是随便在自己电脑上配置了一下环境,试试能不能把当年没有看完的书给看完了,于是有了今天这个判断C ...