2012-06-12 81 views
-2

我正在尋找網站工具(可供下載和更改) - jQuery,PHP,GD,ImageMagick等,它允許用戶直接向圖像添加文本。並且可以動態更改字體,大小,字體顏色和文本的位置。謝謝你的建議。將文本動態插入圖像

+0

自己寫在ImageMagick中有什麼問題? – SomeKittens

+0

我不是「在家」在這方面......你能告訴我一些解決方案嗎? – RWX

+0

http://www.imagemagick.org/Usage/text/ – SomeKittens

回答

1

你不說圖像來自哪裏,但這是我的一些舊代碼。它上傳圖像並在保存到服務器之前添加文本。您應該可以根據自己的需要修改它,並確保您驗證用戶數據。此代碼中有一些驗證,它可能需要更新爲PHP 5 +

<?php 
function clean($name, $max) { 
// Remove everything except letters numbers . and @ in the variable 
preg_replace("/[^A-Za-z0-9.\[email protected]]/","",$name); 

// Do not allow excessively long entries 
$name = substr($name, 0, $max); 
return $name; 
} 

// If the form has been submitted do this 
if ($Submit) { 

// Temporary upload image name 
$original_image = $_FILES['filename']['tmp_name']; 

// Name to save the image as - in this case the same as the original 
$new_image = $_FILES['filename']['name']; 

$text_submitted = $_POST['text_submitted']; 

$text_submitted = clean ($text_submitted, 18); 

$text = preg_split('//', $text_submitted, -1, PREG_SPLIT_NO_EMPTY); 
$total = count ($text); 

for ($i=0; $i < $total; $i++) 
{ 
if ($text[$i] == " "){$text[$i] = 88 ;} 
$text[$i] = $text[$i].".gif "; 
$text_array = $text_array.$text[$i]; 
} 

$cmd = "$original_image -pointsize 50 -font Arial -fill rgba\(0,0,0,0.4\) ". 
" -gravity center -annotate +0+0 $text_array "; 
exec("convert $cmd $new_image"); 
     } 

else { ?> 

<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> 
<label>File to upload</label> 
<input type="file" name="filename" /> 
<label>Text to add to the photo</label> 
<input type="text" name="text_submitted" /><br /> 
<input type="Submit" name="Submit" value="Submit" /> 
</form> 
<?php } ?>