rendered paste body $picture_x = imagesx($image_handler); $picture_y = imagesy($image_handler); //$square_pieces = $this->difficulty * 3; $square_pieces = 60; // 60 x 60 pieces. $count = 0; # Time to generate squares. ob_start(); # lets catch all buffer. for($i = $square_pieces; $i < $picture_x; $i = $squares_pieces + $i) { if($i > $picture_x) { # if $drawing_x = $i - $picture_x; } else { $drawing_x = $i; } for($j = $square_pieces; $j < $picture_y; $j = $square_pieces + $j) { if($j > $picture_y) { $drawing_y = $j - $picture_y; } else { $drawing_y = $j; } $temp_pic = imagecreatetruecolor($drawing_x, $drawing_y); $drawing_x_start = $drawing_x - $square_pieces; $drawing_y_start = $drawing_y - $square_pieces; imagecopy($temp_pic, $image_handler, 0, 0, $drawing_x_start, $drawing_y_start, $drawing_x, $drawing_y); imagejpeg($temp_pic,"puz/".$count.".jpg"); imagedestroy($temp_pic); echo("<img src='puz/".$count.".jpg'>"); $count++; } echo("<br />"); } $squares = ob_get_contents(); ob_end_clean();