function divideImage($block, $file, $puzzle_name) { global $user; //print "USER: $user
"; // first insert into DB $sql = "INSERT INTO puzzles (user_id, image_id, blocks, name, time) VALUES ('$user', '1', '$block', '$puzzle_name', NOW())"; $query = mysql_query($sql) or die(mysql_error()); $puzzle_id = mysql_insert_id(); $folderName = "../../images/$user/$puzzle_id"; createfolder($folderName); // now convert the original image to a max size...... $new_file = "../../images/$user/$puzzle_id/original.jpg"; $image = new Gregphoto_Image($file); $image->setMaxHeight(453); $image->setMaxWidth(604); $image->setJpegQuality(80); $image->resize(Gregphoto_Image::BEST_FIT); $image->saveThumbnail($new_file); list($width,$height) = getimagesize($new_file); $blockSizeWidth = floor($width / $block); $blockSizeHeight = floor($height / $block); $blockSizeWidth_sm = floor(60 / $block); $blockSizeHeight_sm = floor(60 / $block); $offset_x = 0; $offset_y = 0; $randomIntArray = array(); $imageResources = array(); for ($i = 0; $i < $block; $i++) { for ($j = 0; $j < $block; $j++) { $offset_y = $blockSizeHeight * $i; $offset_x = $blockSizeWidth * $j; $randomInt = rand(50000, 10000000); while (in_array($randomInt, $randomIntArray)) { $randomInt = rand(50000, 10000000); } $randomIntArray[] = $randomInt; //$fileName = "img/$user".$i."_".$j.".jpg"; $fileName = "$folderName/".$randomInt.".jpg"; $fileNameSm = "$folderName/".$randomInt."_sm.jpg"; $image_resource = makeImage($new_file, $fileName, $blockSizeWidth, $blockSizeHeight, $blockSizeWidth, $blockSizeHeight, $offset_x, $offset_y); chmod( $fileName , 0776); //$imageResources[] = $fileName; $image = new Gregphoto_Image($fileName); $image->setMaxHeight($blockSizeHeight_sm); $image->setMaxWidth($blockSizeWidth_sm); $image->setJpegQuality(70); $image->resize(Gregphoto_Image::EXACT); $image->saveThumbnail($fileNameSm); chmod($fileNameSm, 0776); //makeImage($fileName, $fileNameSm, $blockSizeWidth_sm, $blockSizeHeight_sm, $blockSizeWidth_sm, $blockSizeHeight_sm, 0, 0); } } $thumbnail_filename = "$folderName/thumb.jpg"; $image = new Gregphoto_Image($new_file); $image->setMaxHeight(60); $image->setMaxWidth(60); $image->setJpegQuality(80); $image->resize(Gregphoto_Image::BEST_FIT); $image->saveThumbnail($thumbnail_filename); $thumbnail_filename = "$folderName/thumb_bg.jpg"; $image = new Gregphoto_Image($new_file); $image->setMaxHeight(140); $image->setMaxWidth(140); $image->setJpegQuality(80); $image->resize(Gregphoto_Image::BEST_FIT); $image->saveThumbnail($thumbnail_filename); //makeMergedImage($imageResources, $block, $thumbnail_filename, $blockSizeWidth, $blockSizeHeight); $puzzle_string = serialize($randomIntArray); $sql = "UPDATE puzzles SET puzzle_string='$puzzle_string', width='$width', height='$height' WHERE id='$puzzle_id'"; $query = mysql_query($sql) or die(mysql_error()); $points = 5; $sql = "UPDATE users_basic SET points=points+5 WHERE user_id='$user'"; $query = mysql_query($sql) or die(mysql_error()); $date = strtotime('today'); $sql = "SELECT COUNT(id) FROM puzzles WHERE user_id='$user' AND UNIX_TIMESTAMP(time) > $date"; $query = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($query); $count = (int)$row[0]; if ($count == 5) { $sql = "UPDATE users_basic SET points=points+20 WHERE user_id='$user'"; $query = mysql_query($sql) or die(mysql_error()); $points += 20; } $sql = "INSERT INTO actions (user_id, type, points, rel_id, time) VALUES ('$user', 1, '$points', '$puzzle_id', NOW())"; $query = mysql_query($sql) or die(mysql_error()); return $puzzle_id; } function makeImage($source_file, $filename, $src_width, $src_height, $dst_width, $dst_height, $src_x, $src_y ) { $quality = 100; // create a temp image with the new size that was created $thumbnail = imagecreatetruecolor($src_width,$src_height); //$thumbnail = imagecreate($src_width,$src_height); $img_source = imagecreatefromjpeg($source_file); imagecopyresampled($thumbnail, $img_source,0, 0, $src_x, $src_y, $src_width, $src_height, $dst_width, $dst_height); imagejpeg( $thumbnail, $filename, $quality ); imagedestroy($img_source); imagedestroy($thumbnail); return $thumbnail; }