Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
合并三个或更多图像--PHP_Php - Fatal编程技术网

合并三个或更多图像--PHP

合并三个或更多图像--PHP,php,Php,对于我的网站,我一直在努力使人们的角色(目前由几个通过CSS移动的图片组成)合并到一个图像中,以使我的生活更轻松。当前无法工作的代码块如下所示: $template = $charRow['template']; $gender = $charRow['gender']; $shirt = $charRow['shirt']; $pant

对于我的网站,我一直在努力使人们的角色(目前由几个通过CSS移动的图片组成)合并到一个图像中,以使我的生活更轻松。当前无法工作的代码块如下所示:

                    $template = $charRow['template'];
                    $gender = $charRow['gender'];
                    $shirt = $charRow['shirt'];
                    $pants = $charRow['pants'];
                    $hat = $charRow['hat'];

                    $templatePic = imagecreatefrompng("Templates/".$template);

                    if (!empty($shirt)) {
                        $shirtPic = imagecreatefrompng($shirt);
                        imagecopy($templatePic,$shirtPic,0,0,0,0,imagesx($templatePic),imagesy($templatePic));
                    }
                    if (!empty($pants)) {
                        $pantsPic = imagecreatefrompng($pants);
                        imagecopy($templatePic,$pantsPic,0,0,0,0,imagesx($templatePic),imagesy($templatePic));
                    }
                    if (!empty($hat)) {
                        $hatPic = imagecreatefrompng($hat);
                        imagecopy($templatePic,$hatPic,0,0,0,0,imagesx($templatePic),imagesy($templatePic));
                    }

                    imagePNG($templatePic, 'Images/'); //Problem line...
这是PHP给我的错误:

警告:imagepng()[function.imagepng]:无法打开“Images/”进行写入:是第139行PathToParentFolderOfFollowingFile/testFile.php中的目录

这个错误到底意味着什么?如何修复

注意:
$charRow
不是问题所在。要获取的查询并没有显示给所有人


还有…你是如何让透明度发挥作用的?我处理的所有文件都是透明的PNG文件。

出现此错误是因为您需要提供文件名,而不是目录。imagePNG函数不知道将此图像保存为哪个文件

试一试


我看到有人说“path”,这可能会让人困惑,但在unix术语中,它包含一个文件名。如果您只给它一个目录,它会将该文件称为什么?

我想到两件事——要么您的php应用程序没有访问图像目录的权限,或者您没有图像目录的正确路径。类似的问题已经得到回答。它现在在各个方面都可以工作,但事实上它没有显示透明度…我如何解决这个问题?在上面快速搜索-您会对发现的内容感到惊讶!;)但是,我的图像已经有了透明的背景,这一事实又如何呢?
imagepng($templatePic, 'Images/anActualFileName.png');