Is there a way to stop wordpress resizing images?
I already have in the functions.php
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 235, 419 );
add_image_size( 'single-post-thumbnail', 235, 419 );
Still doesn't work, when I upload a post thumbnail resizes it to some crazy sizes which I don't want..Any way to get this working?
//The resized image is 235x198 it should be 235x419that's the size of the image that I'm uploading
//SOLVED with the_post_thumbnail("large");
That's because it's scaling the image! Pass a third argument as true so that images are cropped to the exact size.
Related
In WordPress admin, I have defined the size for medium as such:
I have then uploaded an image and defined in my code to use medium
$image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium' );
However, the image size is being rendered at 370 x 186px. With the original size of the image being 1200 x 600. Seems like the width settings are being applied, but not the height?
WordPress is maintaining the aspect ratio for the crop. 1200x600 (which is a ratio of 2:1) is downsized to 370x185 (ratio 2:1), the latter of which is rounded up to 186.
If you look at the thumbnail version there's a checkbox to crop the image exactly, however WordPress doesn't do that for the default image sizes because it is an unexpected experience. If you do want it to crop, you can manually register your own size using add_image_size and pass true for the last parameter which is crop
add_action(
'after_setup_theme',
static function() {
add_image_size( 'custom-medium', 370, 325, true );
}
);
I am trying to manually add more featured image sizes in the functions.php, but if the set image size is larger than the image width, the crop is not being created?
add_theme_support( 'post-thumbnails' );
add_image_size( 'custom-square', 400, 400, true );
add_image_size( 'custom-medium', 1440, 9999 );
add_image_size( 'custom-large', 1920, 9999 );
So if I upload an image with a width of 1000px, the 1440px version is not being created for some reason. How can I correct this?
I wanna resize post thumbnail in Wordpress. So I use that function: get_the_post_thumbnail($onepost->ID, array(234, 156)); But I recive images with size 300x189. Why is this happens?
You best bet it to add your thumbnail size by using at add_image_size function, then call that new thumnail in your function:
In your functions.php:
add_image_size( 'custom-thumb', 234, 156 );
In your template file or wherever you're calling the thumbnail:
the_post_thumbnail( 'custom-thumb' );
Note that you will probably have to regenate your thumbnails after you do this as thumbnails are created when you upload the image, thus all images you uploaded won't have this custom thumbnail size. Here is a good plugin for that:
https://wordpress.org/plugins/regenerate-thumbnails/
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.
I have set crop in functions.php to resize Images for Posts.
Codex from Wordpress: add_image_size, post_thumbnail
add_theme_support('post-thumbnails');
set_post_thumbnail_size(100, 100, true); //size of thumbs
add_image_size( 'post-thumb', 180, 180, true ); //(cropped)
Usage is like below
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'post-thumb' ); } ?>
But it will not resize the thumb and shows the original size. What am I doing wrong?
Wordpress will only resize images on upload, you can use this plugin to resize images on the fly, so the first time you call an image size that does not exists, this plugin will resize the image so the next times image size will exist.