WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Thumbnail size - width priority (2 posts)

  1. alainS
    Member
    Posted 7 years ago #

    Yes, I've seen related posts and none of them resolved my problem.

    Most related posts that I've seen and tried:
    http://wordpress.org/support/topic/53640?replies=57
    http://wordpress.org/support/topic/60927?replies=9
    http://wordpress.org/support/topic/74794?replies=5
    http://wordpress.org/support/topic/77379?replies=4
    http://wordpress.org/support/topic/54180?replies=11
    http://wordpress.org/support/topic/91566?replies=2

    To hell with ratio. I just want that thumb will be "let's say" 120px in width. It doesn't matter if height is 1000px. So an image 300x4000 should resize to 120x??? in proportion.

    Every try with solutions in mentioned posts were semi or fully useless.

    Is it for real or for "..." that no one in the WP universe has a solution?

  2. alainS
    Member
    Posted 7 years ago #

    Ok WP folks...I've figured it out after many tests.

    This solution is for everyone that wants all thumbs be max. xxx width... no matter if image is 2:10 in proportion.

    Replace my 120 value with width of your choice.

    Her we go:

    In inline-uploading.php comment out this:


    if ( $imagedata['width'] * $imagedata['height'] < 4 * 1024 * 1024 ) {
    if ( $imagedata['width'] > 120 && $imagedata['width'] >=

    $imagedata['height'] * 0.2 )
    $thumb = wp_create_thumbnail($file, 120);
    elseif ( $imagedata['height'] > 150 )
    $thumb = wp_create_thumbnail($file, 150);

    if ( @file_exists($thumb) ) {
    $newdata = $imagedata;
    $newdata['thumb'] = basename($thumb);
    update_post_meta($id, '_wp_attachment_metadata', $newdata,

    $imagedata);
    } else {
    $error = $thumb;
    }
    }

    and replace it with:

    if ( $imagedata['width'] * $imagedata['height'] < 4 * 1024 * 1024 )
    {
    if ( $imagedata['width'] > 120 )
    $thumb = wp_create_thumbnail($file, 120);

    if ( @file_exists($thumb) )
    {
    $newdata = $imagedata;
    $newdata['thumb'] = basename($thumb);
    update_post_meta($id, '_wp_attachment_metadata',

    $newdata, $imagedata);
    }
    else { $error = $thumb; }
    }

    then go to admin-functions.php and comment out this portion of code:

    if ($image_attr[0] > $image_attr[1]) {
    $image_width = $image_attr[0];
    $image_height = $image_attr[1];
    $image_new_width = $max_side;

    $image_ratio = $image_width / $image_new_width;
    $image_new_height = $image_height / $image_ratio;
    //width is > height
    } else {
    $image_width = $image_attr[0];
    $image_height = $image_attr[1];
    $image_new_height = $max_side;

    $image_ratio = $image_height / $image_new_height;
    $image_new_width = $image_width / $image_ratio;
    //height > width
    }

    add this instead:

    $image_width = $image_attr[0];
    $image_height = $image_attr[1];
    $image_new_width = $max_side;

    $image_ratio = $image_width / $image_new_width;
    $image_new_height = $image_height / $image_ratio;

    That's it. Now all thumbnails will follow the 120 max width rule. Just replace 120 with width of your choice.

    I think that this post can be marked as resolved :)

    It's really interesting that finding a solution to this problem was really a pain in the ass. I was able to find solutions and help on this forum to more obscure problems.

    Thmubs up for integrating thumbnail handling in next release of WP - the greatest tool that web ever seen.

Topic Closed

This topic has been closed to new replies.

About this Topic