function getPreferedSize($pref_w, $pref_h, $current_w, $current_h, $recursion = false) { if (!$recursion) { $new_size = resize($pref_w, $current_w, $current_h); if ($pref_w <= $new_size[0] && $pref_h <= $new_size[1]) { return $new_size; } return getPreferedSize($pref_w, $pref_h, $new_size[0], $new_size[1], true); } else { $pct = 1 / $current_w; $new_w = $current_w + ceil($pct * $current_w); $new_h = $current_h + ceil($pct * $current_h); if ($pref_w <= $new_w && $pref_h <= $new_h) { return array($new_w, $new_h); } else { return getPreferedSize($pref_w, $pref_h, $new_w, $new_h, true); } } return array($current_w, $current_h); }
} // Create Defined Thumbnail 2 if ($thumbnail2 = $album['Thumbnail2Size']) { $thumbnail2 = explode("x", $thumbnail2); if ($thumbnail2[0] > 0 && $thumbnail2[1] > 0) { $th2_pref_size = getPreferedSize($thumbnail2[0], $thumbnail2[1], $imagesize[0], $imagesize[1]); $thumbnail2_create = new ImageTools($upload_file_path); $thumbnail2_create->resizeNewByWidth($thumbnail2[0], $thumbnail2[1], $th2_pref_size[0], "#FFF"); $thumbnail2_create->save($album_path, "th2_{$new_name}", 100, true); } } // Create Defined Thumbnail 3 if ($thumbnail3 = $album['Thumbnail3Size']) { $thumbnail3 = explode("x", $thumbnail3); if ($thumbnail3[0] > 0 && $thumbnail3[1] > 0) { $th3_pref_size = getPreferedSize($thumbnail3[0], $thumbnail3[1], $imagesize[0], $imagesize[1]); $thumbnail3_create = new ImageTools($upload_file_path); $thumbnail3_create->resizeNewByWidth($thumbnail3[0], $thumbnail3[1], $th3_pref_size[0], "#FFF"); $thumbnail3_create->save($album_path, "th3_{$new_name}", 100, true); } } addImage($album_id, $upload_file_path); $last_id = mysql_insert_id(); $image = getImage($last_id); $image['errors'] = false; $image['thumbnailUrl'] = dirname($image['ImagePath']) . '/th_' . basename($image['ImagePath']); $json = json_encode($image); echo $json; } else { echo json_encode(array("errors" => "AlbumNotExists")); }