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);
随机推荐
- javascript练习----复选框全选,全不选,反选
第一种方式: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- ccc
课本第291页第4题 #include<stdio.h> void main() { int n, m, i, k; int p_begin; ]; scanf("%d" ...
- Spring 读书笔记-----使用Spring容器(一)
pring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.他们都可代表Spring容器,Spri ...
- ubuntu安装jdk-6u45-linux-x64.bin___ZC_20160423
for : Android4.4源码编译 环境 : ubuntu12.04_desktop_amd64 1. 1.1.jdk-6u45-linux-x64.bin 放置于 /home 1.2.命令&q ...
- 关于boost的thread的mutex与lock的问题
妈的,看了好久的相关的知识,感觉终于自己有点明白了,我一定要记下来啊,相关的知识呀.... 1, 也可以看一下boost的线程指南:http://wenku.baidu.com/link?url=E_ ...
- HTML的超链接
一.超链接概念: 超链接也叫 URL 中文翻译为资源定址器.这个定址器的功能主要告诉浏览器根据 URL的地址找到所需的资源.作用于连接资源 二.超链接的常用属性: 1.href=指定目的地,当有了hr ...
- The Zen Programmer (zhuan)
http://blog.csdn.NET/marksinoberg/article/details/52460725 ***************************************** ...
- OpenGL的gluPerspective透视投影变换函数详解[转]
函数原型void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) 首先得设置gluPersp ...
- Asp.NET设置Session过期时间的四种方式
在Asp.net中,可以有四处设置Session的过期时间: 一.全局网站(即服务器)级 IIS-网站-属性-Asp.net-编辑配置-状态管理-会话超时(分钟)-设置为120,即为2小时,即120分 ...
- 显示回收站.reg
显示回收站.reg Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\Current ...