Anim9or Posted July 9, 2009 Share Posted July 9, 2009 I hate to ask for help twice so close to eachother but... I'm working on a photo mosaic website that makes boxes, finds their average color and colors in each space it's boxes average color(eventually it will take picture with this average color and cover the boxes with them). However, I have been having troube. I'm trying to store all the color information using a txt document whihc lists each box's red, green and blue. Below is the code, however, I can not get fwrite to work, the variables are fine but when I check the text file I left for it, it will be empty. Can someone tell me why the fwrite isn't working? Everything else is. for ($height=0;$height<($numberofboxeshigh*$boxsize);$height+=$boxsize) { for ($width=0;$width<($numberofboxeswide*$boxsize);$width+=$boxsize) { for ($x=$width;$x<($width+$boxsize);$x++) { for ($y=$height;$y<($height+$boxsize);$y++) { $rgb = imagecolorat($my_img, $x, $y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF; $totalr+=$r; $totalg+=$g; $totalb+=$b; } } $averager=$totalr/($boxsize*$boxsize); $averageg=$totalg/($boxsize*$boxsize); $averageb=$totalb/($boxsize*$boxsize); $boxred[$width][$height]=$averager; $boxgreen[$width][$height]=$averageg; $boxblue[$width][$height]=$averageb; $boxcolor=imagecolorallocate( $my_img, $averager, $averageg, $averageb); for ($x=$width;$x<($width+$boxsize);$x++) { for ($y=$height;$y<($height+$boxsize);$y++) { imagesetpixel($my_img, $x,$y, $boxcolor); } } $totalr=0; $totalg=0; $totalb=0; } } $text_colour = imagecolorallocate( $my_img, 255, 255, 0 ); $line_colour = imagecolorallocate( $my_img, 128, 255, 0 ); imagestring( $my_img, 4, 30, 25, $boxred[0][0]."x".$numberofboxeshigh."x".$averageb, $text_colour ); imagesetthickness ( $my_img, 5 ); imageline( $my_img, 30, 45, 165, 45, $line_colour ); $file = fopen("images/Pixelize Pictures/Goldie.txt","a"); for ($x=0;$x<$numberofboxeswide;$x+=$boxsize) { for ($y=0;$y<$numberofboxeshigh;$y+=$boxsize) { fwrite($file, $boxred[0][0]); } } fclose($file); Quote Link to comment https://forums.phpfreaks.com/topic/165367-solved-fwrite-issue/ Share on other sites More sharing options...
WolfRage Posted July 9, 2009 Share Posted July 9, 2009 Place this prior to the Fwrite and lets see the information to make sure it is there. Also make sure you have error reporting turned on and be sure to check your error logs. <?php echo $boxred[0][0].'<br />'; print_r($boxred); echo '<br />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/165367-solved-fwrite-issue/#findComment-872118 Share on other sites More sharing options...
Anim9or Posted July 9, 2009 Author Share Posted July 9, 2009 The error reporting fixed it, turns out I was directing it to the folder "Pixelize Pictures" when the folder was called "Pixelized Pictures". Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/165367-solved-fwrite-issue/#findComment-872134 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.