コード例 #1
0
ファイル: function.php プロジェクト: TheDenisNovikov/teacher
function _make_image($tmp_img, $image_type, $extention, $opt)
{
    $resize = $opt['resize'];
    $opt_list = $opt['list'];
    if (!$opt_list) {
        $opt_list = array($opt);
    }
    $ret = array();
    foreach ($opt_list as $opt_) {
        if ($resize) {
            $content = image_file_resize($tmp_img, $image_type, $opt_['crop'], $opt_['width'], $opt_['height']);
        } else {
            $content = file_get_contents($tmp_img);
        }
        $file_name = uniqid() . '.' . $extention;
        $ret[] = write_upload($content, $file_name);
    }
    return count($ret) === 1 ? reset($ret) : $ret;
}
コード例 #2
0
ファイル: function.php プロジェクト: name3/cheng
/**
 * main function
 * @param type $image like $_FILE['xx']
 * @param type $opt resize crop width height
 * @return string url of the final img
 * @throws Exception
 */
function make_image($image, $opt = array())
{
    // deault option
    $opt = array_merge(array('crop' => 0, 'resize' => 0, 'width' => 50, 'height' => 50, 'list' => null), $opt);
    $arr = explode('/', $image['type']);
    $file_type = reset($arr);
    $image_type = end($arr);
    if ($file_type == 'image') {
        $extention = file_ext($image['name']);
        $tmp_img = $image['tmp_name'];
        $resize = $opt['resize'];
        $ret_list = $opt['list'];
        if ($ret_list) {
            $ret = array();
            foreach ($ret_list as $opt_) {
                if ($resize) {
                    image_file_resize($tmp_img, $image_type, $opt_['crop'], $opt_['width'], $opt_['height']);
                }
                $content = file_get_contents($tmp_img);
                $file_name = uniqid() . '.' . $extention;
                $ret[] = write_upload($content, $file_name);
            }
            return $ret;
        } else {
            if ($resize) {
                image_file_resize($tmp_img, $image_type, $opt['crop'], $opt['width'], $opt['height']);
            }
            $content = file_get_contents($tmp_img);
            $file_name = uniqid() . '.' . $extention;
            return write_upload($content, $file_name);
        }
    } else {
        // maybe throw??
        return '';
    }
}