benjrox Posted June 26, 2006 Share Posted June 26, 2006 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 More sharing options...
timmah22 Posted June 26, 2006 Share Posted June 26, 2006 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] Link to comment https://forums.phpfreaks.com/topic/12961-imagejpeg-nothing-seams-to-work/#findComment-49859 Share on other sites More sharing options...
benjrox Posted June 27, 2006 Author Share Posted June 27, 2006 Ahh, thanks, haha I assumed my original $img was the resource. I only started to learn about the image command yesterday :pThanks :) Link to comment https://forums.phpfreaks.com/topic/12961-imagejpeg-nothing-seams-to-work/#findComment-49878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.