Roxxor
10-23-2008, 04:09 PM
I am trying to show images in a folder with imagePNG. But I can´t get it working. Something seems to go wrong with ImageCreateFromPNG function. If I remove the header in pix.php, the images will appear but I will also get som warnings. If I use the header then the browser says it cannot output the image because it contains errors.
index.php
<?php
include "pix.php";
$dir = ".";
$dh = opendir($dir);
while(($file = readdir($dh)) != false)
{
if(preg_match("/.png/", $file) or preg_match("/.PNG/", $file))
{
$pix[] = $file;
}
}
closedir($dh);
?>
<html>
<head>
<title></title>
</head>
<body>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<?php
foreach($pix as $key => $value)
echo "<td><img src=\"pix.php?pic=$value \" /></td>";
?>
</tr>
</table>
</body>
</html>
pix.php
<?php
$pic = $_REQUEST['pic'];
$src = ImageCreateFromPNG($pic);
$width = ImageSx($src);
$height = ImageSy($src);
$x = $width/2;
$y = $height/2;
$dst = ImageCreateTrueColor($x,$y);
ImageCopyResampled($dst,$src,0,0,0,0,$x,$y,$width,$height);
header('Content-Type: image/png'); // if I remove this line, the images are showing but I will also get some errors (see below)
ImagePNG($dst);
?>
These are the warning lines I get when I comment the header('Content... line:
Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\galleri\pix.php on line 5
Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\galleri\pix.php on line 6
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\galleri\pix.php on line 9
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\galleri\pix.php on line 10
Warning: imagepng(): supplied argument is not a valid Image resource in C:\wamp\www\galleri\pix.php on line 13
index.php
<?php
include "pix.php";
$dir = ".";
$dh = opendir($dir);
while(($file = readdir($dh)) != false)
{
if(preg_match("/.png/", $file) or preg_match("/.PNG/", $file))
{
$pix[] = $file;
}
}
closedir($dh);
?>
<html>
<head>
<title></title>
</head>
<body>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<?php
foreach($pix as $key => $value)
echo "<td><img src=\"pix.php?pic=$value \" /></td>";
?>
</tr>
</table>
</body>
</html>
pix.php
<?php
$pic = $_REQUEST['pic'];
$src = ImageCreateFromPNG($pic);
$width = ImageSx($src);
$height = ImageSy($src);
$x = $width/2;
$y = $height/2;
$dst = ImageCreateTrueColor($x,$y);
ImageCopyResampled($dst,$src,0,0,0,0,$x,$y,$width,$height);
header('Content-Type: image/png'); // if I remove this line, the images are showing but I will also get some errors (see below)
ImagePNG($dst);
?>
These are the warning lines I get when I comment the header('Content... line:
Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\galleri\pix.php on line 5
Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\galleri\pix.php on line 6
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\galleri\pix.php on line 9
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\galleri\pix.php on line 10
Warning: imagepng(): supplied argument is not a valid Image resource in C:\wamp\www\galleri\pix.php on line 13