Jump to content

imagejpeg() - nothing seams to work


benjrox

Recommended Posts

Hi,
I'm trying to generate a random image using this code:
[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);

?>[/code]
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 [b]/home/www/benjrox.net/subsites/myspace/images/bg/img.php[/b] on line [b]22[/b]

<br />
<b>Warning: imagedestroy(): supplied argument is not a valid Image resource in [b]/home/www/benjrox.net/subsites/myspace/images/bg/img.php[/b] on line [b]23[/b]
[/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

Link to comment
https://forums.phpfreaks.com/topic/12961-imagejpeg-nothing-seams-to-work/
Share on other sites

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) [snapback]388215[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi,
I'm trying to generate a random image using this code:
[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);

?>[/code]
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.