$destimg=ImageCreate($new_width,$new_height) or die("Problem In Creating image");
$srcimg=ImageCreateFromJPEG($im) or die("Problem In opening Source Image");
imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing");
ImageJPEG($destimg,$im) or die("Problem In saving");
imagedestroy($im);
} else {
$errors[] = $dir.' is not a directory';
return false;
}
}
$dir = "./img/Avatar/";
getRandomImage($dir);
?>
In the images/avatar folder there are 3 images:
theonetokill-avatar.jpg
OneToKills2.jpg
admin-avatar.jpg
Basically it displays randome images that have been resized to 90x90 px
octopi
Posted: Sun Nov 02, 2003 6:40 pm Post subject: (No subject)
Does images[] have any values.....if it doesn't then the program would just goto the Dir specified...and might try to add a .jpg extention to it. That would explain your error in the logs.
Amailer
Posted: Sun Nov 02, 2003 6:49 pm Post subject: (No subject)
It does, it works prefectly with out creating an image, ill show you.
code:
<?
function getRandomImage($dir,$type="random")
{
global $errors,$seed;
if (is_dir($dir)) {
$fd = opendir($dir);
$images = array();
while (($part = @readdir($fd)) == true) {
if ( eregi("(gif|jpg|png|jpeg|bmp)$",$part) ) {
$images[] = $part;
}
}
// adding this in case you want to return the image array
if ($type == 'all') return $images;
<br />
<b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>C:\Program Files\Apache Group\Apache2\htdocs\pictures\new_image.php</b> on line <b>43</b><br />
Amailer
Posted: Sun Nov 02, 2003 7:00 pm Post subject: (No subject)
Look...
code:
[Sun Nov 02 13:49:56 2003] [notice] Parent: Created child process 712
[Sun Nov 02 13:49:57 2003] [notice] Child 712: Child process is running
[Sun Nov 02 13:49:57 2003] [notice] Child 712: Acquired the start mutex.
[Sun Nov 02 13:49:57 2003] [notice] Child 712: Starting 250 worker threads.
[Sun Nov 02 17:18:12 2003] [error] [client 66.185.85.69] File does not exist: C:/Program Files/Apache Group/Apache2/htdocs/Avatar.jpg, referer: http://www.compsci.ca/v2/viewtopic.php?t=2155&highlight=
[Sun Nov 02 17:31:16 2003] [error] [client 205.211.56.77] File does not exist: C:/Program Files/Apache Group/Apache2/htdocs/Avatar.jpg, referer: http://www.compsci.ca/v2/viewtopic.php?t=2155
[Sun Nov 02 17:39:32 2003] [error] [client 64.231.193.26] File does not exist: C:/Program Files/Apache Group/Apache2/htdocs/Avatar.jpg, referer: http://www.compsci.ca/v2/viewtopic.php?t=2155
[Sun Nov 02 17:40:26 2003] [error] [client 192.168.1.1] File does not exist: C:/Program Files/Apache Group/Apache2/htdocs/Avatar.jpg, referer: http://www.compsci.ca/v2/viewtopic.php?t=2155
[Sun Nov 02 17:56:48 2003] [error] [client 192.168.1.1] Not a JPEG file: starts with 0x47 0x49
[Sun Nov 02 17:56:50 2003] [error] [client 192.168.1.1] Not a JPEG file: starts with 0x47 0x49
[Sun Nov 02 17:56:51 2003] [error] [client 192.168.1.1] Not a JPEG file: starts with 0xd0 0xcf
[Sun Nov 02 17:56:52 2003] [error] [client 192.168.1.1] Not a JPEG file: starts with 0x47 0x49
octopi
Posted: Sun Nov 02, 2003 7:28 pm Post subject: (No subject)
Didn't you say $im was just a path name, and not an image resource?
Do you understand what imagedestory() does?
Amailer
Posted: Sun Nov 02, 2003 7:53 pm Post subject: (No subject)
the $im has the the image (eg. ./img/avatar/image.jpg)
Either way, with and without the imagedestory() it does not work :SS:S
octopi
Posted: Sun Nov 02, 2003 10:57 pm Post subject: (No subject)
Well...you were using imagedestory wrong...
Look at your error's its telling you the problem...your trying to open a Jpeg image, that isn't a jpeg image.
Theres nothing else I can do....you should check the paths, and stuff, and see exactly where its looking for the file, before you try and show the image.