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
https://forums.phpfreaks.com/topic/165367-solved-fwrite-issue/
Share on other sites

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.