$b) { $a = $a - $b; } else { $b = $b - $a; } $cmmdc = $a; } if(($cmmdc <= 1) || ($cmmdc == ca) || ($cmmdc == cb)) return 10; return $cmmdc; } //load the JPG image $im = imagecreatefromjpeg("guitars-new.jpg"); //get the image dimensions $size = getimagesize("guitars-new.jpg"); $L=$size[0]; $H=$size[1]; //get the size of puzzle piece $step=CMMDC($L,$H); //determine the number of pieces $Lv=floor((float)$L/(float)$step); $Ho=floor((float)$H/(float)$step); //obtain the puzzle by mixing the pieces $permut = 10*$Lv*$Ho; for($i = 0; $i < $permut; $i++) { $fromx=rand(0,$Lv-1); $fromy=rand(0,$Ho-1); $tox=rand(0,$Lv-1); $toy=rand(0,$Ho-1); //create a new image $temp = imagecreatetruecolor($step, $step); //copy image into $temp imagecopy($temp, $im, 0, 0, $step*$fromx, $step*$fromy, $step, $step); //move in place the generated piece imagecopy($im, $im, $step*$fromx, $step*$fromy, $step*$tox, $step*$toy, $step, $step); //restore the empty piece with the $temp imagecopy($im, $temp, $step*$tox, $step*$toy, 0, 0, $step, $step); } //display the puzzle header("Content-type: image/jpeg"); imagejpeg($im); ?>