Php 图像复制合并不工作
这是我运行的代码,完整的文件Php 图像复制合并不工作,php,php-gd,Php,Php Gd,这是我运行的代码,完整的文件 <?php $image1 = imagecreatefrompng('a.png'); //300 x 300 $image2 = imagecreatefrompng('b.png'); //150 x 150 imagecopymerge($image1, $image2, 0, 0, 75, 75, 150, 150, 50); ?> 我错过了什么?我需要什么吗?imagecopymerge()的响应是真是假(根据位于的PHP手册) 因此
<?php $image1 = imagecreatefrompng('a.png'); //300 x 300
$image2 = imagecreatefrompng('b.png'); //150 x 150
imagecopymerge($image1, $image2, 0, 0, 75, 75, 150, 150, 50); ?>
我错过了什么?我需要什么吗?imagecopymerge()的响应是真是假(根据位于的PHP手册) 因此,脚本不会向浏览器输出任何内容。如果试图输出到浏览器,请将脚本更改为:
<?php
$source = imagecreatefrompng('a.png');
$destination = imagecreatefrompng('b.png');
imagecopymerge($destination, $source, 0, 0, 75, 75, 150, 150, 50);
//Output the correct header to the browser
header('Content-Type: image/png');
//Output the image
imagepng($destination);
?>
或者,如果希望将图像保存到文件中,可以执行以下操作:
<?php
$source = imagecreatefrompng('a.png');
$destination = imagecreatefrompng('b.png');
imagecopymerge($destination, $source, 0, 0, 75, 75, 150, 150, 50);
//Output the correct header to the browser
header('Content-Type: image/png');
//Path to save the image too
$path = '/path/to/where/i/want/to/save/';
//Save the image
imagepng($destination, $path);
?>
什么不起作用?您的问题是什么?函数调用true
或false
返回的值是什么?谢谢,这就解释了问题,还有一个问题问:如何将其保存为服务器上的文件?我已经用保存示例更新了答案。imagepng()只需要另一个输入来指定路径。请注意,这只适用于PNG,如果您使用的是JPG或GIF,请确保使用专门用于这些扩展的图像。第一个代码工作正常,但第二个代码不起任何作用,它不会将任何内容保存到给定路径。。任何解决方案?请尝试启用错误报告。此外,您还重新检查了要保存图像的文件夹的权限。