Reputation: 10601
I have few post thumbnails sizes but it seems like it is not picking them up as I want as it is automatically proportioning by giving its own sizes even tho I have provided fixed sizes in function.php:
In my function.php:
if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size($name = 'p1', $width = 260, $height = 85, $crop = TRUE);
add_image_size($name = 'p2', $width = 260, $height = 100, $crop = TRUE);
add_image_size($name = 'p3', $width = 560, $height = 560, $crop = TRUE);
add_image_size($name = 'p4', $width = 260, $height = 460, $crop = TRUE);
add_image_size($name = 'p5', $width = 260, $height = 60, $crop = TRUE);
add_image_size($name = 'p6', $width = 260, $height = 130, $crop = TRUE);
}
In my template:
<?php
$img = array();
$img[] = '1';
$img[] = '2';
$img[] = '3';
$img[] = '4';
$img[] = '5';
$img[] = '6';
$max = count($img) -1;
$count = rand(0,$max);
$dice = p.$img[$count];
?>
<?php the_post_thumbnail("$dice"); ?>
Basically assigning an array so that i get random picked up sizes, yet while the width is correct for all the images, the height it is not been pick up and wp auto set it to proportionally display the image. I need my own sizes to work and crop them.
Even tried giving this:
if ( function_exists( 'add_image_size' ) ) {
add_image_size('p1', 260, 85, true);
add_image_size('p2', 260, 100, true);
add_image_size('p3', 560, 560, true);
add_image_size('p4', 260, 460, true);
add_image_size('p5', 260, 60, true);
add_image_size('p6', 260, 130, true);
}
With no luck, I get an image with width: 560 and height: 360 for example, why would I if I did not set any size like that? It's like setting the correct height to proportionally display the image instead of cropping it with my defined sizes, I don't get it
Anyone please? Thanks
Upvotes: 0
Views: 250
Reputation: 10601
The issue was with the height of one image not been more or equal as per what i've defined, nice to know!
Basically if your featured image does not have at least the height you supply in the custom post thumb size, it will automatically find the correct proportional height according to its width (yet I assume you'd have the same issue with the width if you define a bigger one than what the actual image has).
To be honest I would have expect it to stretch. Haven't read or found anything about his specification, should be pointed out somewhere in codex.
Thanks tho ;)
Upvotes: 1