Showing
1 changed file
with
29 additions
and
7 deletions
| ... | @@ -212,6 +212,7 @@ class AdminMakeImmerse implements ShouldQueue | ... | @@ -212,6 +212,7 @@ class AdminMakeImmerse implements ShouldQueue |
| 212 | $opacity = $component->opacity ? $component->opacity / 100 : 0.5; | 212 | $opacity = $component->opacity ? $component->opacity / 100 : 0.5; |
| 213 | $font_file = $this->getAbsolutePath($component->font_file); | 213 | $font_file = $this->getAbsolutePath($component->font_file); |
| 214 | $text_bg_box = $component->text_bg_box ?? 0; | 214 | $text_bg_box = $component->text_bg_box ?? 0; |
| 215 | + $font_size = $this->calcFontSize($component->font_size); | ||
| 215 | 216 | ||
| 216 | // 文字淡入淡出模式 | 217 | // 文字淡入淡出模式 |
| 217 | if ($component->draw == 'fade'){ | 218 | if ($component->draw == 'fade'){ |
| ... | @@ -219,13 +220,13 @@ class AdminMakeImmerse implements ShouldQueue | ... | @@ -219,13 +220,13 @@ class AdminMakeImmerse implements ShouldQueue |
| 219 | switch ($component->name){ | 220 | switch ($component->name){ |
| 220 | case 'one_poem': | 221 | case 'one_poem': |
| 221 | foreach ($this->adminMakeVideo->poem2->verses as $item) { | 222 | foreach ($this->adminMakeVideo->poem2->verses as $item) { |
| 222 | - if ($item->content != '') $contents[] = $item->content; | 223 | + if ($item->content != '') $contents[] = $this->autoEnter($item->content, $font_size, $this->output_width); |
| 223 | } | 224 | } |
| 224 | break; | 225 | break; |
| 225 | case 'one_poem_with_annotate': | 226 | case 'one_poem_with_annotate': |
| 226 | foreach ($this->adminMakeVideo->poem2->verses as $item) { | 227 | foreach ($this->adminMakeVideo->poem2->verses as $item) { |
| 227 | - if ($item->content != '') $contents[] = $item->content; | 228 | + if ($item->content != '') $contents[] = $this->autoEnter($item->content, $font_size, $this->output_width); |
| 228 | - if ($item->annotate != '') $contents[] = $item->annotate; | 229 | + if ($item->annotate != '') $contents[] = $this->autoEnter($item->content, $font_size, $this->output_width); |
| 229 | } | 230 | } |
| 230 | break; | 231 | break; |
| 231 | case 'weather': | 232 | case 'weather': |
| ... | @@ -251,13 +252,14 @@ class AdminMakeImmerse implements ShouldQueue | ... | @@ -251,13 +252,14 @@ class AdminMakeImmerse implements ShouldQueue |
| 251 | $sub_text .= 'drawtext="'. | 252 | $sub_text .= 'drawtext="'. |
| 252 | 'fontfile=' . escapeshellarg($font_file) . ':' . | 253 | 'fontfile=' . escapeshellarg($font_file) . ':' . |
| 253 | 'textfile=' . escapeshellarg($text_file) . ':' . | 254 | 'textfile=' . escapeshellarg($text_file) . ':' . |
| 254 | - 'fontsize=' . $this->calcFontSize($component->font_size) . ':' . | 255 | + 'fontsize=' . $font_size . ':' . |
| 255 | 'fontcolor_expr=' . escapeshellarg($text_color . '%{eif\\\\: clip(255*(1*between(t\\, ' . $DS . ' + ' . $FID . '\\, ' . $DE . ' - ' . $FOD . ') + ((t - ' . $DS . ')/' . $FID . ')*between(t\\, ' . $DS . '\\, ' . $DS . ' + ' . $FID . ') + (-(t - ' . $DE . ')/' . $FOD . ')*between(t\\, ' . $DE . ' - ' . $FOD . '\\, ' . $DE . '))\\, 0\\, 255) \\\\: x\\\\: 2 }') . ':' . | 256 | 'fontcolor_expr=' . escapeshellarg($text_color . '%{eif\\\\: clip(255*(1*between(t\\, ' . $DS . ' + ' . $FID . '\\, ' . $DE . ' - ' . $FOD . ') + ((t - ' . $DS . ')/' . $FID . ')*between(t\\, ' . $DS . '\\, ' . $DS . ' + ' . $FID . ') + (-(t - ' . $DE . ')/' . $FOD . ')*between(t\\, ' . $DE . ' - ' . $FOD . '\\, ' . $DE . '))\\, 0\\, 255) \\\\: x\\\\: 2 }') . ':' . |
| 256 | 'x=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][0]) . ':' . | 257 | 'x=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][0]) . ':' . |
| 257 | 'y=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][1]) . ':' . | 258 | 'y=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][1]) . ':' . |
| 258 | '", '; | 259 | '", '; |
| 259 | } | 260 | } |
| 260 | 261 | ||
| 262 | + | ||
| 261 | $drawtext .= $sub_text; | 263 | $drawtext .= $sub_text; |
| 262 | } | 264 | } |
| 263 | 265 | ||
| ... | @@ -269,7 +271,8 @@ class AdminMakeImmerse implements ShouldQueue | ... | @@ -269,7 +271,8 @@ class AdminMakeImmerse implements ShouldQueue |
| 269 | case 'one_poem': | 271 | case 'one_poem': |
| 270 | $stanzas = ''; | 272 | $stanzas = ''; |
| 271 | foreach ($this->adminMakeVideo->poem2->verses as $item) { | 273 | foreach ($this->adminMakeVideo->poem2->verses as $item) { |
| 272 | - if ($item->content != '') $stanzas .= $item->content . "\n"; | 274 | + |
| 275 | + if ($item->content != '') $stanzas .= $this->autoEnter($item->content, $font_size, $this->output_width) . "\n"; | ||
| 273 | } | 276 | } |
| 274 | $contents[] = $stanzas; | 277 | $contents[] = $stanzas; |
| 275 | break; | 278 | break; |
| ... | @@ -290,7 +293,7 @@ class AdminMakeImmerse implements ShouldQueue | ... | @@ -290,7 +293,7 @@ class AdminMakeImmerse implements ShouldQueue |
| 290 | $sub_text .= 'drawtext="'. | 293 | $sub_text .= 'drawtext="'. |
| 291 | 'fontfile=' . escapeshellarg($font_file) . ':' . | 294 | 'fontfile=' . escapeshellarg($font_file) . ':' . |
| 292 | 'textfile=' . escapeshellarg($text_file) . ':' . | 295 | 'textfile=' . escapeshellarg($text_file) . ':' . |
| 293 | - 'fontsize=' . $this->calcFontSize($component->font_size) . ':' . | 296 | + 'fontsize=' . $font_size . ':' . |
| 294 | 'fontcolor=' . $text_color . '@' . $opacity . ':' . | 297 | 'fontcolor=' . $text_color . '@' . $opacity . ':' . |
| 295 | 'x=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][0]) . ':' . | 298 | 'x=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][0]) . ':' . |
| 296 | 'y=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][1]) . ':' . | 299 | 'y=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][1]) . ':' . |
| ... | @@ -304,9 +307,28 @@ class AdminMakeImmerse implements ShouldQueue | ... | @@ -304,9 +307,28 @@ class AdminMakeImmerse implements ShouldQueue |
| 304 | return rtrim($drawtext,', '); | 307 | return rtrim($drawtext,', '); |
| 305 | } | 308 | } |
| 306 | 309 | ||
| 310 | + public function autoEnter($string, $font_width, $video_width) | ||
| 311 | + { | ||
| 312 | + $video_width = $video_width - 2 * $font_width; // 两侧留出空隙 | ||
| 313 | + $row_count = floor($video_width / $font_width); | ||
| 314 | + echo $row_count; | ||
| 315 | + $str_len = mb_strlen($string); | ||
| 316 | + if ($str_len > $row_count) { | ||
| 317 | + $tmp = array_chunk( | ||
| 318 | + preg_split("//u", $string, -1, PREG_SPLIT_NO_EMPTY), $row_count); | ||
| 319 | + $new_str = ""; | ||
| 320 | + foreach ($tmp as $t) { | ||
| 321 | + $new_str .= join("", $t) . "\n"; | ||
| 322 | + } | ||
| 323 | + return $new_str; | ||
| 324 | + }else{ | ||
| 325 | + return $string; | ||
| 326 | + } | ||
| 327 | + } | ||
| 328 | + | ||
| 307 | public function calcFontSize($width) | 329 | public function calcFontSize($width) |
| 308 | { | 330 | { |
| 309 | - return ceil($this->output_width / 360 * $width); | 331 | + return floor($this->output_width / 360 * $width); |
| 310 | } | 332 | } |
| 311 | 333 | ||
| 312 | /** | 334 | /** | ... | ... |
-
Please register or login to post a comment