How to resize image, not crop on post thumb
-
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 : https://www.movieflake.com/ (check home page, all images are crop, not resize)
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to resize image, not crop on post thumb’ is closed to new replies.