I am trying to crop a image to a certain.
I have tried using
add_image_size( 'other', 105, 70, true );
$imageString.= '<div><a href="' . $linkstring . '">' . get_the_post_thumbnail($post->ID, 'other;) . '</a></div>';
But it does not seem to crop to that exact dimension.
Any Ides?
Generally you add image sizes into your functions.php file.
//post thumbnail support
add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup() {
if ( function_exists( 'add_theme_support' ) ) {
add_image_size( 'other', 105, 70, true );
}
}
Then, once in place, for all new image uploads wordpress will create an image at that size.
If you want to create these image sizes for already uploaded images, have a look at http://wordpress.org/extend/plugins/regenerate-thumbnails/
In my experience, get_the_post_thumbnail doesn't always work if you use custom image size added with add_image_size.
I'd advise you to use add_image_size, but get the image throught wp_get_attachment_image_src like this:
$imageurl = wp_get_attachment_image_src($attachment->ID, "other" );
$imageString.= '<div><a href="' . $linkstring . '"><img src="' . $imageurl[0] . '"/></a></div>';
The functions related to image resizing and cropping are all placed in media.php.
For example, start reading about image_resize_dimensions which will also give you dimensions for cropping. Those dimensions can then be used with imagecopyresampled.