zoukankan      html  css  js  c++  java
  • 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();
    	}
    }
    

      

  • 相关阅读:
    java mail
    hibernate 批量处理数据
    动态规划0—1背包问题
    FreeCMS开发过程问题总结(持续更新中)
    RapeLay(电车之狼R)的结局介绍 (隐藏结局攻略)
    笔记本键盘输入错乱,字母都变成数字了
    眼下最好的JSP分页技术
    在一个字符串中找到第一个仅仅出现一次的字符
    央行力保首套房贷背后暗藏何种玄机?
    HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)
  • 原文地址:https://www.cnblogs.com/mayi168/p/3580901.html
Copyright © 2011-2022 走看看