예제 #1
0
function klResizeImage($img, $imgtype, $name, $isIcon, $kl_img_att_max_w, $kl_img_att_max_h)
{
    $max_w = $isIcon ? ICON_MAX_W : $kl_img_att_max_w;
    $max_h = $isIcon ? ICON_MAX_H : $kl_img_att_max_h;
    $size = chImageSize($img, $max_w, $max_h);
    $size_bak = @getimagesize($img);
    $imgtype = $size_bak['mime'];
    $newwidth = $size['w'];
    $newheight = $size['h'];
    $w = $size['rc_w'];
    $h = $size['rc_h'];
    if ($w <= $max_w && $h <= $max_h) {
        return false;
    }
    if (($imgtype == "image/pjpeg" || $imgtype == "image/jpeg") && function_exists("imagecreatefromjpeg")) {
        $img = imagecreatefromjpeg($img);
    }
    if (($imgtype == "image/x-png" || $imgtype == "image/png") && function_exists("imagecreatefrompng")) {
        $img = imagecreatefrompng($img);
    }
    if ($imgtype == "image/gif" && function_exists("imagecreatefromgif")) {
        $img = imagecreatefromgif($img);
    }
    if (!isset($img)) {
        return false;
    }
    if (function_exists("imagecopyresampled")) {
        $newim = imagecreatetruecolor($newwidth, $newheight);
        imagecopyresampled($newim, $img, 0, 0, 0, 0, $newwidth, $newheight, $w, $h);
    } else {
        $newim = imagecreate($newwidth, $newheight);
        imagecopyresized($newim, $img, 0, 0, 0, 0, $newwidth, $newheight, $w, $h);
    }
    if (($imgtype == "image/pjpeg" || $imgtype == "image/jpeg") && !imagejpeg($newim, $name)) {
        return false;
    }
    if (($imgtype == "image/x-png" || $imgtype == "image/png") && !imagepng($newim, $name)) {
        return false;
    }
    if ($imgtype == "image/gif" && !imagegif($newim, $name)) {
        return false;
    }
    ImageDestroy($newim);
    return true;
}
예제 #2
0
파일: xmlrpc.php 프로젝트: szshenjian/JIEWU
function mw_newMediaObject($args)
{
    global $options_cache;
    escape($args[1]);
    escape($args[2]);
    $username = $args[1];
    $password = $args[2];
    $user = login($username, $password);
    $file = $args[3];
    if (!preg_match('/([^\\/\\:\\*\\?<>\\|]+\\.\\w{2,6})|(\\{2}[^\\/\\:\\*\\?<>\\|]+\\.\\w{2,6})/', $file['name'], $matches)) {
        error_message(500, '文件错误');
    }
    $filename = $matches[0];
    $bits = $file['bits'];
    if (!empty($data["overwrite"]) && $data["overwrite"] == true) {
    }
    $att_type = Option::getAttType();
    if (empty($filename)) {
        error_message(500, '文件名错误');
    }
    $extension = strtolower(substr(strrchr($filename, "."), 1));
    // 文件类型检测
    if (!in_array($extension, $att_type)) {
        error_message(500, '文件类型错误');
    }
    $uppath_root = substr(Option::UPLOADFILE_PATH, 1);
    $uppath = $uppath_root . gmdate('Ym') . '/';
    $fname = md5($filename) . gmdate('YmdHis') . '.' . $extension;
    $attachpath = $uppath . $fname;
    if (!is_dir($uppath_root)) {
        umask(0);
        $ret = @mkdir($uppath_root, 0777);
        if ($ret === false) {
            error_message(500, '创建文件上传目录失败');
        }
    }
    if (!is_dir($uppath)) {
        umask(0);
        $ret = @mkdir($uppath, 0777);
        if ($ret === false) {
            error_message(500, '上传失败。文件上传目录(content/uploadfile)不可写');
        }
    }
    $fp = @fopen($attachpath, 'wb');
    if (!$fp) {
        error_message(500, '文件无法写入');
    }
    fwrite($fp, $bits);
    fclose($fp);
    doAction('xmlrpc_attach_upload', $attachpath);
    // resizeImage
    $imtype = array('jpg', 'png', 'jpeg');
    $thum = $uppath . 'thum-' . $fname;
    $thum_created = true;
    if (Option::get('isthumbnail') && in_array($extension, $imtype) && function_exists('ImageCreate')) {
        $max_w = Option::get('att_imgmaxw');
        $max_h = Option::get('att_imgmaxh');
        $size = chImageSize($attachpath, $max_w, $max_h);
        $newwidth = $size['w'];
        $newheight = $size['h'];
        $w = $size['rc_w'];
        $h = $size['rc_h'];
        if ($w <= $max_w && $h <= $max_h) {
            $thum_created = false;
        }
        if ($thum_created && ($extension == 'jpeg' || $extension == 'jpg')) {
            if (function_exists('imagecreatefromjpeg')) {
                $img = imagecreatefromjpeg($attachpath);
            } else {
                $thum_created = false;
            }
        } elseif ($thum_created && $extension == 'png') {
            if (function_exists('imagecreatefrompng')) {
                $img = imagecreatefrompng($attachpath);
            } else {
                $thum_created = false;
            }
        }
        if ($thum_created && function_exists('imagecopyresampled')) {
            $newim = imagecreatetruecolor($newwidth, $newheight);
            imagecopyresampled($newim, $img, 0, 0, 0, 0, $newwidth, $newheight, $w, $h);
        } elseif ($thum_created) {
            $newim = imagecreate($newwidth, $newheight);
            imagecopyresized($newim, $img, 0, 0, 0, 0, $newwidth, $newheight, $w, $h);
        }
        if ($thum_created && ($extension == 'jpeg' || $extension == 'jpg')) {
            if (!imagejpeg($newim, $attachpath)) {
                $thum_created = false;
            }
        } elseif ($thum_created && $extension == 'png') {
            if (!imagepng($newim, $attachpath)) {
                $thum_created = false;
            }
        }
        if ($thum_created) {
            ImageDestroy($newim);
        }
    }
    $img_url = $options_cache['blogurl'] . 'content/uploadfile/' . date('Ym') . '/' . $fname;
    $xml = "\n        <struct>\n            <member>\n                <name>file</name>\n                <value>\n                    <string>{$fname}</string>\n                </value>\n            </member>\n            <member>\n                <name>url</name>\n                <value>\n                    <string>{$img_url}</string>\n                </value>\n            </member>\n            <member>\n                <name>type</name>\n                <value>\n                    <string></string>\n                </value>\n            </member>\n        </struct>\n    ";
    response($xml);
}
예제 #3
0
파일: cache.php 프로젝트: LockGit/emlog
 /**
  * 用户信息缓存
  */
 private function mc_user()
 {
     $user_cache = array();
     $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user");
     while ($row = $this->db->fetch_array($query)) {
         $photo = array();
         $avatar = '';
         if (!empty($row['photo'])) {
             $photosrc = str_replace("../", '', $row['photo']);
             $imgsize = chImageSize($row['photo'], Option::ICON_MAX_W, Option::ICON_MAX_H);
             $photo['src'] = htmlspecialchars($photosrc);
             $photo['width'] = $imgsize['w'];
             $photo['height'] = $imgsize['h'];
             $avatar = strstr($photosrc, 'thum') ? str_replace('thum', 'thum52', $photosrc) : preg_replace("/^(.*)\\/(.*)\$/", "\$1/thum52-\$2", $photosrc);
             $avatar = file_exists('../' . $avatar) ? $avatar : $photosrc;
         }
         $row['nickname'] = empty($row['nickname']) ? $row['username'] : $row['nickname'];
         $user_cache[$row['uid']] = array('photo' => $photo, 'avatar' => $avatar, 'name_orig' => $row['nickname'], 'name' => htmlspecialchars($row['nickname']), 'mail' => htmlspecialchars($row['email']), 'des' => htmlClean($row['description']), 'ischeck' => htmlspecialchars($row['ischeck']), 'role' => $row['role']);
     }
     $cacheData = serialize($user_cache);
     $this->cacheWrite($cacheData, 'user');
 }
