Created
September 23, 2024 13:05
-
-
Save AaEzha/e2e634649e608d423205130d454317eb to your computer and use it in GitHub Desktop.
Generate gambar dummy dengan text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Fungsi untuk membuat gambar menggunakan FFMPEG | |
| function generateImage($text, $textColor, $backgroundColor, $outputImage) | |
| { | |
| // Konversi warna teks dan background menjadi format rgba yang bisa digunakan oleh FFMPEG | |
| $textColor = "0x" . ltrim($textColor, '#'); | |
| $backgroundColor = "0x" . ltrim($backgroundColor, '#'); | |
| // Ukuran gambar | |
| $width = 200; | |
| $height = 200; | |
| // Perintah FFMPEG untuk membuat gambar | |
| $ffmpegCommand = "ffmpeg -f lavfi -i color=c=$backgroundColor:s={$width}x{$height} -vf " . | |
| "'drawtext=fontfile=/path/to/font.ttf:text=\"$text\":fontcolor=$textColor:x=(w-text_w)/2:y=(h-text_h)/2'" . | |
| " -frames:v 1 $outputImage"; | |
| // Eksekusi perintah | |
| shell_exec($ffmpegCommand); | |
| } | |
| // Panggil fungsi untuk membuat gambar dengan teks, warna teks, dan background yang diinginkan | |
| $text = $_GET['text']; | |
| $textColor = "#" . $_GET['textcolor']; // Warna teks dalam format hex | |
| $backgroundColor = "#" . $_GET['bgcolor']; // Warna background dalam format hex | |
| $outputImage = "output_image-".time().".png"; | |
| generateImage($text, $textColor, $backgroundColor, $outputImage); | |
| echo "Gambar berhasil dibuat: " . $outputImage; | |
| echo "<br>"; | |
| echo "<img src='$outputImage'>"; | |
| // Cara menggunakan: | |
| // Akses browser dengan url sebagai berikut: localhost/ffmpeg.php?text=Laravel&textcolor=FFFFFF&bgcolor=1A2BC3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment