나는 facebook 앱에 불을 붙이고 있는데, 여러 프로필 사진을 하나의 큰 이미지로 전환해야합니다. PHP에서 가능한 방법이 있습니까?PHP에서 여러 개의 이미지를 하나의 단일 이미지로 스티칭하는 방법은 무엇입니까?
0
A
답변
1
http://www.php.net/manual/en/function.imagecopy.php의 예를 참조하고 imagecopy()
을 여러 번 사용하십시오.
1
저는이 질문에 새로운 것이지만 이미지를 가져와 함께 결합하는 스크립트를 개발 중입니다. 현재 모든 이미지의 크기가 동일하면 작동하지만 변경 작업을하고 있으며 기고를 환영합니다. 사진 콜라주를 만들 수있는 API가
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. Java를 사용하여 여러 .png 이미지를 단일 이미지로 병합하는 방법은 무엇입니까?
- 2. 중복 된 이미지를 하나의 단일 이미지로 병합
- 3. 여러 개의 NSImage를 하나의 큰 이미지로 합성하는 방법은 무엇입니까?
- 4. Iphonesdk 세 개의 이미지를 두 개의 단일 이미지로 병합하십시오.
- 5. 이미지를 여러 이미지로 분할
- 6. JavaScript를 사용하여 여러 이미지를 하나의 이미지로 결합 할 수 있습니까?
- 7. 많은 RGB 이미지를 MATLAB에서 하나의 이미지로 연결하는 방법은 무엇입니까?
- 8. iPhone Apps에서 두 이미지를 단일 이미지로 병합하는 방법은 무엇입니까?
- 9. 세 가지 이미지로 취급되는 단일 이미지를 만드는 방법은 무엇입니까?
- 10. 하나의 파일에 여러 개의 이미지를 저장하는 방법
- 11. 하나의 큰 이미지를 4 개의 작은 이미지로 나누면로드 시간이 단축됩니까?
- 12. 두 개의 PNG 이미지를 .NET을 사용하여 하나의 이미지로 결합
- 13. 여러 이미지로 드로어 블을 만드는 방법은 무엇입니까?
- 14. 부동 소수점/이미지를 단일 이미지로 변환
- 15. 하나의 Graphviz 레코드 필드에서 여러 개의 가장자리를 생성하는 방법은 무엇입니까?
- 16. PHP에서 단일 메소드에 동시에 액세스하는 여러 사용자를 차단하는 방법은 무엇입니까?
- 17. 하나의 캔버스에서 여러 이미지를 사용해야합니까?
- 18. 여러 이미지를 표시하는 방법은 무엇입니까?
- 19. 여러 컨트롤을 이미지로 렌더링
- 20. 하나의 IP가있는 단일 iis 서버에 여러 개의 ftp 사이트
- 21. 여러 개의 PHP 스크립트를 하나의 파일에 병합
- 22. jQuery 라이트 박스를 하나의 링크에서 여러 이미지로 열려면 어떻게합니까?
- 23. 여러 이미지를 하나의 이미지에 정렬 하시겠습니까?
- 24. 단일 행에 이미지를 표시
- 25. 격자보기에서 여러 열의 이미지를 표시하는 방법은 무엇입니까?
- 26. 여러 개의 Python 소스 파일을 하나의 파일로 연결하는 방법은 무엇입니까?
- 27. django에서 하나의 템플릿에 여러 개의 뷰를 추가하는 방법은 무엇입니까?
- 28. 하나의 WPF 응용 프로그램에서 여러 개의 창을 사용하는 방법은 무엇입니까?
- 29. 여러 버전에서 단일 XPO를 유지하는 방법은 무엇입니까?
- 30. 여러 개의 SPGridview 대신 단일 DataKeyName?
이 : 나는 웹 사이트에 대한 CSS 이미지 - 호버/비 호버 상태 그래픽을 만들기 위해이를 사용했습니다? – Jeyaganesh
나는 이미지를 바느질하는 대신에 대안을 만들었습니다. 정사각형 상자를 따라 표시했습니다. http://devlup.com/programming/php/how-to-create-facebook-application-using-php-and-graph-api/1589/ – Jeyaganesh