- Error_reporting (7 );
- Define ('root', getcwd ());
- Define ('basedir', parse_url ($ _ SERVER ['request _ URI '], PHP_URL_PATH ));
- If ($ _ POST ['text']) {
- $ Ret = array ();
- $ Text = $ _ POST ['text'];
- Try {
- $ Ret ['imgurl'] = text2img ($ text, (array) $ _ REQUEST ['config']);
- }
- Catch (Exception $ e ){
- $ Ret ['imgurl'] = print_r ($ e, true );
- }
- Echo str_replace ('\/', '/', json_encode ($ ret ));
- Exit (0 );
- }
- Function text2img ($ text, $ options = array ())
- {
- $ Text. = "\ n ------------------------------- \ n ";
- $ Text. = "http://iscup.com ";
- $ Rows = substr_count ($ text, "\ n") + 1;
- $ Font_path = $ options ['fontfile']? $ Options ['fontfile']: ROOT. '/SIMSUN. TTC ';
- If (! File_exists ($ font_path ))
- Throw new Exception ("the font file cannot be found: $ font_path ");
- $ Font_size = $ options ['fontsize']? $ Options ['fontsize']: 12;
- $ Padding = $ options ['padding']? $ Options ['padding']: 30;
- $ Row_plus_height = $ options ['row _ plus_height ']? $ Options ['row _ plus_height ']: 4;
- $ Border = 1;
- $ Im_width = 430;
- $ Im_height = ($ row_plus_height + ($ font_size * 4)/3) * $ rows + ($ padding + $ border) * 2;
- $ Im = @ imagecreatetruecolor ($ im_width, $ im_height );
- If (! $ Im)
- Throw new Exception ("image initialization failed, please check GD configuration ");
- Imagefilledrectangle ($ im, $ border, $ border, ($ im_width-2 * $ border), ($ im_height-2 * $ border), imagecolorallocate ($ im, 255,255,255 ));
- Imagettftext ($ im, $ font_size, 0, ($ border + $ padding), ($ font_size * 4)/3 + $ border + $ padding), imagecolorallocate ($ im, 0, 0, 0), $ font_path, $ text );
- $ Base_path = '/Files ';
- $ Base_filename = date ("Y-m-d, H-I-s"). '.png ';
- $ Short_filename = $ base_path. '/'. $ base_filename;
- $ Short_url = rtrim (BASEDIR, '/'). $ short_filename;
- @ Mkdir (ROOT. $ base_path, 0777, true );
- $ Filename = ROOT. $ short_filename;
- If (! Imagepng ($ im, $ filename )){
- Throw new Exception ("An error occurred while creating the image. ");
- }
- @ Imagedestroy ($ im );
- Return $ short_url;
- }
-
- ?>
-
-
- Long Weibo tool
|