我正在構建一個Facebook應用程序,我需要將多個個人資料圖片切換爲一個大圖片。有沒有可能在PHP中的任何方式?如何在php中將多個圖像拼接成單一圖像?
0
A
回答
1
請參閱http://www.php.net/manual/en/function.imagecopy.php上的示例並多次使用imagecopy()
。
1
我對這個問題很陌生,但我正在開發一個腳本來拍攝圖像並將它們縫合在一起。現在它只適用於所有圖像尺寸相同的情況,但我正在努力改變這一點,並歡迎捐款。我用這個做CSS圖像懸停/非懸停狀態的圖形網站:
https://github.com/ElusiveMind/image_stitch
/**
* Image stitching function.
*
* Now operates with images of varying heights as well as widths.
*
* @param array $files
* An array of files. Each element is a path to the file in question.
*
* @param int $rows
* The number of rows the end resulting image will have. The images
* will be added to the new image in the order of the array divided
* equally in number to the rows specified here.
*
* @param int $action
* An integer (or static define) of the action to take on the resulting
* image.
* IMAGE_STITCH_DISPLAY - Display the item (default action).
* IMAGE_STITCH_SAVE - Save the image to the file system (path required).
* IMAGE_STITCH_RETURN - Return the resulting file pointer to the calling
* function for processing there.
*
* @param string $path
* The path of where to save the resulting new image.
*
* @return image $image
* The image data that can have whatever done to it.
*/
function image_stitch($files, $rows = 2, $action = IMAGE_STITCH_DISPLAY, $path = NULL) {
foreach($files as $file) {
$path = explode('.', $file);
if ($path[count($path)-1] == 'png') {
$images[] = imagecreatefrompng($file);
}
else {
$images[] = imagecreatefromjpeg($file);
}
}
$number_of_images = count($images);
$number_of_columns = ($number_of_images/$rows) - 1;
$total_width = 0;
$max_width = 0;
$total_heights = array();
$widths = array(array());
$grid = array(array());
for ($y = 1; $y <= $rows; $y++) {
$this_height = $this_width = 0;
for ($x = 0; $x <= $number_of_columns; $x++) {
if (empty($files[(($y + ($x - 1)) + ($number_of_columns * ($y - 1)))])) {
next;
}
$image_size = getimagesize($files[(($y + ($x - 1)) + ($number_of_columns * ($y - 1)))]);
$grid[$x][$y] = $images[(($y + ($x - 1)) + ($number_of_columns * ($y - 1)))];
$width = $image_size[0];
$height = $image_size[1];
$widths[$x][$y][] = $width;
$this_width += $width;
if ($height > $this_height) {
$this_height = $height;
}
if ($x == 0 && $y > 1) {
$total_heights[] = $this_height;
if ($max_width < $this_width) {
$max_width = $this_width;
}
}
}
}
$total_heights[] = $this_height;
if ($max_width < $this_width) {
$max_width = $this_width;
}
$destination_image = imagecreatetruecolor($max_width, array_sum($total_heights));
$black = imagecolorallocate($destination_image, 0, 0, 0);
imagecolortransparent($destination_image, $black);
imagealphablending($destination_image, FALSE);
imagesavealpha($destination_image, TRUE);
// place our images
foreach($grid as $instance_key => $instance) {
$height = $total_heights[$instance_key];
foreach($instance as $reference_key => $reference) {
imagecopyresampled($destination_image, $reference, $instance_key * 180, ($reference_key - 1) * 180, 0, 0, 180, 180, 180, 180);
}
}
// Display the image if directed
if ($action = IMAGE_STITCH_DISPLAY) {
header('content-type: image/png');
imagepng($destination_image);
imagedestroy($destination_image);
exit();
}
// Return the image if directed.
if ($action == IMAGE_STITCH_RETURN) {
return $destination_image;
}
// If we are saving the image, save it with no compression or filters.
if (!$empty($path)) {
imagepng($destination_image, $path, 0, PNG_NO_FILTER);
}
return TRUE;
}
相關問題
- 1. 將多個圖像拼接成一個SL/WP7
- 2. 如何拼接多個圖像
- 3. 如何優化多個圖像拼接?
- 4. 多個攝像頭圖像拼接
- 5. 用PHP拼接圖像GD
- 6. 將圖像拼接在一起Opencv -Python
- 7. opencv:將圖像拼接在一起
- 8. 圖像拼接
- 9. 如何在Android中將多個圖像組合成單個圖像?
- 10. 使用Javascript將多個圖像拼接在一起
- 11. 用OpenCV將小圖像拼接成更大的圖像
- 12. 如何使用C#中的MagickNet將圖像拼接在一起?
- 13. R拼接圖像
- 14. OpenCV - 圖像拼接
- 15. 圖像拼接&OCR
- 16. 將多個圖像壓縮成單個圖像
- 17. 在iOS上拼接圖像
- 18. 如何使用ImageMagick將圖標連接成單個圖像?
- 19. 單個圖像中的多個圖像
- 20. 用ChunkyPNG將多個圖像「條」組合成一個圖像
- 21. 如何在另一個圖像中顯示多個圖像。
- 22. 如何在數字微圖中將圖像的幀合併成一個圖像?
- 23. 使用Image Magick我需要將兩個圖像的一半拼接成一個新圖像
- 24. 多圖像拼接 - 添加第三圖像
- 25. 如何在PHP中的另一個圖像內包含圖像?
- 26. 將圖像分割成多張圖像
- 27. 如何合併單個圖像中的多個圖像
- 28. 無法拼接圖像
- 29. 拼接無重疊圖像
- 30. 圖像建模/拼接
沒有任何API來創建照片拼貼? – Jeyaganesh 2011-02-11 18:04:47