php 加载字体 并保存成图片
Lepaskan: 2016-06-23 13:29:55
[php] view plain copy
-
- // Set the content-type
- header("Content-type: image/png");
-
- // Create the image
- $im = imagecreatetruecolor(400, 100);
-
- // Create some colors
- $white = imagecolorallocate($im, 255, 255, 255);
- $grey = imagecolorallocate($im, 128, 128, 128);
- $black = imagecolorallocate($im, 0, 0, 0);
- imagefilledrectangle($im, 0, 0, 399, 100, $white);
-
- // The text to draw
- $text = '字典网';
- // Replace path by your own font path
- $font = 'fontName.ttf';
-
- // Add some shadow to the text
- //imagettftext($im, 60, 0, 11, 21, $grey, $font, $text);
-
- // Add the text
- imagettftext($im, 60, 0, 0, 70, $black, $font, $text);
-
- // Using imagepng() results in clearer text compared with imagejpeg()
- imagepng($im);
- imagedestroy($im);
如果想保存图可以用下面代码
[html] view plain copy
- ob_start();
- imagejpeg($im);
- $img = ob_get_contents();
- ob_end_clean();
- $size = strlen($img);
-
- $fp2=@fopen('tst.jpg', "a");
- fwrite($fp2,$img);
- fclose($fp2);
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
-
2024-07-24 01:15:32
-
2024-07-24 01:14:33
-
2024-07-24 01:12:02
-
2024-07-24 01:00:59
-
2024-07-24 00:45:54
-
2024-07-24 00:41:43
-
2024-07-24 00:40:17
-
2024-07-24 00:36:02
-
2024-07-24 00:32:54
-
2024-07-24 00:32:14
Topik-topik yang berkaitan
Lagi>