コード例 #1
0
 function image_is()
 {
     $type = split(",", strtolower($GLOBALS['_confing']['web_upload_image']));
     if (!isset($type)) {
         $type = array('image/gif', 'image/jpeg', 'image/png', 'image/jpg', 'image/bmp', 'image/pjpeg');
     } else {
         $type = image_type($type);
     }
     if (!in_array($this->pic['type'], $type)) {
         msg('上传文件格式不正确!请重新上传');
     }
 }
コード例 #2
0
ファイル: imager.php プロジェクト: Kunnapat/chowtime
function image_save($img, $file_name)
{
    $type = image_type($file_name);
    if ($type == "gif") {
        imagegif($img, $file_name);
    } else {
        if ($type == "jpg" || $type == "jpeg" || $type == "pjpeg") {
            imagejpeg($img, $file_name);
        } else {
            if ($type == "png") {
                imagepng($img, $file_name);
            }
        }
    }
}
コード例 #3
0
ファイル: index.php プロジェクト: Kufirc/Gazelle
    img_error('badprotocol');
}
if (!preg_match('/^' . IMAGE_REGEX . '/is', $URL, $Matches)) {
    img_error('invalid');
}
if (isset($_GET['c'])) {
    list($Data, $FileType) = $Cache->get_value('image_cache_' . md5($URL));
    $Cached = true;
}
if (!isset($Data) || !$Data) {
    $Cached = false;
    $Data = @file_get_contents($URL, 0, stream_context_create(array('http' => array('timeout' => 15))));
    if (!$Data || empty($Data)) {
        img_error('timeout');
    }
    $FileType = image_type($Data);
    if ($FileType && function_exists("imagecreatefrom{$FileType}")) {
        $Image = imagecreatefromstring($Data);
        if (invisible($Image)) {
            img_error('invisible');
        }
        if (verysmall($Image)) {
            img_error('small');
        }
    }
    if (isset($_GET['c']) && strlen($Data) < 262144) {
        $Cache->cache_value('image_cache_' . md5($URL), array($Data, $FileType), 3600 * 24 * 7);
    }
}
// Reset avatar, add mod note
function reset_image($UserID, $Type, $AdminComment, $PrivMessage)
コード例 #4
0
ファイル: functions.php プロジェクト: sdgdsffdsfff/json-db
function get_img_data($url)
{
    if (empty($url)) {
        return false;
    }
    $md5 = md5($url);
    $cache_file = __DIR__ . '/cache/' . $md5 . '.img';
    if (file_exists($cache_file)) {
        return file_get_contents($cache_file);
    }
    $res = curl_get_content($url, null, 7, 30);
    if (empty($res)) {
        return false;
    }
    $img_data = 'data:image/' . image_type($url) . ';base64,' . base64_encode($res);
    file_put_contents($cache_file, $img_data);
    return $img_data;
}
コード例 #5
0
function composite_image($origin, $comp, $out_file)
{
    if (file_exists($origin) && file_exists($comp)) {
        $os = image_size($origin);
        $cs = image_size($comp);
        $w = $os[0];
        $h = $os[1];
        $cw = $cs[0];
        $ch = $cs[1];
        $x = ($w - $cw) / 2;
        $y = ($h - $ch) / 2;
        if (extension_loaded('imagick')) {
            $i = new Imagick($origin);
            $c = new Imagick($comp);
            $i->compositeImage($c, Imagick::COMPOSITE_DEFAULT, $x, $y);
            $i->writeImage($out_file);
            return true;
        }
        if (extension_loaded('gd')) {
            $ext = image_type($origin);
            // Reading the origin image
            if ($ext == 'jpg' || $ext == 'jpeg') {
                $im = imagecreatefromjpeg($origin);
            } else {
                $im = imagecreatefrompng($origin);
            }
            $ext = image_type($comp);
            // Reading the composite image
            if ($ext == 'jpg' || $ext == 'jpeg') {
                $overlay = imagecreatefromjpeg($comp);
            } else {
                $overlay = imagecreatefrompng($comp);
            }
            imagecopymerge($im, $overlay, $x, $y, 0, 0, $cw, $ch, 100);
            $ext = image_type($out_file);
            if ($ext == 'jpg' || $ext == 'jpeg') {
                imagejpeg($im, $out_file);
            } else {
                imagepng($im, $out_file);
            }
            imagedestroy($overlay);
            imagedestroy($im);
        }
    }
    return false;
}