Urgent ~ The code for generating the image cannot be changed for a long time. if you have mastered this code, you can directly convert the text into an image, and then the generated image is of a black background by default ..
Now I want to figure out why the background is black and the .jpg image in the same directory is used as the background?
In other words, the generated image background is 1.jpg, rather than the current color background? How to change... I am not familiar with the study for a long time ..
128) {$ count + = 1; $ flag + = 3;} else {$ count + = 0.5; $ flag + = 1;} if ($ count> = $ width) {$ strArr [] = substr ($ str, 0, $ flag); $ str = substr ($ str, $ flag); $ len-= $ flag; $ count = 0; $ flag = 0; }}$ strArr [] = $ str; return $ strArr;} function str2rgb ($ str) {$ color = array ('Red' => 0, 'green' => 0, 'blue' => 0); $ str = str_replace ('#','', $ str); $ len = strlen ($ str); if ($ len = 6) {$ arr = str_split ($ str, 2 ); $ color ['red'] = (int) base_c Onvert ($ arr [0], 16, 10); $ color ['green'] = (int) base_convert ($ arr [1], 16, 10 ); $ color ['blue'] = (int) base_convert ($ arr [2], 16, 10); return $ color;} if ($ len = 3) {$ arr = str_split ($ str, 1); $ color ['red'] = (int) base_convert ($ arr [0]. $ arr [0], 16, 10); $ color ['green'] = (int) base_convert ($ arr [1]. $ arr [1], 16, 10); $ color ['blue'] = (int) base_convert ($ arr [2]. $ arr [2], 16, 10); return $ color;} function ma Keimger ($ text = "retrieving content failed... ", $ types, $ ids) {$ setStyle = '52a300 '; # set the color. you can also select and pass this parameter on the page, use | format $ haveBrLinker = ""; # use the extra long separator $ fontFile = 'simfang. ttf'; # font file name, which is stored in the font directory. you can also select and pass this parameter $ userStyle = explode ('|', $ setStyle) on the page ); # separated color $ text = substr ($ text, 0, 1000); # cut the first 10 thousand characters $ text = iconv ("GB2312", "UTF-8", $ text ); $ imgpath = "". $ types. "/"; # Image storage address if (! Is_dir ($ imgpath) {mkdir ($ imgpath) ;}$ imgfile = $ imgpath. $ ids. '.gif '; if (file_exists ($ imgfile) {return $ imgfile;} else {// Here is the border width. you can pass the parameter $ paddingTop = 500; $ paddingLeft = 35; $ paddingBottom = 260; $ copyrightHeight = 0; $ canvasWidth = 640; $ canvasHeight = 1136; // $ canvasHeight = $ paddingTop + $ paddingBottom + $ copyrightHeight; $ fontSize = 38; $ lineHeight = intval ($ fontSize * 1.8); $ textArr = array (); $ tempA Rr = explode ("\ n", trim ($ text); $ j = 0; foreach ($ tempArr as $ v) {$ arr = str_p ($ v, 25); $ textArr [] = array_shift ($ arr); foreach ($ arr as $ v) {$ textArr [] = $ haveBrLinker. $ v; $ j ++; if ($ j> 100) {break ;}}$ j ++; if ($ j> 100) {break ;}} $ textLen = count ($ textArr); $ canvasHeight = $ lineHeight * $ textLen + $ canvasHeight; $ im = imagecreatetruecolor ($ canvasWidth, $ canvasHeight ); # define the canvas $ colorArray = str2rgb ($ userStyl E [1]); imagefill ($ im, 0, 0, imagecolorallocate ($ im, $ colorArray ['red'], $ colorArray ['green'], $ colorArray ['blue']); $ colorArray = str2rgb ('000000'); $ colorLine = imagecolorallocate ($ im, $ colorArray ['red'], $ colorArray ['green'], $ colorArray ['blue']); $ padding = 0; $ x1 = $ y1 = $ x4 = $ y2 = $ padding; $ x2 = $ x3 = $ canvasWidth-$ padding-1; $ y3 = $ y4 = $ canvasHeight-$ padding-1; // you can select and pass this parameter on the page and select whether to display the parameter. Border and color. Imageline ($ im, $ x1, $ y1, $ x2, $ y2, $ colorLine); imageline ($ im, $ x2, $ y2, $ x3, $ y3, $ colorLine); imageline ($ im, $ x3, $ y3, $ x4, $ y4, $ colorLine); imageline ($ im, $ x4, $ y4, $ x1, $ y1, $ colorLine); // font path, or you can select and pass this parameter for the page. $ fontStyle = 'font /'. $ fontFile; if (! Is_file ($ fontStyle) {exit ('select the font file first! ');} // Write four random numbers $ colorArray = str2rgb ($ userStyle [0]); $ fontColor = imagecolorallocate ($ im, $ colorArray ['red'], $ colorArray ['green'], $ colorArray ['blue']); foreach ($ textArr as $ k => $ text) {$ offset = $ paddingTop + $ lineHeight * ($ k + 1)-intval ($ lineHeight-$ fontSize)/2); imagettftext ($ im, $ fontSize, 0, $ paddingLeft, $ offset, $ fontColor, $ fontStyle, $ text) ;}$ fontColor = imagecolorallocate ($ im, 0, 0, 0); $ Offset + = 18; $ text = 'hangzhou'; imagettftext ($ im, 10, 0, $ paddingLeft, $ offset, $ fontColor, $ fontStyle, $ text ); $ offset + = 28; $ fontColor = imagecolorallocate ($ im, 255, 0, 0); // You can also select and pass this parameter as a page, such as the displayed text, and whether to display and display the location. $ Text = 'the image comes from... '; $ text = iconv ("GB2312", "UTF-8", $ text); imagettftext ($ im, 14, 0, $ paddingLeft + 160, $ offset, $ fontColor, $ fontStyle, $ text); imagegif ($ im, $ imgfile); imagedestroy ($ im); // echo $ imgfile; // exit ($ imgfile );} return $ imgfile;} $ gg =$ _ POST ['GG ']; if ($ gg = "") {// You can also add the font color and background color, border color, font size, border display, border width, select the font to display, and the copyright of the last line... echo "Enter the content! "; Echo" "; exit () ;}else {$ imghtml = makeimger ($ gg," WeiBo ", time (). rand (1111,9999); echo"";}?>
Reply to discussion (solution)
$ Im = imagecreatetruecolor ($ canvasWidth, $ canvasHeight); # define the canvas
Change
$ Im = imagecreatefrom#('xxx.jpg '); # define the canvas
$ Im = imagecreatetruecolor ($ canvasWidth, $ canvasHeight); # define the canvas
Change
$ Im = imagecreatefrom#('xxx.jpg '); # define the canvas
Thank you ~! Another problem is that the image quality of the background image after the background image is generated is poor. can this change improve the image quality?
No!
You only write on images and should not affect the image quality.
No!
You only write on images and should not affect the image quality.
Ask another question. Can the text generated by $ _ POST ['GG '] have a background effect? Or exclusive effect?
No!
You only write on images and should not affect the image quality.
Moderator. Ask again .. Can the generated font center it? Currently, paddingleft is used .. To automatically center the left and right sides .. Yes? How to change it?
Do you still remember coordinate translation?