• Resolved downfast

    (@downfast)


    Hi,
    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.

    Any one please? Thanks

Viewing 10 replies - 1 through 10 (of 10 total)
  • Try:

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

    Thread Starter downfast

    (@downfast)

    Hi thanks, I get this tho:

    Parse error: syntax error, unexpected T_DOUBLE_ARROW in …/functions.php on line 7

    Then try:

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

    Thread Starter downfast

    (@downfast)

    yeah I did try that too before 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

    Is the original image’s height larger than 560px?

    Thread Starter downfast

    (@downfast)

    i think so yeah, why?

    I’m not sure of WP’s behaviour in this situation if you uploaded an image whose height was less than your custom height.

    Thread Starter downfast

    (@downfast)

    oh i see why you’ve asked that.. let me try different sizes then

    Thread Starter downfast

    (@downfast)

    The issue was with the height of one image not been more or equal as per what i’ve defined, nice to know and thanks!

    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 this specification anywhere, should be pointed out somewhere in codex.

    Thanks tho 😉

    Thanks for confirming this. My guess is that the proportional re-sizing is a deliberate fallback for this kind of situation. Whilst a “stretched” height might be a logical expectation, that could result in a badly distorted image. The proportional re-sizing, OTOH, at least doesn’t look too bad.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Custom post thumbnails not using custom sizes’ is closed to new replies.