準備工做:php
代碼:瀏覽器
<?php header("Content-type: image/jpeg"); //瀏覽器輸出,如不須要可去掉此行 $im = @imagecreatefromjpeg('bg.jpg'); //從圖片創建文件,此處以jpg文件格式爲例 $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); $text = '16'; //要寫到圖上的文字 $font = 'arial.ttf'; //寫的文字用到的字體。 $srcw=imagesx($im); imagettftext($im, 40, 0, 20, 80, $grey, $font, $text); imagettftext($im, 40, 0, 20, 80, $black, $font, $text); imagettftext($im, 40, 0, 20, 80, $white, $font, $text); imagepng($im); imagedestroy($im); ?>
【效果】ide
若是要將圖片保存到某個文件夾,只需將 :字體
imagepng($im);改成:spa
imagepng($im,"路徑/output.png");blog