2013-04-26 46 views
-2

對我有這樣的代碼工作這使文本在PHP中的圖像,但是當我保存生成的圖像投射到我的電腦只圖像顯示和文本沒有。PHP文本在圖像 - 文本犯規顯示保存的圖像

這裏是我使用的代碼:

<?php 
header("Content-type: image/png"); 
    $imgPath = 'template4.png'; 
    $image = imagecreatefrompng($imgPath); 
    $color = imagecolorallocate($image, 255, 0, 0); 

error_reporting(0); 
if(isset($_POST['submit'])) 

{ 
    $GT = $_POST['GT']; 


    $Gamertag = preg_replace('/ /', "+", $GT); 



    $content = file_get_contents("http://www.ea.com/uk/football/profile/{$Gamertag}/360"); 


    if ($content == false) { 
     echo "Cant find this Gamertag"; 
     exit(); 
    } 


    // Titles Won 

    preg_match('#<div class="stat"> 
       Titles Won    <span>([0-9\.]*)<span class="sprite13 goalImage cup"></span></span>#', $content, $titleswon); 
} 


$string = $titleswon[1]; 
$fontSize = 3; 
$x = 5; 
$y = 5; 
imagestring($image, $fontSize, $x, $y, $string, $color); 
imagepng($image); 
?> 

如果我只設置$字符串$字符串= '你好'; hello在保存時保留字,但是因爲我使用preg_match來獲取要打印到圖像上的值,所以當我保存時文本不顯示。

任何幫助,謝謝。

+2

所以這是一個正則表達式問題.... – migajek 2013-04-26 12:22:21

+0

你如何保存圖像? – Robin 2013-04-26 12:40:21

+0

只需右擊+節省 – Koala 2013-04-26 12:41:20

回答

1

保存直接使用圖像:

imagepng($Image, The path to save the file to.) 
1

正如評論所說,這是正則表達式的問題,不是文字到圖像的問題。

首先,你應該檢查的preg_match的結果與布爾值false,看是否匹配成功。 與\s+\s* 做至少的var_dump看到匹配的結果替換圖案的任何空白。

+0

文本並在圖像上顯示的,所以在一定的preg_match合作,它只有當我將圖像保存它不顯示 – Koala 2013-04-26 12:32:28