catch_that_image size and cropping
-
Hi there, I’m trying to find a way to have a set size and potentially hard crop images using the catch_that_image function.
At the moment, I’m using featured images primarily, but have older posts which don’t have any. Because I have a section that show a random group of posts with images I decided to use catch_that_image in an if/else statement to make sure something showed up.
Now for featured images I have the following code
if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 150, 150 ); } if ( function_exists( 'add_image_size' ) ) { add_image_size( 'article', 600, 250, true ); add_image_size( 'recent', 150, 70, true ); add_image_size('homepage', 200, 200, true); add_image_size('slider', 400, 190, true);
So I really am hoping there is a way to use add_image_size or something similar to catch_that_image in order to do the 150×70 true option. I can set the size with html, but then it distorts the image pretty bad depending on original size.
Also here is my catch_that_image code and the code I’m using to call that or the featured image.
Catch_that_image code.
<?php function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img = "/images/logo.png"; } return $first_img; } ?>
Code calling the images.
<?php if ( has_post_thumbnail() ) { ?> <p class="image"><a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'recent' ); ?></a></p> <?php } else{ ?> <p class="image"><a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"> <img src="<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>" /></a></p> <?php } ?>
I’ve tried just using the options from the add_image_size functions, but those don’t work, and I’ve tried different variations in the catch_that_image function as well.
I appreciate any help or insight anyone has.
- The topic ‘catch_that_image size and cropping’ is closed to new replies.