I use this script on funtion.php to retrieve first image of post on home page as an post thumbnail. 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. im new in wordpress // 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>'; } Code (markup): than add this code on index.php <?php getFirstImage(); ?> Code (markup):
add a class to the image, and set up the css like this: .thumb { max-width:150px; max-heght:150px; } Code (markup): not the answer u were looking for but a efficent workaround. But looking over that code, it should not crop it, it should resize it. I believe. This is the same code with the max width and max height rather than width and height. It might work. Using it you will not need to add a class like I mentioned above, because we are building the conditions into the style tag. Just plug and play. // 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; max-width:'.$width.'px; max-height:'.$height.'px;" title="'.$title.'"></a>'; } Code (markup):
yes you can simply re-size any image anywhere by inserting that mentioned simple width and height code in it. Hope it will help
I add max width and max height rather than width and height. after this none of the image will show. i also try many plugins but none of work same as i want. i use the theme - junkie channel, this is the official site of the theme : http://www.theme-junkie.com/themes/channel/ In this theme, the auto post thumbnail is already activated and the image will crop not resize, this theme did not accept external images, and all of my blog - http://www.movieflake.com/ post have external images thats why i use this code. i also put this question in wordpress official forum and they reply me, visit this- http://codex.wordpress.org/Function_Reference/wp_get_attachment_image but i did not understand anything, hope these information help you, to help me. Thanks