コード例 #1
0
ファイル: mf_front_end.php プロジェクト: robre/Magic-Fields-2
function aux_image($value, $params, $type = NULL)
{
    $md5_params = md5($params);
    $thumb_path = MF_CACHE_DIR . 'th_' . $md5_params . "_" . $value;
    $thumb_url = MF_CACHE_URL . 'th_' . $md5_params . "_" . $value;
    $image_path = MF_FILES_DIR . $value;
    $name_image = $value;
    if ($type == 'image_media') {
        $data = preg_split('/\\//', $value);
        $thumb_path = MF_CACHE_DIR . 'th_' . $md5_params . "_" . $data[count($data) - 1];
        $thumb_url = MF_CACHE_URL . 'th_' . $md5_params . "_" . $data[count($data) - 1];
        $image_path = str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $value);
        $name_image = $data[count($data) - 1];
    }
    if (file_exists($thumb_path)) {
        $value = $thumb_url;
    } else {
        //generate thumb
        $create_md5_filename = 'th_' . $md5_params . "_" . $name_image;
        $output_filename = MF_CACHE_DIR . $create_md5_filename;
        $final_filename = MF_CACHE_URL . $create_md5_filename;
        $default = array('zc' => 1, 'w' => 0, 'h' => 0, 'q' => 85, 'src' => $image_path, 'far' => false, 'iar' => false);
        $size = @getimagesize($image_path);
        $defaults['w'] = $size[0];
        $defaults['h'] = $size[1];
        $params_image = explode("&", $params);
        foreach ($params_image as $param) {
            if ($param) {
                $p_image = explode("=", $param);
                $default[$p_image[0]] = $p_image[1];
            }
        }
        if ($default['w'] > 0 && $default['h'] == 0) {
            $default['h'] = round($default['w'] * $defaults['h'] / $defaults['w']);
        } elseif ($default['w'] == 0 && $default['h'] > 0) {
            $default['w'] = round($default['h'] * $defaults['w'] / $defaults['h']);
        }
        $MFthumb = MF_PATH . '/MF_thumb.php';
        require_once $MFthumb;
        $thumb = new mfthumb();
        if (is_wp35()) {
            $thumb_path = $thumb->image_resize35($default['src'], $default['w'], $default['h'], $default['zc'], $default['far'], $default['iar'], $output_filename, $default['q']);
        } else {
            $thumb_path = $thumb->image_resize($default['src'], $default['w'], $default['h'], $default['zc'], $default['far'], $default['iar'], $output_filename, $default['q']);
        }
        if (is_wp_error($thumb_path)) {
            return $thumb_path;
            return $thumb_path->get_error_message();
        }
        $value = $final_filename;
    }
    return $value;
}
コード例 #2
0
 function mf_check_wp_gallery_version()
 {
     if (is_wp35()) {
         echo "<script>jQuery(document).ready(function(\$){mf_use_new_image_gallery();});</script>";
     }
 }
コード例 #3
0
    $size = getimagesize(MF_CACHE_DIR . $image_name);
    $handle = fopen(MF_CACHE_DIR . $image_name, "rb");
    $contents = NULL;
    while (!feof($handle)) {
        $contents .= fread($handle, 1024);
    }
    fclose($handle);
    header("Cache-Control: public");
    header("Content-type: image/" . $extension);
    header("Content-Disposition: inline; filename=\"" . MF_CACHE_DIR . $image_name . "\"");
    header('Content-Length: ' . filesize(MF_CACHE_DIR . $image_name));
    echo $contents;
} else {
    //generating the image
    $thumb = new mfthumb();
    if (is_wp35()) {
        $thumb_path = $thumb->image_resize35($file, $params['w'], $params['h'], $params['zc'], $params['far'], $params['iar'], MF_CACHE_DIR . $image_name);
    } else {
        $thumb_path = $thumb->image_resize($file, $params['w'], $params['h'], $params['zc'], $params['far'], $params['iar'], MF_CACHE_DIR . $image_name);
    }
    //Displaying the image
    if (file_exists($thumb_path)) {
        $size = getimagesize($thumb_path);
        $handle = fopen($thumb_path, "rb");
        $contents = NULL;
        while (!feof($handle)) {
            $contents .= fread($handle, filesize($thumb_path));
        }
        fclose($handle);
        header("Cache-Control: public");
        header("Content-type: image/" . $extension);