WordPress.org

Ready to get started?Download WordPress

Forums

How to resize image (3 posts)

  1. Mixtaka
    Member
    Posted 4 years ago #

    I use this script on funtion.php to retrieve first image of post, 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 add this code on index.php

    <?php getFirstImage(); ?>

  2. esmi
    Forum Moderator
    Posted 4 years ago #

  3. Mixtaka
    Member
    Posted 4 years ago #

    Hello esmi

    im totally new in php and wordpress.

    is it possible, you tell me exactly what modification i do in this code. so the image will size, when i set there height and width.

    i view this page - http://codex.wordpress.org/Function_Reference/wp_get_attachment_image but did not understand.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic