WordPress.org

Ready to get started?Download WordPress

Forums

[closed] How to resize image, not crop on post thumb (2 posts)

  1. Mixtaka
    Member
    Posted 4 years ago #

    I use this script on funtion.php to retrieve first image of post on home page to show as thumbnail, and the script will work same as i want, but the post image will crop not resize. can anyone tell me what modification i do in this code, so the image will resize.

    // Retrieve the src of first image in a post
    function bm_extract_string($start, $end, $original) {
    $original = stristr($original, $start);
    $trimmed = stristr($original, $end);
    return substr($original, strlen($start), -strlen($trimmed));
    }
    function getFirstImage() {
    $content = get_the_content();
    $pic_string = bm_extract_string('src="','" ',$content);
    $imagesize = getimagesize($pic_string);
    list($width, $height, $type, $attr) = getimagesize($pic_string);
    $link = get_permalink();
    $title = get_the_title($post->post_title);
    echo '<a href="'.$link.'" style="background:url('.$pic_string.'); display:block; width:'.$width.'px; height:'.$height.'px;" title="'.$title.'"></a>';
    }

    than i add this code in index.php

    <?php getFirstImage(); ?>

    this is my site : http://www.movieflake.com/ (check home page, all images are crop, not resize)

  2. MichaelH
    Member
    Posted 4 years ago #

    Duplicate: http://wordpress.org/support/topic/374689

    Please refrain from posting duplicate topics

Topic Closed

This topic has been closed to new replies.

About this Topic