<?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圖片中寫入字符串然後生成圖片下載到本地的更多相关文章

  1. Scrapy——將爬取圖片下載到本地

    1. Spider程序: 1 import scrapy, json 2 from UnsplashImageSpider.items import ImageItem 3 4 class Unspl ...

  2. C# 的 Dictionary 寫入前應注意事項

    一個已上線.用戶龐大的系統,幾個月來第一次出現這個系統錯誤訊息 : 「已經加入含有相同索引鍵的項目」「已添加了具有相同键的项」An item with the same key has already ...

  3. [Python筆記] 將 Pandas 的 Dataframe 寫入 Sqlite3

    使用 pandas.io 寫入 Sqlite import sqlite3 as lite from pandas.io import sql import pandas as pd 依照 if_ex ...

  4. 字符串hash补充(模数情况下)

    字符串模板,在模数意义下的,比较好用 #include<stdio.h> typedef long long LL; /*[字符串哈希算法] 字符串哈希算法的提出,涉及到如何快速地求两个字 ...

  5. sql 不同server間寫入數據

    select * from sys.servers sp_dropserver @server =N'' sp_dropserver '' ,'droplogins' EXEC master.dbo. ...

  6. [Java]借助PrintWriter类和StringWriter类,取出异常堆栈信息放入字符串中

    在程序开发中,有时我们不仅需要将异常堆栈信息打印在控制台里或是log里,可能还需要将它存在String中,再送到合适的地方,如错误页面,数据库等. 要取异常堆栈信息,具体的函数就是: /** * Ge ...

  7. Jquery解析Json字符串,并且动态生成数据表格Table

    //ajax获得后台传来的json字符串 $.post("UserInfo.ashx", function (data) { //假设data="{T1:[{User_I ...

  8. python 根据字符串动态的生成变量名并且赋值

    Python 动态的创建变量 一.子符串的形式 这是在今天的一个项目中,发现需要动态的创建很多变量.每个变量对应的值的来源都相同.在网上看了些资料,研究出了这个动态创建变量的牛逼方法. 所用的方法就是 ...

  9. php 在不知道字符串有多长的情况下,如何去除前三个字符?

    $string='字符串';$subject=substr_replace(string,'',0,3);

随机推荐

  1. iOS - OC PList 数据存储

    前言 直接将数据写在代码里面,不是一种合理的做法.如果数据经常改,就要经常翻开对应的代码进行修改,造成代码扩展性低.因此,可以考虑将经常变的数据放在文件中进行存储,程序启动后从文件中读取最新的数据.如 ...

  2. 管道寄售库存MRKO结算后,冲销问题

    管道寄售库存MRKO结算后,冲销问题 1.通常使用MIRO对采购订单进行发票校验后,若发现校验错误,直接使用MR8M取消发票校验,同时手工F-03对借发票校验借方GRIR和取消发票校验的贷方GRIR进 ...

  3. THE SENSE OF BEAUTY

    #include<stdio.h> int main() { ][] = { " ,.:;j", " ,: i. .,:;ff", " : ...

  4. [转载] 高效 MacBook 工作环境配置

    原文: http://mp.weixin.qq.com/s?__biz=MjM5NzMyMjAwMA==&mid=208231200&idx=1&sn=8a76ddc56c1f ...

  5. UIButton的状态

    normal(普通状态) 默认情况(Default) 对应的枚举常量:UIControlStateNormal highlighted(高亮状态)按钮被按下去的时候(手指还未松开)对应的枚举常量:UI ...

  6. 基础2 JVM

    1. 内存模型以及分区,需要详细到每个区放什么. //运行时数据区域 方法区 Method Area 各个线程共享的内存区域 存储已被虚拟机加载的类信息 常量 静态变量 即时编译器编译后的代码 虚拟机 ...

  7. linux 文件类型 文件权限

    linux中常见的文件类型有: “—”表示普通文件 :-rw-r--r-- 1 root root 41727 07-13 02:56 install.log   “d”表示目录 :drwxr-xr- ...

  8. Android开发面试经——4.常见Android进阶笔试题(更新中...)

      Android开发(29)  版权声明:本文为寻梦-finddreams原创文章,请关注:http://blog.csdn.net/finddreams 关注finddreams博客:http:/ ...

  9. Hibernate Projections(投影、统计、不重复结果)

    Hibernate除了处理查询结果集中的对象之外,还可以将结果集中的结果当做行和列集来使用,这与通过JDBC执行select查询获得的数据的使用方式相似.因此,Hibernate也支持属性.统计函数和 ...

  10. Android_开发工具的下载和开发环境的搭建

    一.Android开发工具的下载  Android开发者官网: http://developer.android.com/           Android开发工具:http://www.andro ...