According to the requirements, text must be written in nine tables, the title can be edited, and weather, background, and expressions can be selected. Finally, a picture is generated, which can be shared and the results can also be stored in the database. github address: 9Diary GitHub
- /**
- * Add log
- * bgid background image
- * title log title
- * Table title and content are separated into 1, 2, 3, 4, 6, 7, 8, 9 tables with '-|*dt*|-' Information
- * Table 5 related: mid_title, emoticons
- * Template id: tempid, to be developed
- * open: privacy
- */
-
- //dump($_POST);
- $bgid = intval(htmlspecialchars($_REQUEST['bgid']));
- $title = htmlspecialchars($_POST[' title']);
- $cnt = str_replace(PHP_EOL, '',$_POST['cnt']);
- //Title and content cannot be empty
- if (!isset($title) || !isset($cnt )){
- echo 'Title and content cannot be empty!';
- }
- $imgid = intval($_POST['imgId']);
- $weatherId = intval($_POST['weatherId']);
- $mid_title = htmlspecialchars($_POST['mid_title']);
- $cnt_titles = $_POST['cnt_titles'];
- $tempId = intval($_POST['tempId']);
- $open = intval($_POST['open ']);
-
- //Write image
- require_once('AppDiary.class.php');
- $image = new AppDiary();
- $path = dirname(__FILE__);
- $backimage = $path.'/ images/preview/'.$bgid.'.jpg';
- $weatherimg = $path.'/images/weather/'.$weatherId.'.gif';
- $emoticons_img = $path.'/images/emoticons/ '.$imgid.'.gif';
- $contents = explode('-|*dt*|-',$cnt);
- $contents_title = explode('-|*dt*|-', $cnt_titles);
- $str = array(
- array($weatherimg,528,1,61,62),//Weather
- array($contents_title[0],35,83,146,28,'cnt'),//Table 1 title
- array($contents[0],35,111,160,100,'cnt_titles'),//Table 1 content
- array($contents_title[1],222,83,146,28,'cnt'),//Table 2 title
- array($contents [1],222,111,160,100,'cnt_titles'),//Table 2 content
- array($contents_title[2],407,83,146,28,'cnt'),//Table 3 title
- array($contents[2], 407,111,160,100,'cnt_titles'),//Table 3 content
- array($contents_title[3],35,244,146,28,'cnt'),//Table 4 title
- array($contents[3],35,273,160,100,'cnt_titles') ,//Table 4 content
- array($mid_title,240,235,146,38,'mid_title'),//Table 5 title
- array($emoticons_img,261,283,80,80),//Table 5 content
- array($contents_title[ 4],407,244,146,28,'cnt'),//Table 6 title
- array($contents[4],407,273,160,100,'cnt_titles'),//Table 6 content
- array($contents_title[5],35,409,146,28 ,'cnt'),//Table 7 title
- array($contents[5],35,436,160,100,'cnt_titles'),//Table 7 content
- array($contents_title[6],221,409,146,28,'cnt'), //Table 8 title
- array($contents[6],221,436,160,100,'cnt_titles'),//Table 8 content
- array($contents_title[7],407,409,146,28,'cnt'),//Table 9 title
- array($contents[7],407,436,160,100,'cnt_titles'),//Table 9 content
- );
- //var_dump($str);
- $pic = $image->topaste($backimage,$str);
- $filename = $path.'/upfile/'.$pic;
- //Added a time() mainly to prevent the same file name
- $newname = $title.'_'.time().strrchr($ pic, '.');
- $newfile = $path.'/upfile/'.$newname;
- //This is mainly used for Chinese titles
- $newfile = iconv( 'UTF-8', 'GB18030', $newfile );
- if (file_exists($filename)){
- //Change file name successfully
- if (rename($filename,$newfile)){
- $pic = $newname;
- }
- echo json_encode(array('info' =>$pic,'status'=>1));
- }else{
- //Failed to generate file
- echo json_encode(array('info'=>'Error'.$pic,'status'=> ;0));
- }
-
Copy code
|