2014-02-14 28 views
0

下面是在php中動態生成圖像的代碼。我想在這個動態創建的圖像中添加一些圖像。我已經用imagecopy嘗試過我的運氣,但是 失敗了,因爲我認爲它處理已經創建的圖像以將圖像複製到另一個圖像上。所以請儘快幫助。提前致謝。 :)如何在php中動態生成的圖像中添加來自某個源文件的jpeg圖像

<?php 

$my_img = imagecreate(1200, 630); 

$background = imagecolorallocate($my_img, 2,144,162); 

$text_colour = imagecolorallocate($my_img, 255, 255, 0); 

$text_colour1 = imagecolorallocate($my_img, 255, 255, 255); 

$line_colour = imagecolorallocate($my_img, 128, 255, 0); 

$font='C:\Windows\Fonts\ARLRDBD.ttf'; 

imagettftext($my_img, 48, 0, 450, 100, $text_colour, $font,"Hello World"); 

$font1='C:\Windows\Fonts\Arial.ttf'; 

imagettftext($my_img, 32, 0, 650, 160, $text_colour1, $font1,Hello World"); 

imagettftext($my_img, 32, 0, 500, 300, $text_colour1, $font1,"Hello World"); 

imagettftext($my_img, 32, 0, 560, 440, $text_colour1, $font1,"Hello World"); 

header("Content-type: image/png"); 

imagepng($my_img); 

imagepng($my_img,'Ethers.png'); 

imagecolordeallocate($text_colour); 

imagecolordeallocate($text_colour1); 

imagecolordeallocate($background); 

imagedestroy($my_img); 

header('Content-Type: image/png'); 

imagedestroy($my_img); 

?> 
+0

你也有圖像編輯功能,如http://www.php.net/manual/en/ref.image.php –

回答

1

有現成的代碼可用於播放圖像編輯。

從以下鏈接中找到班級。

http://www.phpclasses.org/package/6323-PHP-Manipulate-GIF-JPEG-and-PNG-images.html

這個類可以用來操縱GIF,JPEG和PNG圖像。

它可以以GIF,JPEG和PNG格式加載圖像並執行多種類型的操作。

目前,它可以調整圖片的大小,使圖像上的文字,呈現水印圖像與應用幾種類型的像模糊,邊緣檢測效果,銳化,浮雕等。

產生的圖像可以是保存到文件或以GIF,PNG和JPEG格式顯示爲當前腳本輸出。

+0

我也知道圖像編輯功能的庫,但不知道哪個他們會爲我工作。 – Yudi

+1

您可以使用圖片合併http://www.php.net/manual/en/image.examples.merged-watermark.php。我建議的班級有水印。水印不過是添加了一些不透明的圖像,使其看起來像水印。如果你的透明度不爲零,圖像將顯示爲原樣並被合併。 –

+0

Thankyou。它爲我工作。 :) – Yudi