php圖片中寫入字符串然後生成圖片下載到本地
<?php
/**
* 生成卡片得類
* Enter description here ...
* @author perry
* @time 2014-03-03 10:02:20
*/ class CreateImg{
public $destination; //默認圖片
public $fontname; //默認的字體
public $font_size; //字體大小
public $company ; //字符串
public $booth; //字符串
public $im; //圖片對象
public $filedir; //圖片零時目錄
function CreateImg($destination,$company,$booth,$fontname='font/ADOBEGOTHICSTD-BOLD.OTF',$font_size='14'){
$this->destination = $destination;
$this->company=$company;
$this->booth = $booth;
$this->fontname = $fontname;
$this->font_size = $font_size;
} /**
* 生成一個圖片
* Enter description here ...
* @param unknown_type $dir 圖片零時保存目錄
*/
function createNew($dir='attachment'){
//Header('Content-type: image/jpg');
$this->im = imagecreatefromjpeg($this->destination);
$black = imagecolorallocate($this->im, 0, 160, 236); //字體顏色
//文字放在圖片位置
imagettftext($this->im, $this->font_size,0, 395, 410, $black, $this->fontname, $this->company);
imagettftext($this->im, $this->font_size,0, 365, 437, $black, $this->fontname, $this->booth);
//保存目录是否存在,否則創建一個
if(!is_dir($dir)){
mkdir($dir);
}
$this->filename=date('YmdHis',time()).rand(10000,999999).".jpg"; //新文件名称
$this->filedir=$dir."/".$this->filename;
imagejpeg($this->im);
imagedestroy($this->im); } /**
* 下載圖片到本地
* Enter description here ...
* @param unknown_type $ispre 是否保存在空間:1保存 0不保存
*/ function downNew($ispre=0){
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($this->filedir));
Header("Content-Disposition: attachment; filename=e-invitation.jpg");
$fh = fopen($this->filedir, 'rb');
fpassthru($fh);
fclose($fh);
empty($ispre)? unlink($this->filedir):null;
exit();
}
}
php圖片中寫入字符串然後生成圖片下載到本地的更多相关文章
- Scrapy——將爬取圖片下載到本地
1. Spider程序: 1 import scrapy, json 2 from UnsplashImageSpider.items import ImageItem 3 4 class Unspl ...
- C# 的 Dictionary 寫入前應注意事項
一個已上線.用戶龐大的系統,幾個月來第一次出現這個系統錯誤訊息 : 「已經加入含有相同索引鍵的項目」「已添加了具有相同键的项」An item with the same key has already ...
- [Python筆記] 將 Pandas 的 Dataframe 寫入 Sqlite3
使用 pandas.io 寫入 Sqlite import sqlite3 as lite from pandas.io import sql import pandas as pd 依照 if_ex ...
- 字符串hash补充(模数情况下)
字符串模板,在模数意义下的,比较好用 #include<stdio.h> typedef long long LL; /*[字符串哈希算法] 字符串哈希算法的提出,涉及到如何快速地求两个字 ...
- sql 不同server間寫入數據
select * from sys.servers sp_dropserver @server =N'' sp_dropserver '' ,'droplogins' EXEC master.dbo. ...
- [Java]借助PrintWriter类和StringWriter类,取出异常堆栈信息放入字符串中
在程序开发中,有时我们不仅需要将异常堆栈信息打印在控制台里或是log里,可能还需要将它存在String中,再送到合适的地方,如错误页面,数据库等. 要取异常堆栈信息,具体的函数就是: /** * Ge ...
- Jquery解析Json字符串,并且动态生成数据表格Table
//ajax获得后台传来的json字符串 $.post("UserInfo.ashx", function (data) { //假设data="{T1:[{User_I ...
- python 根据字符串动态的生成变量名并且赋值
Python 动态的创建变量 一.子符串的形式 这是在今天的一个项目中,发现需要动态的创建很多变量.每个变量对应的值的来源都相同.在网上看了些资料,研究出了这个动态创建变量的牛逼方法. 所用的方法就是 ...
- php 在不知道字符串有多长的情况下,如何去除前三个字符?
$string='字符串';$subject=substr_replace(string,'',0,3);
随机推荐
- git学习笔记06-创建分支合并分支-比svn快多了,因为只有指针在改变
一开始git只有一条时间线,这个分支叫主分支,即master分支. HEAD严格来说不是指向提交,而是指向master,master才是指向提交的,所以,HEAD指向的就是当前分支. 每次提交,mas ...
- iOS JS交互
1. 添加本地js文件, 并配置head中的属性 function increaseMaxZoomFactor() { var element = document.createElem ...
- ASP.NET MVC HtmlHelper用法集锦
ASP.NET MVC HtmlHelper用法集锦 在写一个编辑数据的页面时,我们通常会写如下代码 1:<inputtype="text"value='<%=View ...
- 关于图片加载非常爽的一个三方控件 fresco,一个三fresco
Hi EveryBody 今天来玩一个非常爽的控件 fresco 到底有多爽呢 接着看就知道了 首先 来看看fresco 是个神马东西 https://github.com/facebook/fre ...
- Hbase之插入数据
/** * Created by similarface on 16/8/17. */ import org.apache.hadoop.conf.Configuration; import org. ...
- listview定位到上次显示的位置
整体思路:滑动lictview时,记录listview的位置,定位时定位到该位置. 1.添加全局变量 private int scrolledX = 0; private int scrolledY ...
- Dorado7检验器失效原因分析
应用场景: AutoForm1使用包含A.B两个字段的DataType1. A字段不允许为空,并且B字段取值true时A字段需要重新输入,B取其它值时A值不需重新录入. 实现方法:A字段添加了非空检验 ...
- 猫都能学会的Unity3D Shader入门指南
https://onevcat.com/2013/07/shader-tutorial-1/ https://onevcat.com/2013/08/shader-tutorial-2/
- OneProxy使用手册--致力于打造透明的数据层
介绍 平民软件官网上线(http://www.onexsoft.com) OneProxy是由原支付宝首席架构师楼方鑫开发,目前由楼方鑫创立的杭州平民软件公司(@平民架构)提供技术支持.目前 ...
- rsa加密--选择padding模式需要注意的问题。。。
最近在做一个项目中需要,在android对一个密码字段首先进行 一次md5加密后再进行一次rsa加密,然后把加密的结果通过 json协议传输给nginx服务器进行解密.在android中,可以直接 使 ...