bballer13sn
bballer13sn

Reputation: 1

Merging Three or More Images -- PHP

For my website, I've been trying to make it so people's characters (which are currently composed of several pictures that are moved by CSS) are merged into one image as to make my life easier. The chunk of code that currently doesn't work is as follows:

                    $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...

This is the error PHP is giving me:

Warning: imagepng() [function.imagepng]: Unable to open 'Images/' for writing: Is a directory in PathToParentFolderOfFollowingFile/testFile.php on line 139

What exactly does this error mean and how can it be fixed?

NOTE: $charRow is not the problem. The query to get that is just not being displayed to all of you.

Also...How do you make the transparency work? All the files I'm working with are PNG files WITH transparency.

Upvotes: 0

Views: 170

Answers (1)

JAL
JAL

Reputation: 21563

That error appears because you need to supply a filename, not a directory. The imagePNG function does not know what file to save this image as.

Try

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

I see the docs say 'path', which could be confusing, but in unix terms that includes a filename. If you just gave it a directory, what would it call the file?

Upvotes: 2

Related Questions