【问题标题】:Merging Three or More Images -- PHP合并三个或更多图像 -- PHP
【发布时间】:2011-11-17 17:45:03
【问题描述】:

对于我的网站,我一直在尝试将人们的角色(目前由几张由 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/”进行写入:是 PathToParentFolderOfFollowingFile/testFile.php 中第 139 行的目录

这个错误究竟是什么意思,如何解决?

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

另外...您如何使透明度起作用?我正在使用的所有文件都是具有透明度的 PNG 文件。

【问题讨论】:

  • 想到两件事 - 您的 php 应用程序没有访问图像目录的权限,或者您没有正确的图像目录路径。
  • 类似问题已回答here

标签: php


【解决方案1】:

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

试试

imagepng($templatePic, 'Images/anActualFileName.png');

我看到the docs 说“路径”,这可能会造成混淆,但在包含文件名的 unix 术语中。如果你只是给它一个目录,它会叫什么文件?

【讨论】:

  • 它现在以各种方式工作,但事实上它没有显示透明度......我该如何解决这个问题?
  • 在 SO 上进行快速搜索 - 你会惊讶于你的发现! ;) stackoverflow.com/questions/1705098/…
  • 但是我的图片已经有透明背景了呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-02
  • 1970-01-01
  • 1970-01-01
  • 2022-08-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多