我有n图像,并且想用php代码创建一个图像。我使用imagecopymerge(),但无法做到。请举例子?PHP - 从图像创建一个图像
3
A
回答
8
代码:
$numberOfImages = 3;
$x = 940;
$y = 420;
$background = imagecreatetruecolor($x, $y*3);
$firstUrl = '/images/upload/photoalbum/photo/1.jpg';
$secondUrl = '/images/upload/photoalbum/photo/2.jpg';
$thirdUrl = '/images/upload/photoalbum/photo/3.jpg';
$outputImage = $background;
$first = imagecreatefromjpeg($firstUrl);
$second = imagecreatefromjpeg($secondUrl);
$third = imagecreatefromjpeg($thirdUrl);
imagecopymerge($outputImage,$first,0,0,0,0, $x, $y,100);
imagecopymerge($outputImage,$second,0,$y,0,0, $x, $y,100);
imagecopymerge($outputImage,$third,0,$y*2,0,0, $x, $y,100);
imagejpeg($outputImage, APPLICATION_PATH .'/images/upload/photoalbum/photo/test.jpg');
imagedestroy($outputImage);
2
感谢kruksmail,
我适应特定项目中的图像可能是未知的答案。所以我让你的答案与一系列图像一起工作。
它还可以指定您想要的行数或列数。我添加了一些意见,以帮助也。
$images = array('/images/upload/photoalbum/photo/1.jpg','/images/upload/photoalbum/photo/2.jpg','/images/upload/photoalbum/photo/3.jpg');
$number_of_images = count($images);
$priority = "columns"; // also "rows"
if($priority == "rows"){
$rows = 3;
$columns = $number_of_images/$rows;
$columns = (int) $columns; // typecast to int. and makes sure grid is even
}else if($priority == "columns"){
$columns = 3;
$rows = $number_of_images/$columns;
$rows = (int) $rows; // typecast to int. and makes sure grid is even
}
$width = 150; // image width
$height = 150; // image height
$background = imagecreatetruecolor(($width*$columns), ($height*$rows)); // setting canvas size
$output_image = $background;
// Creating image objects
$image_objects = array();
for($i = 0; $i < ($rows * $columns); $i++){
$image_objects[$i] = imagecreatefromjpeg($images[$i]);
}
// Merge Images
$step = 0;
for($x = 0; $x < $columns; $x++){
for($y = 0; $y < $rows; $y++){
imagecopymerge($output_image, $image_objects[$step], ($width * $x), ($height * $y), 0, 0, $width, $height, 100);
$step++; // steps through the $image_objects array
}
}
imagejpeg($output_image, 'test.jpg');
imagedestroy($output_image);
print "<div><img src='test.jpg' /></div>";
+0
感谢您的这一点,我能够适应这个问题,以解决我有一个问题,我有 –
+0
2.5年并仍然有帮助。谢谢!仅供参考,如果您想从中心裁剪图像而不是左侧边缘,可以将'imagecopymerge()'方法修改为:imagecopymerge($ output_image,$ image_objects [$ step],($ width * $ x),($ height * $ y),imagesx($ image_objects [$ step])/ 2 - $ width/2,0,$ width,$ height,100);' – justinl
相关问题
- 1. PHP - 创建一个从其他图像
- 2. PHP:如何从另一个PNG图像创建图像
- 3. PHP创建图像
- 4. (iphone)我从图像创建一个新的图像时,创建一个泄漏?
- 5. 从朋友的个人资料图像创建图像 - Facebook/PHP
- 6. 从2张图像创建图像
- 7. 使用PHP从一个图像文件夹创建缩略图
- 8. Java - 创建一个图像
- 9. ASP.net创建一个图像
- 10. 创建一个图像库
- 11. 创建一个tiff图像
- 12. 从较大的图像创建一个子图像
- 13. JavaFX从现有的图像创建一个新的图像
- 14. 从JPanel创建一个小图像
- 15. 从图像创建位图
- 16. 从图形创建图像
- 17. 创建一个高亮图像地图
- 18. 从裁剪图像创建新图像
- 19. 如何创建一个tabView像图像
- 20. PHP/JS图像创建
- 21. 使用PHP创建图像
- 22. 从表格创建图像
- 23. 如何从另一幅图像的一部分创建图像?
- 24. 从html创建图像
- 25. 从Blob创建图像
- 26. 从pdf创建图像
- 27. 创建一个动态PNG图像
- 28. 创建一个div的图像?
- 29. 从字节创建图像[]
- 30. 从图像创建gdoc(OCR)
请发表您的评论。 – Nadh
在这里看到http://stackoverflow.com/questions/1394061/how-to-merge-transparent-png-with-image-using-php –
如果你想复制和重新调整大小的图像遵循教程http ://blog.webtech11.com/2012/04/21/upload-and-resize-an-image-with-php.html –