php圖片中寫入字符串然後生成圖片下載到本地

时间:2022-12-19 23:42:22
<?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&num; 的 Dictionary 寫入前應注意事項

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

  3. &lbrack;Python筆記&rsqb; 將 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. &lbrack;Java&rsqb;借助PrintWriter类和StringWriter类,取出异常堆栈信息放入字符串中

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

  7. Jquery解析Json字符串&comma;并且动态生成数据表格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. hdu Prime Ring Problem

    简单的dfs,貌似这道题用暴力枚举就可以了,毕竟数据开的是比较小的. #include"iostream" #include"algorithm" #inclu ...

  2. Remove a Driver Package from the Driver Store

    http://technet.microsoft.com/en-us/library/cc730875.aspx Determine the name of the driver package in ...

  3. Google street、Google satellite 、百度地图Iframe切换桥接JS

    1.地图切换方法 注意:父页面访问Iframe页面JS方法需根据Iframe的名字来调用如:named "mapIfame" 即 mapIfame.window.iframeFun ...

  4. 游戏 TRAP&lpar;SNRS)AlphaBeta版本

    大家好,我是PuzzledBoy,大一(大二快).我是一个独立的游戏开发商,我的梦想是成为一名伟大的艺术家的第九 今天来公布我的第一个独立游戏TRAP(SNRS)的Alpha測试版啦啦啦~~~! 游戏 ...

  5. Octave Tutorial(《Machine Learning》)之第一课《数据表示和存储》

    Octave Tutorial 第一课 Computation&Operation 数据表示和存储 1.简单的四则运算,布尔运算,赋值运算(a && b,a || b,xor( ...

  6. HTTP模拟工具【C&num;&sol;Winform源码】、Json绑定TreeView控件、使用了MetroModernUI、RestSharp、Dapper&period;Net、Newtonsoft&period;Json、SmartThreadPool这几个主要开源框架

    HTTP模拟工具 开发语言:C#/Winform开发工具:Visual Studio 2017数据库:   SQLite使用框架:界面-MetroModernUI              Http请 ...

  7. Junit4X系列--hamcrest的使用

    OK,在前面的一系列博客里面,我整理过了Assert类下面常用的断言方法,比如assertEquals等等,但是org.junit.Assert类下还有一个方法也用来断言,而且更加强大.这就是我们这里 ...

  8. NavUtils【底部虚拟导航栏工具类】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 获取底部虚拟导航栏的高度值 效果图 代码分析 checkDeviceHasNavigationBar(Context context ...

  9. 4&period;27Linux&lpar;5&rpar;

    2019-4-27 15:39:03 学了Linux好几天,发现Linux用着还是很爽 你一定要知道你要干啥!!!! 列一下参考博客: mysql博客地址:https://www.cnblogs.co ...

  10. 搭建Fabric网络(四)运行网络

    启动网络 docker-compose -f docker-compose-cli.yaml up -d如果container cli关闭了,可以手动启动 docker start cli 设置环境变 ...