...

View Full Version : problem with puzzle, help!



erickkz
05-08-2006, 07:07 PM
Hi everyone!

I build a dynamic puzzle, but I have a problem, this is the process of my program:

You can upload or select one image, then you choose the number of rows and columns, then, when you press start the program slice the image in the parts what I want and you can scramble, those pieces are saved in a directory with the name of the image(I can see the directory and the pieces match!) and then, show them in the page. The problem is when I slice the same image in different rows and columns, the old pieces and the new pieces seems to be mixed ONLY IN THE PAGE, but if I check the directory the pieces ARE CORRECT!.

Then If I press REFRESH in (ie) or firefox this message appears:
“The page cannot be refreshed without resending the information. Click retry to send the information again, or click cancel to return to the page that you were trying to view”.

If I press retry the problem is fixed!. This is the view:


The first time I slice a image
http://img173.imageshack.us/my.php?image=p12wf.jpg

If I change the rows and columns
http://img516.imageshack.us/my.php?image=p24tq.jpg

If I press retry
http://img198.imageshack.us/my.php?image=p36uc.jpg

I don't want to press "refresh" every time the sliced image is wrong(the user don’t know it). This is some of my code:


if($_POST["inicia_puzzle"]){
$image=$main_file; $global_counter=0;
$pos1=strrpos($main_file,".");
$main_file=substr($main_file, 0, $pos1);
if(is_dir("fotospuzzle/$mimochila_login/$main_file")){

$dirt = "fotospuzzle/$mimochila_login/$main_file";
$dht = opendir($dirt);

while (false !== ($nombre_archivot = readdir($dht))) {
$pieces[] = $nombre_archivot;
}
closedir($dht);

$counterpieces=2; $totalpieces=0;
while($pieces[$counterpieces]!=NULL){
unlink("fotospuzzle/$mimochila_login/$main_file/".$pieces[$counterpieces]);
$counterpieces++; $totalpieces++;
}

rmdir("fotospuzzle/$mimochila_login/$main_file");
mkdir("fotospuzzle/$mimochila_login/$main_file", 0777);
}
else{
if(!is_dir("fotospuzzle/$mimochila_login"))
mkdir("fotospuzzle/$mimochila_login", 0777);
mkdir("fotospuzzle/$mimochila_login/$main_file", 0777);
}

$image="galeria/Rompecabezas/".$image;
$v_vwidth=$value_rows;
$v_vheigh=$value_colums;

list($vwidth,$hheight, $tipo, $atr) = getimagesize($image);
if(($vwidth>550)||($hheight>550)){
if($vwidth>$hheight) $difference=$vwidth-550;
elseif($hheight>$vwidth) $difference=$hheight-550;
elseif($hheight==$vwidth) $difference=$hheight-550;

$new_vwidth=$vwidth-$difference;
$new_vheigh=$hheight-$difference+50;
$img = imagecreatetruecolor($new_vwidth,$new_vheigh);
$map_img = imagecreatefromjpeg($image);
imagecopyresized($img,$map_img,0,0,0,0,$new_vwidth,$new_vheigh, $vwidth, $hheight);
imagejpeg($img,$image,85);
imagedestroy($img);
imagedestroy($map_img);
$vwidth=$new_vwidth;
$hheight=$new_vheigh;
}

$cont_vwidth=round($cont_vwidth=$vwidth/$v_vwidth);
$cont_vheigh=round($cont_vheigh=$hheight/$v_vheigh);

$internal_counter=0;
$stop_flag=$v_vwidth*$v_vheigh;
$limite=$stop_flag; $limite--;

for($i=0; $i<$hheight; $i=$i+$cont_vheigh){
if($internal_counter==$stop_flag)
break;
for($j=1; $j<$vwidth; $j=$j+$cont_vwidth){
if($internal_counter==$stop_flag)
break;
if(!(($j+3)>$vwidth)){
$img = imagecreatetruecolor($cont_vwidth,$cont_vheigh);
$org_img = @imagecreatefromjpeg($image);
$ims = getimagesize($image);
imagecopy($img,$org_img, 0, 0, $j, $i, $vwidth, $hheight);
imagejpeg($img,"fotospuzzle/$mimochila_login/$main_file/"."p".$internal_counter.".jpg",85);
imagedestroy($img);
imagedestroy($org_img);
$internal_counter++;
}
}
}
list($vwidth2,$hheight2, $tipo2, $atr2) = getimagesize("fotospuzzle/$mimochila_login/$main_file/p0.jpg");
for($f=0; $f<=$limite; $f++)
$slices[$f]="p".$f.".jpg";
$aux=1;
for($z=0; $z<=$limite; $z++){
if($z==0)
$image_pieces=$image_pieces."<table border='1' cellpadding='0' cellspacing='0' ><tr>";
if(fmod($aux,$v_vwidth)==0)
$image_pieces=$image_pieces."<td><img name='c.$z' src='fotospuzzle/$mimochila_login/$main_file/$slices[$z]' width='$vwidth2' height='$hheight2' border='0'></td></tr><tr>";
else
$image_pieces=$image_pieces."<td><img name='c.$z' src='fotospuzzle/$mimochila_login/$main_file/$slices[$z]' width='$vwidth2' height='$hheight2' border='0'></td>";
if($z==$limite)
$image_pieces=$image_pieces."</table>";
$aux++;
flush();
}

$active_button="<input type='button' name='Scramble' value='Scramble' onClick='accion_imagen(this.form)' class='estiloboton'>";

}

Basically this code, copy a part of a image and create a new one with that part and then I print it in my page
Any suggestion would be appreciated

P.D. Sorry for the size of this thread

cdwhalley.com
05-08-2006, 11:15 PM
Well, I can't suggest what's wrong. I can suggest that you put more blank lines and comments in your code.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum