imagecopymerge获得白色背景而不是黑色

时间:2015-07-13 13:25:17

标签: php

我需要将两个图像合并在一起并添加文本。但是当代码输出时我得到黑色背景。当我删除" imagecopymerge"功能我看到白色背景。

$firstUrl = '1.jpg';   
$secondUrl = "2.jpg";
$a  = getimagesize ($firstUrl);    

$x = 320;
$y = $a[1]+88;

$image = imagecreatetruecolor($x, $y);
$white = imagecolorallocate($image, 255, 255, 255);

imagefilledrectangle($image, 0, 0, $x, $y, $white);     

$first = imagecreatefromjpeg($firstUrl);
$second = imagecreatefromjpeg($secondUrl);

imagecopymerge($image,$first,0,0,0,0, $x, $y,100);
imagecopymerge($image,$second,$a[0]-70,$a[1]+10,0,0, 60, 60,100);    

$text_color = imagecolorallocate($image, 51, 51, 51);
$font = 'a.ttf';
imagettftext($image, 12, 0, 10, $a[1]+30, $text_color, $font, "text");

header("Content-Type: image/png");
imagepng($image); 

2 个答案:

答案 0 :(得分:2)

使用要插入的图像的宽度和高度:

imagecopymerge($image,$first,0,0,0,0,imagesx($first),imagesy($first),100);

$x$y是最终图片的尺寸。如果$first小于' ' Transfers Component Data ' If Range("B28").Value + Range("C28").Value <> someValue then Range("B28").Select Selection.Copy Windows("Form.xls").Activate Range("O61:P61").Select ActiveSheet.Paste Range("I71:J71").Select ActiveCell.FormulaR1C1 = "10.00%" Range("A72:P72").Select Range("A1:A21").Select Windows("Transfer Template.xlsm").Activate Range("A1").Select End if End if ' ' Final_Transfer_Macro Macro ' ,那么imagecopymerge()会用黑色填充缺失的区域。

使用imagesx()imagesy(),您可以复制图片的确切区域。

答案 1 :(得分:0)

更改行,imagecopymerge($ image,$ first,0,0,0,0,$ x,$ y,100);像 imagecopymerge($ image,$ first,100,100,0,0,$ x,$ y,100); 然后它应该工作。