Jump to content

[SOLVED] fwrite issue


Anim9or

Recommended Posts

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 >> 8) & 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);

Link to comment
Share on other sites

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 />';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.