2016-07-08 46 views
-4

如何讓php創建一個這樣的圖像?Create image PHP

enter image description here

(顯然,如果沒有文字,邊框,線條,箭頭)。

+1

的[PHP:GD](http://php.net/manual/en/book.image.php)文檔,[A相關的問題](HTTP://計算器。 com/questions/645582 /如何在圖表中繪製圖表)和[通用Google搜索](https://www.google.com/search?q=php%20make%20graph)可能做好出發點 – castis

+0

這是如此的廣泛?他很清楚自己想做什麼:製作一張包含三張帶邊框圖像的圖像。如果你沒有看到他給出的示例圖像,它只是廣泛的。 –

回答

1

你可以使用GD庫。

// Load the three image files: 
$images[1]=imagecreatefromjpeg("file1.jpg"); 
$images[2]=imagecreatefromjpeg("file2.jpg"); 
$images[3]=imagecreatefromjpeg("file3.jpg"); 
// Determine their dimensions. 
$totalx=$totaly=0; 
for ($ix in $images) { 
    $img=$images[$ix]; 
    $totalx+=imagesx($img); // get total width 
    $totaly=max($totaly,imagesy($img)); // get maximum height 
} 
$xm=20; // side and in-between margin 
$ym=20; // top and bottom margin 
$totalx+=$xmargin*4; // 2 for the outsides and 2 for the in-betweens 
$totaly+=$ymargin*2; // for top and bottom 
$i=imagecreatetruecolor($totalx,$totaly); 
$xstart=0; // where to place the next image 
for ($ix in $images) { 
    $img=$images[$ix]; 
    $xstart+=$imagesx($img)+$xm; // increase by this image's width plus buffer 
    imagecopy($i,$img,$xstart,$ym,0,0,imagesx($img),imagesy($img)); 
} 
imagepng($i); // this outputs the image data. if you want to write it to a file you can do that with imagepng($i,$filename). 

http://php.net/manual/en/ref.image.php

+0

請記住,您需要使用正確的圖像加載功能。例如,如果源圖像是PNG,那麼您需要使用imagecreatefrompng()而不是imagecreatefromjpeg()。您可以掃描文件名或使用MIME類型來確定圖像格式,然後從*()函數調用相應的圖像 - 有趣的是,這些函數的結尾與MIME類型值匹配!同樣,如果你想輸出非PNG的東西,你必須使用例如imagejpeg($ i)而不是imagepng($ i)。 –

+0

此外,如果您希望圖像在最終圖像中的大小相同,則可以在imagecopy()調用中使用所需的w/h值而不是圖像()和imagesy()。在我的例子中,我推測你想要的圖像尺寸與原來相同。 –