Jump to content


Photo

imagejpeg() - nothing seams to work


  • Please log in to reply
2 replies to this topic

#1 benjrox

benjrox
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationSydney, Australia

Posted 26 June 2006 - 09:11 PM

Hi,
I'm trying to generate a random image using this code:
<?php

$dirname = "/home/www/benjrox.net/subsites/myspace/images/bg/resized/";

if ($handle = opendir($dirname)) {
    while (false !== ($dir = readdir($handle))) {
        if ($dir != "." && $dir != "..") {
            $bgcount++;
              }
    }
    closedir($handle);
} else {
    die("Could not get a directory list");
}

$randimg = rand(1,$bgcount);

$img = "/home/www/benjrox.net/subsites/myspace/images/bg/resized/bg". $randimg .".jpg";

header("Content-type: image/jpeg");

imagejpeg($img,null,100);
imagedestroy($img);

?>
Except I keep getting this:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<br />
<b>Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/www/benjrox.net/subsites/myspace/images/bg/img.php on line 22

<br />
<b>Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/www/benjrox.net/subsites/myspace/images/bg/img.php on line 23
[/quote]
The images exist, it just doesn't work [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]

Thanks,
Benj



#2 timmah22

timmah22
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 June 2006 - 11:36 PM

did you create the image resource?


$img = @imagecreate(100, 50)

[!--quoteo(post=388215:date=Jun 26 2006, 04:11 PM:name=Benj RooZ)--][div class=\'quotetop\']QUOTE(Benj RooZ @ Jun 26 2006, 04:11 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi,
I'm trying to generate a random image using this code:
<?php

$dirname = "/home/www/benjrox.net/subsites/myspace/images/bg/resized/";

if ($handle = opendir($dirname)) {
    while (false !== ($dir = readdir($handle))) {
        if ($dir != "." && $dir != "..") {
            $bgcount++;
              }
    }
    closedir($handle);
} else {
    die("Could not get a directory list");
}

$randimg = rand(1,$bgcount);

$img = "/home/www/benjrox.net/subsites/myspace/images/bg/resized/bg". $randimg .".jpg";

header("Content-type: image/jpeg");

imagejpeg($img,null,100);
imagedestroy($img);

?>
Except I keep getting this:

The images exist, it just doesn't work [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]

Thanks,
Benj
[/quote]

timmah uses [a href="http://wakeupcalls.net" target="_blank"]wake up calls dot net[/a]

#3 benjrox

benjrox
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationSydney, Australia

Posted 27 June 2006 - 12:11 AM

Ahh, thanks, haha I assumed my original $img was the resource. I only started to learn about the image command yesterday :P
Thanks :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users