PHP图片裁减源码

Home / Article MrLee 2017-4-5 3807

//timthumb缩略图函数 已经把域名全部加上,好用七牛空间镜像
function post_thumbnail($width, $height, $dataSrc) {
    global $post;
    $blogUrl = 'http://' . $_SERVER['HTTP_HOST'];
    $isTimThumb = get_option('themes_fo2_TimThumb');
    $first_img_src = catch_that_image();
    $timthumbFlod = str_replace($blogUrl, '', get_bloginfo("template_url"));;
    if (has_post_thumbnail()) { //如果有缩略图,则显示缩略图
        $timthumb_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID) , 'full');
        $timthumb_src = str_replace($blogUrl, '', $timthumb_src[0]);
        if (isset($dataSrc)) {
            if (!$isTimThumb) {
                $post_timthumb = '<img ' . $dataSrc . '="' . $timthumbFlod . '/timthumb.php?src=' . $timthumb_src . '&amp;h=' . $height . '&amp;w=' . $width . '&amp;zc=1" alt="' . $post->post_title . '" />';
            } else {
                $post_timthumb = '<img ' . $dataSrc . '="' . $timthumb_src . '" height="' . $height . '" width="' . $width . '" alt="' . $post->post_title . '" />';
            }
        } else {
            if (!$isTimThumb) {
                $post_timthumb = '<img src=' . $timthumbFlod . '/timthumb.php?src=' . $timthumb_src . '&amp;h=' . $height . '&amp;w=' . $width . '&amp;zc=1" alt="' . $post->post_title . '" />';
            } else {
                $post_timthumb = '<img src="' . $timthumb_src . '" height="' . $height . '" width="' . $width . '" alt="' . $post->post_title . '" />';
            }
        }
        if (isset($timthumb_src{5})) {
            echo $post_timthumb;
        }
    } else {
        $first_img_src = str_replace($blogUrl, '', $first_img_src);
        if (!empty($first_img_src)) { //如果日志中有图片
            if (isset($dataSrc)) {
                if (!$isTimThumb) {
                    $post_timthumb = '<img ' . $dataSrc . '="' . $timthumbFlod . '/timthumb.php?src=' . $first_img_src . '&amp;h=' . $height . '&amp;w=' . $width . '&amp;zc=1" alt="' . $post->post_title . '" />';
                } else {
                    $post_timthumb = '<img ' . $dataSrc . '="' . $first_img_src . '" height="' . $height . '" width="' . $width . '" alt="' . $post->post_title . '" />';
                }
            } else {
                if (!$isTimThumb) {
                    $post_timthumb = '<img src="' . $timthumbFlod . '/timthumb.php?src=' . $first_img_src . '&amp;h=' . $height . '&amp;w=' . $width . '&amp;zc=1" alt="' . $post->post_title . '" />';
                } else {
                    $post_timthumb = '<img src="' . $first_img_src . '" height="' . $height . '" width="' . $width . '" alt="' . $post->post_title . '" />';
                }
            }
        } else { //如果日志中没有图片,则显示默认
            if (isset($dataSrc)) {
                $post_timthumb = '<img ' . $dataSrc . '="' . get_bloginfo("template_url") . '/images/default_thumb.gif" alt="' . $post->post_title . '" />';
            } else {
                $post_timthumb = '<img src="' . get_bloginfo("template_url") . '/images/default_thumb.gif" alt="' . $post->post_title . '" />';
            }
        }
        echo $post_timthumb;
    }
}

 

本文链接:https://www.it72.com/11970.htm

推荐阅读
最新回复 (1)
返回