wordpress resizing add_image_size properly - php

I am trying to change the size of a thumbnail in wordpress, but it keeps making it exactly square even though I want to stretch the width moreso than the height.
Im not sure why this doesnt work. Any help would be great
In functions I have
// Used for large feature (header) images.
add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true );
// Used for featured posts if a large-feature doesn't exist.
add_image_size( 'small-feature', 500, 300 );
and below
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'results-thumb', 70, 55, true);
}
and where im calling the thumbnail...
<?php echo the_post_thumbnail('results-thumb'); ?>
Heres the site, at the bottom in the latest results section you'll see the thumbnails..
http://limerickfc.hailstormcommerce.com/cms/

Ok, I just fixed it with css workaround by applying a min-width rule to the containing div, although Im still not sure this is the best way to go about it. But I wont accept the answer yet as Im sure Ill run into this situation again

You probably need to regenerate the sizes. Try installing and running this plugin http://wordpress.org/extend/plugins/regenerate-thumbnails/

Related

Problem with WordPress featured image thumbnail sizes and names in code

[I messed up because I don't now much (or any) PHP.]
Recently I changed themes. Both themes are using identical thumbnail sizes for post links in various sections. My problem: the thumbnails are named differently in both themes!
The previous theme has this code to register thumbnails:
'thumb-small', 160, 160, true );
'thumb-standard', 320, 320, true );
'thumb-medium', 520, 245, true );
'thumb-large', 720, 340, true );
The new current theme uses this code and naming structure:
'kontrast-small', 160, 160, true );
'kontrast-standard', 320, 320, true );
'kontrast-medium', 520, 245, true );
'kontrast-large', 720, 340, true );
Since I didn't know any better I changed all instances of the new theme's calls for thumbnails, eg I replaced (in my child theme) the <?php the_post_thumbnail('kontrast-medium'); ?> with <?php the_post_thumbnail('thumb-medium'); ?>, the old name.
This means that all featured image thumbnails from the old theme are displayed in the correct size in the new one. Now, that I have published the first new post my theme (of course) doesn't find the matching thumbnail and displays an image that's wrong in dimensions. I assume this mess is related to some database entries, which refer to the theme's naming structure for thumbnails.
How can I fix this?
Any suggestion for some php function which could replace my messy code replacement?
Further explanation: all my featured images have the post title as graphic text overlay on the image; any automatic WordPress cropping usually cuts off some of the text or makes it too small to read. So I created all sizes manually and uploaded them via FTP, replacing the automatically generated versions. Hence I cannot use the normally suggested "Regenerate Thumbnails" plugin. The blog is is over 6 years old and has nearly 250 posts - too much time and work to re-upload each thumbnail into the matching sub-directories.
The problem can be seen here https://dare2go.com/galleries/street-art/

Woocommerce 3.5: single product variation images show stretched 100x100 thumbnails after update

Can't figure this out after a lot of Google / stack overflow searches.
After a Woocommerce update to 3.5, the main image shown AFTER clicking on a variation is blurry because these are stretched from a cropped 100x100 thumbnail. This worked fine before!
Here you will see the problem: https://www.purewood.nl/kasten/kast-kalkverf-mat/
The gallery thumbnails work fine as you can see, it only happens when clicking on a variation.
I checked in the wordpress customizer, but can't see thumbnail sizes with 100x100.
I found a solution for me
It will fix the issue until the next Woocommerce update I guess
Visit [https://wordpress.org/support/topic/variation-products-images-issues-woocommrece/][1]
You are facing this issue, right? http://prntscr.com/laaw07
have you checked by regenerate image? if not. then install WordPress Image regenerator plugin. and try once. Hope problem would be solved.
But still, if you are watching the same problem then contact me. I can solve it.
thank you
Try to adjust Thumbnail width (700 Worked For me, According To Your Size Lill Tweak) & Keep Thumbnail Cropping 1:1
I just fixed the output of the json to replace the string that is being displayed.
-416x416 was the one that was bothering me
$variations_attr = function_exists( 'wc_esc_json' ) ? wc_esc_json( $variations_json ) : _wp_specialchars( $variations_json, ENT_QUOTES, 'UTF-8', true );
$variations_attr2 = str_replace("-416x416","",$variations_attr);

Wordpress image size medium shows different sizes

Thanks for looking here and trying to provide some useful answer. Recently I have downloaded the plugin https://wordpress.org/plugins/olevmedia-shortcodes/ and it works really fine. But when trying to use the short-code for "Recent Post" i'm facing image-sizing related issue that you see on the image attached below:
It looks really ugly. I opened a code and found the small piece of code for this function:
$out .= '<div class="omsc-recent-posts-title"><h3>'. get_the_title() .'</h3></div>';
if( $thumbnail && has_post_thumbnail() ) {
$img = wp_get_attachment_image_src( get_post_thumbnail_id(), apply_filters('omsc_sc_recent_posts_img_size', 'medium'));
if($img) {
$img_html=apply_filters('omsc_sc_recent_posts_img', '<img src="'.$img[0].'" alt="'.esc_attr($post->post_title).'" />', array(
'img_src' => $img[0],
'link' => get_permalink(),
'alt' => $post->post_title,
));
$out.='<div class="omsc-recent-posts-thumb">'.$img_html.'</a></div>';
}
}
Then I look on the image size and it says:
$img = wp_get_attachment_image_src( get_post_thumbnail_id(), apply_filters('omsc_sc_recent_posts_img_size', 'medium'));
Checking through FireBug For some posts the "Medium" size is set to 222x221, for others 300x300 and for the rest 222x167
All I want to do is to make all thumbnails having the same size. So, I created this piece of code for my theme's function.php file:
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'custom-recpost-thumb', 222, 221,true );
}
and then for the plugin php file I made a call to the function in this way:
$img = wp_get_attachment_image_src( get_post_thumbnail_id(), apply_filters('omsc_sc_recent_posts_img_size', 'custom-recpost-thumb'));
I see the same. Absolutely no changes has been made. What I've done wrong?
the problem as I can see it is that the pictures you upload is not the same dimensions so it will fit your width and make the height auto there are pretty much two ways you can get around this 1. fix your pictures before you upload or fit it with css no.2= make your box that holds your img the width and height that you want and make it overflow hidden then take your image and say it have to be the same height as the box and the width have to be auto the reason for this that most pictures is made as a landscape so in that way your pictures can fit.. for the record it is not a pretty way to do it and I would recommend fixing you pictures before you upload them
Different sizes of original images will create differently sized "medium" images. This is because the medium settings in WordPress are there to accommodate images of different sizes. In general, those pixel settings provide reasonably good looking medium sized images for any size original image. I suspect WordPress is overriding your function call to show "the best" image it can, based on its algorithms and image optimization.
Even with the coding options for WordPress.org, there are still some universal settings that WP will employ to create "good" websites. Maybe it's a reputation thing, maybe it's another example of technology organizations telling users what is best for them.
In any case, I agree with Anker that optimizing your images before you upload them is a better solution. It will give you more control, and improve the chance that WP will display your images as you want.

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 ;)

Categories