【问题标题】:PHP - Combine two images verticallyPHP - 垂直组合两个图像
【发布时间】:2020-07-22 18:09:57
【问题描述】:

我在我的 Laravel 应用程序中组合了两个图像,它可以在我的本地机器上运行。但是底部图像在我的 Ubuntu 服务器上消失了。所有图像均小于 100kb。内存限制设置为 -1。

注意:在合并之前,我将顶部图像转换为与底部图像具有相同宽度。

$top_image_path = '/textImage.jpg';
$bottom_image_path = '/blueImage.jpg';

list($top_image_width, $top_image_height) = getimagesize($top_image_path);
list($bottom_image_width, $bottom_image_height) = getimagesize($bottom_image_path);

$merged_width = $bottom_image_width;
$merged_height = $top_image_height + $bottom_image_height;

$merged_image = imagecreatetruecolor($merged_width, $merged_height);

imagealphablending($merged_image, false);
imagesavealpha($merged_image, true);

$img1 = imagecreatefromjpeg($top_image_path);
$img2 = imagecreatefromjpeg($bottom_image_path);

imagecopy($merged_image, $img1, 0, 0, 0, 0, $top_image_width, $top_image_height);
imagecopy($merged_image, $img2, 0, $bottom_image_width, 0, 0, $bottom_image_width, $bottom_image_height);

imagejpeg($merged_image, 'merged_image.jpg'); 

结果:

我本地机器上的输出图像:

Ubuntu 服务器上的输出图像:

【问题讨论】:

    标签: php image-processing


    【解决方案1】:

    我认为该行存在以下问题。

    imagecopy($merged_image, $img2, 0, $top_image_height, 0, 0, $bottom_image_width, $bottom_image_height);
    

    【讨论】:

      猜你喜欢
      • 2018-10-07
      • 2015-10-14
      • 2021-01-04
      • 1970-01-01
      • 2020-07-14
      • 2014-02-04
      • 2019-07-04
      • 2011-04-22
      • 1970-01-01
      相关资源
      最近更新 更多