• Hi!

    I’m writing a plugin for WordPress. I need to retrieve cropped version of post thumbnail but I can’t.

    Here’s what I’m doing:

    I open the image in the builtin image editor, I crop it obtaining a 203 x 300px version. I crop it and save it (only thumbnail).

    Then in my plugin I’m trying to obtain it with:
    get_the_post_thumbnail( $post->ID, 'thumbnail' );
    which gives me a 80 x 120px version (instead of 203 x 300)!

    I’ve also tried the following way:

    <?php
    $image = wp_get_attachment_image_src( $attachId, 'thumbnail' );
    ?>
    <img src="<?php echo $image[0]; ?>" alt="<?php echo $imgAlt; ?>" />

    and I’m obtaining a 91x120px version!

    Any help will be very much appreciated!

    Regards
    Agus

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I too find image management baffling, but I believe using add_image_size() will help you get the desired results.

    Thread Starter ajberasategui

    (@ajberasategui)

    Hi,

    @bcworkz, thank you for your answer, but that solution is not good for me because the image size is not always the same. I’m using the WordPress image editor as I need different ratios (and sizes) for different images.

    Anybody else?

    Regards,
    Agus

    I believe your Settings>Media dictates the thumbnail size – the cropping you’re doing is then resized based on the thumbnail settings.

    Try one of these instead:

    <?php echo wp_get_attachment_img($image->ID, ‘medium’); ?>
    <?php echo wp_get_attachment_img($image->ID, ‘full’); ?>

    Thread Starter ajberasategui

    (@ajberasategui)

    Hi,

    @kcrusher, thank you for your answer. No luck with you recommendations.

    What I’ve found is that the thumbnail is getting the desired ratio but for some reason WordPress automatically makes it smaller. In my media settings I’ve set the thumbnail size bigger than my example size (203,300) but WordPress keeps resizing it to 80×120 (which has about the same aspect ratio but different size).

    So, the problem is not in getting the image but in the way saves it after cropping it.

    All you help is very appreciated and further help will be as well.

    Regards,
    Agus

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get Cropped Thumbnail’ is closed to new replies.