php – 如何将多个图像和文本合并为单个图像?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 如何将多个图像和文本合并为单个图像?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4453字,纯文字阅读大概需要7分钟。
内容图文
![php – 如何将多个图像和文本合并为单个图像?](/upload/InfoBanner/zyjiaocheng/810/1e375d61d5ec44e09752848b701e8cd3.jpg)
我在div中有多个PNG图像,这些图像是PNG,并根据他/她选择的自定义选项呈现为用户的单个图像.此外,添加文本也可以作为其他功能启用,这允许带有文本的div添加到这些图像的上方.
现在我想生成一个图像,其中包含多个图像和文本,保持字体系列和文字大小.
例如.界面上显示的图像与图像和文本的组合. (它设法与css定位一起出现)
这是由下面的两个图像和文本组成的
这是我尝试拍摄图像:create-image.php文件
<?php
createimageinstantly();
function createimageinstantly($img1='',$img2='',$img3=''){
$x=$y=1000;
header('Content-Type: image/png');
$targetFolder = '/gw/media/uploads/processed/';
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$img1 = $targetPath.'img1.png';
$img2 = $targetPath.'img2.png';
$img3 = $targetPath.'img3.png';
$outputImage = imagecreatetruecolor(1000, 1000);
$first = imagecreatefrompng($img1);
$second = imagecreatefrompng($img2);
$third = imagecreatefrompng($img3);
imagecopy($outputImage,$first,0,0,0,0, $x, $y);
imagecopy($outputImage,$second,0,0,0,0, $x, $y);
imagecopy($outputImage,$third,0,200,-200,0, $x, $y);
imagepng($outputImage, $targetPath .round(microtime(true) * 1000).'.png');
imagedestroy($outputImage);
}
?>
但这给了我整个黑色的图像
此外,我需要在最终生成的图像上混合文本
编辑:
> jpg图像更改为png
> imagecopymege更改为imagecopy
最新结果:
<?php
createimageinstantly();
//$targetFolder = '/gw/media/uploads/processed/';
//$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
//$img3 = $targetPath.'img3.png';
//print_r(getimagesize('http://www.vapor-rage.com/wp-content/uploads/2014/05/sample.jpg'));
function createimageinstantly($img1='',$img2='',$img3=''){
$x=$y=600;
header('Content-Type: image/png');
$targetFolder = '/gw/media/uploads/processed/';
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$img1 = $targetPath.'img1.png';
$img2 = $targetPath.'img2.png';
$img3 = $targetPath.'img3.png';
$outputImage = imagecreatetruecolor(600, 600);
// set background to white
$white = imagecolorallocate($outputImage, 255, 255, 255);
imagefill($outputImage, 0, 0, $white);
$first = imagecreatefrompng($img1);
$second = imagecreatefrompng($img2);
$third = imagecreatefrompng($img3);
//imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
imagecopyresized($outputImage,$first,0,0,0,0, $x, $y,$x,$y);
imagecopyresized($outputImage,$second,0,0,0,0, $x, $y,$x,$y);
imagecopyresized($outputImage,$third,200,200,0,0, 100, 100, 204, 148);
imagepng($outputImage, $targetPath .round(microtime(true)).'.png');
imagedestroy($outputImage);
}
?>
和输出图像
解决方法:
我用这种方式实现了它,
使用这3张图片,img1.png,img2.png,img3.png
并创建-mage.php文件
<?php
createimageinstantly();
//$targetFolder = '/gw/media/uploads/processed/';
//$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
//$img3 = $targetPath.'img3.png';
//print_r(getimagesize('http://www.vapor-rage.com/wp-content/uploads/2014/05/sample.jpg'));
function createimageinstantly($img1='',$img2='',$img3=''){
$x=$y=600;
header('Content-Type: image/png');
$targetFolder = '/gw/media/uploads/processed/';
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$img1 = $targetPath.'img1.png';
$img2 = $targetPath.'img2.png';
$img3 = $targetPath.'img3.png';
$outputImage = imagecreatetruecolor(600, 600);
// set background to white
$white = imagecolorallocate($outputImage, 255, 255, 255);
imagefill($outputImage, 0, 0, $white);
$first = imagecreatefrompng($img1);
$second = imagecreatefrompng($img2);
$third = imagecreatefrompng($img3);
//imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
imagecopyresized($outputImage,$first,0,0,0,0, $x, $y,$x,$y);
imagecopyresized($outputImage,$second,0,0,0,0, $x, $y,$x,$y);
imagecopyresized($outputImage,$third,200,200,0,0, 100, 100, 204, 148);
// Add the text
//imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
//$white = imagecolorallocate($im, 255, 255, 255);
$text = 'School Name Here';
$font = 'OldeEnglish.ttf';
imagettftext($outputImage, 32, 0, 150, 150, $white, $font, $text);
$filename =$targetPath .round(microtime(true)).'.png';
imagepng($outputImage, $filename);
imagedestroy($outputImage);
}
?>
结果图像是
参考:imagecopyresized& imagettftext
感谢您通过评论/答案提出的建议.
我还在http://sumankc.com/2016/01/30/merge-multiple-images-and-text-to-create-single-image-php-gd-library/详细发表了这篇文章
美好的一天 !!
内容总结
以上是互联网集市为您收集整理的php – 如何将多个图像和文本合并为单个图像?全部内容,希望文章能够帮你解决php – 如何将多个图像和文本合并为单个图像?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。