|
@@ -758,6 +758,12 @@ class Img
|
|
|
$color = $this->_txt['color'];
|
|
|
|
|
|
$fontFile = isset($this->_txt['font']) ? $this->_txt['font'] : "SIMSUN.TTC";
|
|
|
+
|
|
|
+ $this->_txt['autowrap'] = 0;
|
|
|
+ if (isset($this->_txt['width']) && $this->_txt['width'] > 0) {
|
|
|
+ $this->_txt['name'] = $this->_gd_autowrap($this->_txt['size'], $this->_txt['angle'], $fontFile, $this->_txt['name'], $this->_txt['width']);
|
|
|
+ }
|
|
|
+
|
|
|
$position = imagettfbbox($this->_txt['size'], $this->_txt['angle'], $fontFile, $this->_txt['name']);
|
|
|
if ($position) {
|
|
|
$source_x = imagesx($this->_image);
|
|
@@ -777,13 +783,39 @@ class Img
|
|
|
$B = hexdec(substr($color,5));
|
|
|
putenv('GDFONTPATH=' . realpath('.'));
|
|
|
|
|
|
- imagettftext($this->_image, $this->_txt['size'],$this->_txt['angle'], $this->_txt['left'], $this->_txt['top'], imagecolorallocate($this->_image, $R, $G, $B),$fontFile,$this->_txt['name']);
|
|
|
+ imagettftext($this->_image, $this->_txt['size'],$this->_txt['angle'], $this->_txt['left'], $this->_txt['top'] + $this->_txt['autowrap'], imagecolorallocate($this->_image, $R, $G, $B),$fontFile,$this->_txt['name']);
|
|
|
}
|
|
|
|
|
|
imagejpeg($this->_image, $this->_dest['txt']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * @desc 文字自动换行
|
|
|
+ * @param *
|
|
|
+ */
|
|
|
+ private function _gd_autowrap($fontsize, $angle, $fontface, $string, $width) {
|
|
|
+
|
|
|
+ $content = "";
|
|
|
+
|
|
|
+
|
|
|
+ for ($i=0;$i<mb_strlen($string);$i++) {
|
|
|
+ $letter[] = mb_substr($string, $i, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($letter as $l) {
|
|
|
+ $teststr = $content." ".$l;
|
|
|
+ $testbox = imagettfbbox($fontsize, $angle, $fontface, $teststr);
|
|
|
+
|
|
|
+ if (($testbox[2] > $width) && ($content !== "")) {
|
|
|
+ $content .= "\n";
|
|
|
+ $this->_txt['autowrap'] += $this->_txt['size'];
|
|
|
+ }
|
|
|
+ $content .= $l;
|
|
|
+ }
|
|
|
+ return $content;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* @desc 销毁资源
|
|
|
* @param *
|