2016-11-23 112 views
0

您好我編碼的圖像生成從文本到影像,之後造成的,當我想保存爲圖像它顯示我 -*.php file, and not .png (image)- 代碼:無法保存使用php創建的圖像 - imagepng();

$name = $_POST['tekst']; 
$file ="imgs/tbybc1.png"; 
header('Content-Type: image/png'); 
$im = imagecreatefrompng($file); 
$white = imagecolorallocate($im, 255, 255, 255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$black = imagecolorallocate($im, 0, 0, 0); 
$text = $name; 
$font = 'fonts/Roboto-Thin.ttf'; 
imagettftext($im, 40, 0, 70, 215, $white, $font, $text); 
//imagettftext($im, 20, 0, 260, 255, $white, $font, $data); 
imagepng($im); 
imagedestroy($im); 

我能爲它做的,我用Google搜索,但我沒有找到任何東西。有沒有解決方案來做到這一點?或者如果有任何圖像生成器的方法告訴我:)謝謝:)

回答

0

您可以使用htaccess重寫爲此。

例如。

RewriteRule ^/captcha.png$ /gen.php [NC,L] 

然後就在您的網頁源captcha.png:

<img src="/captcha.png" alt="" />