Urgent ~ Generate a picture of the code, changed for half a day not, master

Source: Internet
Author: User
This code converts the text directly into a picture, and then the default generated picture is a black background.
Now want to ask the master to help how to change, the background does not color black, but directly for the same directory of. jpg images as the background?

In other words, the resulting picture background is 1.jpg instead of the current color background? Ask how to change ... Study half a day do not understand.

  {$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_convert ($arr [0], +); $color [' Green '] = (int) base_convert ($arr [1], 2), $color [' blue '] = (int) base_convert ($arr [], +); return $color;} if ($len ==3) {$arr =str_split ($str, 1), $color [' red '] = (int) base_convert ($arr [0]. $arr [0], (+); $color [' green '] = (int ) Base_convert ($arr [1]. $arr [1], 2), $color [' blue '] = (int) base_convert ($arr []. $arr [2], (+); return $color;} return $color;} function Makeimger ($text = "Content acquisition failed ...", $types, $ids) {$setStyle = ' 52a300 '; #设置颜色, can also be developed as a page to select and pass this parameter, in | format $havebrlinker = ""; #超长使用分隔符 $fontFile = ' Simfang.ttf '; #字体文件名, put the font directory, can also be developed as a page to select and pass this parameter $userStyle = Explode (' | ', $setStyle); #分开颜色 $text = substr ($text, 0, 1000); #截取前一万个字符 $text = Iconv ("GB2312", "UTF-8", $text); $imgpath = "". $types. " /"; #图片存放地址if (!is_dir ($imgpath)) {mkdir ($imgpath);} $imgfile = $imgpath. $ids. '. gif '; if (file_exists ($imgfile)) {return $imgfile;} else{//here is the border width, can be passed the foreground parameters $paddingtop = 0; $paddingLeft = 640; $copyrightHeight = 260; $canvasHeight = 1136;//$canvasHeight = $paddingTop + $paddingBottom + $copyrightHeight; $fontSize =; $lineHeight = intval ($fontSize * 1.8); $TEXTARR = Array (), $TEMPARR = explode ("\ n", Trim ($text)), $j = 0;foreach ($tempArr as $v) {$arr = Str_div ($ V, $textArr [] = Array_shift ($arr), foreach ($arr as $v) {$TEXTARR [] = $haveBrLinker. $v; $j ++;if ($j >) {break;} } $j ++;if ($j >) {break;}} $textLen = count ($TEXTARR), $canvasHeight = $lineHeight * $textLen + $canvasHeight; $im = Imagecreatetruecolor ($ Canvaswidth, $canvasHeight); #定义画布 $colorArray = Str2rgb ($userStyle [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; $x 1 = $ Y1 = $x 4 = $y 2 = $padding; $x 2 = $x 3 = $canvasWidth-$padding-1; $y 3 = $y 4 = $canvasHeight-$padding -1;//can be developed as a page to select and pass This parameter, select whether to show borders and colors. Imageline ($im, $x 1, $y 1, $x 2, $y 2, $colorLine), Imageline ($im, $x 2, $y 2, $x 3, $y 3, $colorLine), Imageline ($im, $x 3, $y 3, $x 4 , $y 4, $colorLine); Imageline ($im, $x 4, $y 4, $x 1, $y 1, $colorLine);//font path, can also be developed as a page to select and pass this parameter $fontstyle = ' font/'. $fontFile, if (!is_file ($fontStyle)) {exit (' Please select font file first! ')} Write four digits $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 + + $text = '-------------------------------------------------- --------------------------------------------'; Imagettftext ($im, 0, $paddingLeft, $offset, $fontColor, $fontStyle , $text), $offset + =; $fontColor = imagecolorallocate ($im, 255, 0, 0);//can also be developed as a page to select and pass this parameter, such as the displayed text, and whether the display, display location, etc. $text = ' The picture comes from ... '; $text = Iconv ("GB2312", "UTF-8", $text); Imagettftext ($im, 0, $paddingLeft +, $offset, $fontColor, $fontStyle, $text); Imagegif ($im, $imgfile);    Imagedestroy ($im);//echo $imgfile; Exit ($imgfile);} return $imgfile;} $gg =$_post[' GG '];if ($gg = = "") {//Here can also increase the font color, background color, border color, font size, whether the border is displayed, border width, select the displayed font, and the last line of copyright ... echo "Please enter the content!";     echo ""; Exit ();}  else{$imghtml =makeimger ($gg, "WeiBo", Time (). Rand (1111,9999)); Echo

"; }? >


Reply to discussion (solution)

$im = Imagecreatetruecolor ($canvasWidth, $canvasHeight); #定义画布
Switch
$im = Imagecreatefromjpeg (' xxx.jpg '); #定义画布

$im = Imagecreatetruecolor ($canvasWidth, $canvasHeight); #定义画布
Switch
$im = Imagecreatefromjpeg (' xxx.jpg '); #定义画布



Thank you! Another problem is that the background image generated after the background picture quality is very poor, this can change its quality better?

No!
You just write on the picture, it should not affect the quality of the

No!
You just write on the picture, it should not affect the quality of the



Ask another question. $_post[' GG '] generated text, can you get back effect? or an outer glow effect?

No!
You just write on the picture, it should not affect the quality of the



Moderator. Ask again. Can the resulting font be centered? It is now controlled with Paddingleft. Want to get it centered automatically around it. May I? How to change?

Coordinate panning do you remember?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.