Crop thumbnail images - add_image_size - Wordpress - php

I am trying to add a thumbnail crop to images, however I can't get it to work correctly. I have faced similar problems earlier, but wasn't able to solve it.
The page shows the latest posts, and since some of them has different horatio and size, I must use thumbnail crop within functions to make them appear the same size and correct horatio, and not scale them into something different.
This is the code I am using to show latest thumb
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('frontpage_thumb'); } ?>
Within functions.php:
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
add_theme_support( 'nav-menus' );
}
add_action( 'after_setup_theme', 'mytheme_custom_thumbnail_size' );
function mytheme_custom_thumbnail_size(){
add_image_size( 'frontpage_thumb', 300, 220, array( 'center', 'center' ) ); // Hard crop center
}
The problem
They thumbs resize, but don't crop. See page.
I have tried Regenerate Thumb Plugin, but no result.
Have I misunderstood the "WP cropping"?

The problem appeared to be related with the thumbnails with Wordpress.
To solve the problem I did the following:
Uninstall the thumbnail plugin used
Install another thumbnail plugin
Regenerate

Related

How to Add Custom post Thumbnails in WordPress Theme without Plugin

On my WordPress website, I have a blog page that contains 4 posts, and each post has an image of size 1080x900 px. I want to show this image as a thumbnail of 350x300px on the WordPress site.
How can I add custom thumbnail size in the function.php file and what is the next step to do?
You can use
add_theme_support( 'post-thumbnails' );
add_image_size( 'custom-size', 350, 300, true );
Images will be available as a thumb in that size after you regenerate media.
For more info: https://developer.wordpress.org/reference/functions/add_image_size/

Featured Image on Wordpress

I have a little problem... when I want to show the featured image on my posts, the chosen size isn't working (the photo is shown in it's own size). And I want the featured Image to be shown in the same width as the post total width but I have no clue!
This is the code I'm using in the PHP section
if ( function_exists( 'add_theme_support' ) ) add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size(640, 205);
My question is... where do I have to put this code?
<?php add_theme_support( 'post-thumbnails' );?>
And what would be the css I have to use to show it in the same width as the post total width?
Thanks
Put the php code add_theme_support( 'post-thumbnails' ); on functions.php under the theme directory.
WordPress cutting thumbnails while uploading the file, so you have to enable the feature first then upload the image.
Put this code add_theme_support( 'post-thumbnails' ); in function.php file
Select Post option,at right side bar corner,you will find the option as Featured images changes and updates,select and update the image which you require.
Else try with this Code format:
the_post_thumbnail();
set_post_thumbnail_size( 50, 50);`add_image_size( 'single-post-thumbnail', 590, 180 );

Wordpress 3.8 add_image_size( ) not working

i am trying to create my first wordpress theme and i came now to a problem i can't seem to solve.
Due to the design of the theme, i would like to have featured images on every post, but they would need to be all the same size.
On my functions.php i have enabled the feature images, set a size and even tried to add custom size, but nothing is working as i wanted.
My code looks like this:
function.php:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 200,200, true);
add_image_size( 'feat', 200, 200, true );
then on my content.php:
<?php the_post_thumbnail('feat'); ?>
The images resize, but they don't crop. It makes the bigger side of the image equal to 200, but still keeps the original aspect ration.
Any ideas of what i'm doing wrong?
Maybe it happens because you had added add_image_size before you uploaded your images.
Try to delete and upload images again or download Regenerate Thumbnails plugin and regenerate all your images in media library.

Disable aspect ratio or image crop on wordpress custom header images

Can anyone help me with either disabling the aspect ratio for custom header image cropping in the wordpress 2011 theme, or disabling the cropping altogether?
At this stage I just need to get it done, even if it means modifying the core files. I've googled solutions, but have found none so far.
Thank you!
If I understand well what you want to do, I think you can look at the functions.php file of the theme.
You will see these lines :
// The height and width of your custom header.
// Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values.
define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 288 ) );
// We'll be using post thumbnails for custom header images on posts and pages.
// We want them to be the size of the header image that we just defined
// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
// Add Twenty Eleven's custom image sizes
add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images
add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist
If you want to change the behaviour of the crop, you just have to set the third parameter of the *add_image_size()* function to false as you can see it in the add_image_size() codex page
I hope that's what you want, if not, let me know ;)

wordpress add thumbnail to post Excerpts plugin or method

I am looking for a way to add thumbnail images to post Excerpts.
I've installed: SuperSlider-Excerpt and Thumbnail For Excerpts plugins but I need to specifically assign the thumbnail that I want to use per post or automatically get the featured image to display as the thumbnail.
Anyone know a method or plugin that can do this please?
You can do this pretty easily with Wordpress. Like Francy said, the_post_thumbnail() will add the featured image you have picked on the post edit page in the admin section.
First you need to set up your thumbnails in your functions.php file. This is in the root directory of your theme (wp-content/themes/your-theme). Write this:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 200, 200, false ); // Set your size, and clipping options
This would make thumbnails 200x200. You may want something else, so put whatever number you want in there.
Now that thumbnails are active, you can use the the_post_thumbnail() throughout your site, inside the loop, to display the thumbnail you've picked.
For example, if you want them to appear on the index page, head to index.php in your theme root directory, and write , right before . Experiment with where these appear, and get it in the right place for you.
Try within the loop:
the_post_thumbnail("thumbnail");
Or what also helped me was:
<?php
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail');
$theImageSource = $image[0];
?>

Categories