根据标题关键字生成图片实现优质图片PHP代码
作者:互联网
$bgimg = "./image/" . $numrand . ".jpg"; $bg_info = getimagesize($bgimg); $bg_type = image_type_to_extension($bg_info[2], false); $func = "imagecreatefrom" . $bg_type; $bg_image = $func($bgimg); $numrand2 = rand(1, 6); $tu1 = "./image/" . $numrand2 . ".png"; $tu1_info = getimagesize($tu1); $tu1_type = image_type_to_extension($tu1_info[2], false); $tu1_func = "imagecreatefrom" . $tu1_type; $tu1_image = $tu1_func($tu1); imagecopy($bg_image, $tu1_image, 100, 50, 0, 0, 600, 400); $tu2 = "./image/" . $numrand2 . ".png"; $tu2_mark = getimagesize($tu2); $tu2_type = image_type_to_extension($tu2_mark[2], false); $tu2_func = "imagecreatefrom" . $tu2_type; $tu2_image = $tu2_func($tu2); imagecopy($bg_image, $tu2_image, 583, 1193, 0, 0, 258, 261); $gettxtone = mb_substr($get, 0, 12, "utf-8"); $gettxttwo = mb_substr($get, 12, 13, "utf-8"); $gettxtthree = mb_substr($get, 25, 13, "utf-8"); $text1 = preg_split("/(?<!^)(?!$)/u", $gettxtone); $text2 = preg_split("/(?<!^)(?!$)/u", $gettxttwo); $text3 = preg_split("/(?<!^)(?!$)/u", $gettxtthree); if (($waterturn == 1)) { $waterfont = $watertitle; $waterfont = preg_split("/(?<!^)(?!$)/u", $waterfont); } $color = imagecolorallocate($bg_image, 255, 255, 255); $font = "./font/" . $fontrand . ".ttf"; $font_lposition = [110, 60]; $font_tposition = [220, 120]; $height = $height + $h * $size; $titlelenth = strlen($title); if ($titlelenth > 20) { $x = 130; $y = 220; } else { $x = 200; $y = ($height - imagefontheight($size)) / 2; } $size = 40; $y2 = $y + 60; $x2 = 110; $y3 = $y2 + 60; $x3 = $x2; foreach ($text1 as $k => $v) { imagettftext($bg_image, $size, 0, $x, $y, $color, $font, $v); $x = $x + 45; } foreach ($text2 as $k => $v) { imagettftext($bg_image, $size, 0, $x2, $y2, $color, $font, $v); $x2 = $x2 + 45; } foreach ($text3 as $k => $v) { imagettftext($bg_image, $size, 0, $x3, $y3, $color, $font, $v); $x3 = $x3 + 45; } if ($waterfont) { foreach ($waterfont as $k => $v) { imagettftext($bg_image, $size, 0, $waterx, $watery, $color, $font, $v); $waterx = $waterx + 45; } } header("Content-type:image/png"); imagepng($bg_image); imagedestroy($bg_image); imagedestroy($bg_image); imagedestroy($tu1_image); imagedestroy($tu2_image); session_start(); header("Cache-Control: private, max-age=10800, pre-check=10800"); header("Pragma: private"); header("Expires: " . date(DATE_RFC822, strtotime(" 2 day")));
根据标题关键字生成图片实现优质图片PHP代码,随笔记录。
本文转自万象文库www.2wx.com。
标签:size,bg,tu1,image,关键字,PHP,type,tu2,图片 来源: https://www.cnblogs.com/kobayashilin/p/16139647.html