예제 #4
0
/**
 * 图片生成缩略图
 *
 * @param string $img 预缩略的图片
 * @param string $thum_path 生成缩略图路径
 * @param int $max_w 缩略图最大宽度 px
 * @param int $max_h 缩略图最大高度 px
 * @return unknown
 */
function resizeImage($img, $thum_path, $max_w, $max_h)
{
    if (!in_array(getFileSuffix($thum_path), array('jpg', 'png', 'jpeg', 'gif'))) {
        return false;
    }
    if (!function_exists('ImageCreate')) {
        return false;
    }
    $size = chImageSize($img, $max_w, $max_h);
    $newwidth = $size['w'];
    $newheight = $size['h'];
    $w = $size['rc_w'];
    $h = $size['rc_h'];
    if ($w <= $max_w && $h <= $max_h) {
        return false;
    }
    return imageCropAndResize($img, $thum_path, 0, 0, 0, 0, $newwidth, $newheight, $w, $h);
}
예제 #5
0
파일: blogger.php 프로젝트: flyysr/emlog
<?php

/**
 * 个人资料
 * @copyright (c) Emlog All Rights Reserved
 */
require_once 'globals.php';
if ($action == '') {
    $User_Model = new User_Model();
    $row = $User_Model->getOneUser(UID);
    extract($row);
    $icon = '';
    if ($photo) {
        $imgsize = chImageSize($photo, Option::ICON_MAX_W, Option::ICON_MAX_H);
        $token = LoginAuth::genToken();
        $icon = "<img src=\"{$photo}\" width=\"{$imgsize['w']}\" height=\"{$imgsize['h']}\" style=\"border:1px solid #CCCCCC;padding:1px;\" />\n        <br /><a href=\"javascript: em_confirm(0, 'avatar', '{$token}');\">删除头像</a>";
    } else {
        $icon = '<img src="./views/images/avatar.jpg" />';
    }
    include View::getView('header');
    require_once View::getView('blogger');
    include View::getView('footer');
    View::output();
}
if ($action == 'update') {
    LoginAuth::checkToken();
    $User_Model = new User_Model();
    $photo = isset($_POST['photo']) ? addslashes(trim($_POST['photo'])) : '';
    $nickname = isset($_POST['name']) ? addslashes(trim($_POST['name'])) : '';
    $email = isset($_POST['email']) ? addslashes(trim($_POST['email'])) : '';
    $description = isset($_POST['description']) ? addslashes(trim($_POST['description'])) : '';
예제 #6
0
                    if (is_null($kl_album)) {
                        $condition = " and album={$album} order by id desc";
                    } else {
                        $idStr = empty($kl_album) ? 0 : $kl_album;
                        $condition = " and id in({$idStr}) order by substring_index('{$idStr}', id, 1)";
                    }
                    $log_photo_query = $DB->query("SELECT * FROM " . DB_PREFIX . "kl_album WHERE 1 {$condition}");
                    $kl_album_config = unserialize(Option::get('kl_album_config'));
                    $kl_album_log_photo_length = isset($kl_album_config['log_photo_length']) ? intval($kl_album_config['log_photo_length']) : 480;
                    $kl_album_log_photo_width = isset($kl_album_config['log_photo_width']) ? intval($kl_album_config['log_photo_width']) : 360;
                    if ($kl_album_log_photo_length == 0 || $kl_album_log_photo_width == 0) {
                        $kl_album_log_photo_length = $kl_album_log_photo_width = 10000;
                    }
                    while ($log_photo = $DB->fetch_array($log_photo_query)) {
                        $log_photo_url = $blogurl . substr($log_photo['filename'], 3);
                        $log_photo_size = chImageSize(EMLOG_ROOT . str_replace('thum-', '', substr($log_photo['filename'], 2)), $kl_album_log_photo_length, $kl_album_log_photo_width);
                        $log_photo_content .= '
					<li id="attlist">
					<a href="' . str_replace('thum-', '', $log_photo_url) . '" title="' . $log_photo['truename'] . '" target="_blank">
					<img src="' . $log_photo_url . '" width="60" height="60"></a>
					<br /><a href="javascript: addPhoto(\'' . str_replace('thum-', '', $log_photo_url) . '\',\'' . $log_photo_size['w'] . '\',\'' . $log_photo_size['h'] . '\');">嵌入</a>
					</li>';
                    }
                }
                break;
            }
        }
    }
    ?>
<div id="media-upload-body">
<?php