PHP对图片资源进行左右上下拼接两种方法

<?php

/*

欢迎使用贪夜php函数

分析一些自己写的免费函数可供调用,边学习,边分享,小白学习,大佬勿喷

更多可进QQ群:951387336;

贪夜QQ:2899133851


 

*/

    function picStitching_u_d($path1,$path2) {

        //上下合成图片

        //path1-图片1路径,path2-图片2路径

     $photo1 = $path1;

     $photo2 = $path2;

     $photo1info = getimagesize ($photo1);

     $photo2info = getimagesize ($photo2);

     

     $photo1width = $photo1info[0];

     $photo1height = $photo1info[1];

     

     $photo2width = $photo2info[0];

     $photo2height= $photo2info[1];

     

     $initwidth = max (array($photo1width,$photo2width));

     $initheight = $photo1height + $photo2height;

     //创建画布

     $image = imagecreatetruecolor($initwidth, $initheight);

     //合成图片

    imagecopyresized($image ,imagecreatefromjpeg($photo1),0, 0, 0, 0,$photo1width,$photo1height,$photo1width,$photo1height);  

    imagecopyresized($image,imagecreatefromjpeg($photo2),0,$photo1height, 0, 0,$initwidth,$photo2height,$photo2width,$photo2height);

    //协议头

    ob_clean();

    header ("Content-Type:image/jpeg");

    //输出图片

    imagejpeg($image);

    //销毁图片

    imagedestroy($image);

    }  

    function picStitching_l_r($path1,$path2) {

        //左右合成图片

        //path1-图片1路径,path2-图片2路径

     $photo1 = $path1;

     $photo2 = $path2;

     $photo1info = getimagesize ($photo1);

     $photo2info = getimagesize ($photo2);

     

     $photo1width = $photo1info[0];

     $photo1height = $photo1info[1];

     

     $photo2width = $photo2info[0];

     $photo2height= $photo2info[1];

     

     $initwidth = $photo1width+$photo2width;

     $initheight = max(array($photo1height,$photo2height));

     //创建画布

     $image = imagecreatetruecolor($initwidth, $initheight);

     //合成图片

     imagecopyresized($image ,imagecreatefromjpeg($photo1),0, 0, 0, 0,$photo1width,$initheight,$photo1width,$photo1height);  

     imagecopyresized($image,imagecreatefromjpeg($photo2),$photo1width,0, 0, 0,$photo2width,$initheight,$photo2width,$photo2height);

    //协议头

    ob_clean();

    header ("Content-Type:image/jpeg");

    //输出图片

    imagejpeg($image);

    //销毁图片

    imagedestroy($image);

    }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
拼接多张图片的流程可以分为以下步骤: 1. 加载多张图片:使用Qt中的QImage类加载多张图片,可以使用QImage::load函数加载文件或QImage::fromData函数加载内存数据。 2. 调整图片大小:如果需要将图片进行拼接,需要先调整图片的大小使其尺寸相同,可以使用QImage::scaled函数进行缩放。 3. 创建目标图像:根据需要拼接的方式,创建一个目标图像,可以使用QImage::size函数获取图片大小,然后使用QImage::copy函数创建一个新的QImage对象。 4. 将图片拼接到目标图像:根据需要拼接的方式,使用QPainter类将多张图片绘制到目标图像上,可以使用QPainter::drawImage函数绘制图片。 5. 保存拼接后的图片:使用QImage::save函数将拼接后的图片保存到文件或内存中。 下面是一个简单的示例代码,可以实现左右拼接多张图片: ```cpp // 加载多张图片 QList<QImage> images; images.append(QImage("image1.png")); images.append(QImage("image2.png")); images.append(QImage("image3.png")); // 调整图片大小 int width = images[0].width(); int height = images[0].height(); for (int i = 1; i < images.size(); i++) { if (images[i].width() != width || images[i].height() != height) { images[i] = images[i].scaled(width, height); } } // 创建目标图像 QImage result(width * images.size(), height, QImage::Format_ARGB32); result.fill(Qt::transparent); // 将图片拼接到目标图像 QPainter painter(&result); for (int i = 0; i < images.size(); i++) { painter.drawImage(i * width, 0, images[i]); } // 保存拼接后的图片 result.save("result.png"); ``` 如果需要实现上下拼接,可以将目标图像的宽度设置为图片宽度,高度设置为所有图片高度之和,然后依次将每张图片绘制到目标图像上即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贪夜怕黑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值