PDA

View Full Version : another sig php question from sabe


sabret00the
10-09-2003, 03:00 PM
this script is meant to give me a random image script usable on forums such as this
<?php
// usage: http://www.ebslive.com/sig.png/
// read folder
$folder=opendir(".");
while ($file = readdir($folder))
$names[count($names)] = $file;
closedir($folder);
// sort file names in array
sort($names);
// remove any non-images from array
$tempvar=0;
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"||$ext==".gif"||$ext==".jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
// random
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
// random image from array
$woot=$names1[$rand_keys[0]];
header("Cache-control: max-age=31536000");
header("Expires: " . gmdate("D, d M Y H:i:s",time()+31536000) . "GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s",time()) . "GMT");
header("Content-disposition: inline; filename=sig.jpg");
header('Content-type: image/jpeg');
$im = imagecreatefromjpeg("$woot");
imagealphablending($im, true);
imagejpeg($im, "", 80);
?>

however it's not quite working like that, in alot of cases, i prefer to use png's either due to the size, loading speed or superior ability when it comes to transparency, but when i try and use this script i seem to get this error quite a bit

<br />
<b>Warning</b>: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in <b>/home/ebslive/public_html/sig.png/index.php</b> on line <b>34</b><br />
<br />
<b>Warning</b>: imagecreatefromjpeg(): 'ebs-banner.png' is not a valid JPEG file in <b>/home/ebslive/public_html/sig.png/index.php</b> on line <b>34</b><br />
<br />
<b>Warning</b>: imagealphablending(): supplied argument is not a valid Image resource in <b>/home/ebslive/public_html/sig.png/index.php</b> on line <b>35</b><br />
<br />
<b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>/home/ebslive/public_html/sig.png/index.php</b> on line <b>36</b><br />
this or something very quite similar, how can i fix this?

sabret00the
10-09-2003, 11:34 PM
*bump*

mr e
10-10-2003, 12:04 AM
You could always just name them image1.png, image2.png etc, then just randomize a number and attach it to "image" then echo that back out, not nearly as cool, but it works.

Other than that, I noticed that if you have the substring of -4 to check for file extensions then you'll never get a .jpeg, since it's 5 chars long.

sabret00the
10-10-2003, 10:40 AM
i got the second bit, but the second bit went right over my head, could you say that in lamen turms please

MindTrix
10-10-2003, 02:54 PM
i got the second bit, but the second bit went right over my head, could you say that in lamen turms please


Im useless at php but from what i can guess/gather he means this bit of code


$ext=strtolower(substr($names[$i],-4));

Which im guessing because you have -4 at the end wont let it show .jpeg files because .jpeg= 5 letters long not 4 or less.


Sorry if im wrong and messed everything up here

sabret00the
10-10-2003, 06:03 PM
heh, that's the only bit i got, thanks for trying to help tho'