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?
<?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?