static function avatar($picture, $size_data = array(200, 100, 75, 50, 32), $save_dir = '') { $image = img::open($picture); $true_size = img::info($image, 'width'); $save_name = basename($picture, pathinfo($picture, PATHINFO_EXTENSION)); if ($true_size >= $size_data[0]) { $arr = null; foreach ($size_data as $target_size) { $target_img = img::create($target_size, $target_size, 'ffffff', true); $arr = array(0, 0, 0, 0, $target_size, $target_size, $true_size, $true_size); $copy_result = img::copy($target_img, $image, 5, $arr); if ($copy_result) { img::save($target_img, $save_name . '.gif', $save_dir . $target_size . '/'); } } return true; } }
static function avatar($img, $size_data = array(100, 75, 50, 32), $save_dir = '') { $res = img::open($img); $true_size = img::info($res, 'width'); $save_name = basename($img); $save_name = substr($save_name, 0, strpos($save_name, '.')); if ($true_size >= $size_data[0]) { $arr = null; foreach ($size_data as $target_size) { $target_img = img::create($target_size, $target_size, 'ffffff', true); $arr = array(0, 0, 0, 0, $target_size, $target_size, $true_size, $true_size); $copy_res = img::copy($target_img, $res, 5, $arr); if ($copy_res) { img::save($target_img, $save_name . '_' . $target_size . '.gif', $save_dir); } } return true; } }