<?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. JS 拼装代码的HTML onClick方法传递字符串

    有时会在JS中拼装HTML代码,这时在HTML中出现的onClick()方法中: 1.出现传递Num型的数据,直接拼装进去即可: 2.可能会出现传递字符串的情况,处理方法比较特殊,如下: a:直接字符 ...

  2. 手动导出Excel方法

    private void dgJiBingZhenDuanBind() {   Response.Clear(); Response.Charset = "GB2312"; Res ...

  3. 第一天……

    Hello,大家好! 不对,这个开头有点不对.我不应该这么说,这个博客我是为我自己而开通的.目的很简单,好记兴不如烂笔头,把每天所学所感写下来. 我想作一个有条理的人,一个有计划的人,一个有效率的人. ...

  4. JavaSE复习_6 枚举类

    △单例类是指只有一个实例,而枚举类实际上就是有有限个实例的类,在类里已经把实例定义好了. △枚举类的三种创建形式: 1) enum Week { MON,TUE,WED;//枚举类有默认构造函数创建的 ...

  5. Binary Tree Paths

    Description: Given a binary tree, return all root-to-leaf paths. For example, given the following bi ...

  6. Object Pascal 方法与技巧

    4 方法与技巧 4.1 设置代码模板 代码模板是Delphi 的代码感知特性的一种,通过它可以快速.高效和正确地输入代码.代码模板将一些常用的语句块保存在模板中,然后程序员只要在代码编辑器中按下“Ct ...

  7. @synchronized (object)使用详解

    synchronized关键字代表这个方法加锁,相当于不管哪一个线 程A每次运行到这个法时,都要检查有没有其它正在用这个方法的线程B(或者C D等),有的话要等正在使用这个方法的线程B(或者C D)运 ...

  8. Android 空心和实心按钮

    Android 空心和实心按钮 做界面时 有时老要用到这种按钮 动画如下 实心的 <?xml version="1.0" encoding="utf-8" ...

  9. jpeg了解

    JPEG是一个压缩标准,又可分为标准 JPEG.渐进式JPEG及JPEG2000三种: ①标准JPEG:以24位颜色存储单个光栅图像,是与平台无关的格式,支持最高级 别的压缩,不过,这种压缩是有损耗的 ...

  10. 转:C 函数调用栈

    第一篇: 转自:http://kingj.iteye.com/blog/1555017 本文转自  http://blog.csdn.net/eno_rez/article/details/21586 ...