Support » Fixing WordPress » Thumbnail Size in 2.3 – X & Y Issues

  • Resolved travelvice

    (@travelvice)


    Hello,

    I’m trying to get all new thumbnails to conform to a MAX 150px width.

    I have found references to this line of code: $max_side = apply_filters( 'wp_thumbnail_max_side_length', 128, $attachment_id, $file );

    …but the problem is that it’s setting the Y — vertical — axis of the image to max out at 150px, when it’s only the X axis that needs the limitation.

    In short, how do you make thumbnails with a max width of 150px, and not care about the height?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    You don’t. Not without severe modifications to the code.

    You can change the 128, but that’s referring to the long side of the image, not to the width or height in particular.

    You would have to rewrite a fair amount of the code in the wp_create_thumbnail function to do what you want to do.

    Is there an ifelse function that could determine the orientation of the image before this value is set?

    If landscape then maxlength would be 150
    If portrait then maxlength would be 200

    — that should set a width of 150 for horizontal images and 150 for vertical images…

    perhaps something along the lines of….

    if ($image_height > $image_width) {
          $max_side = apply_filters( 'wp_thumbnail_max_side_length', 200, $attachment_id, $file );
    } else {
          $max_side = apply_filters( 'wp_thumbnail_max_side_length', 150, $attachment_id, $file );
        }

    Success….!

    The final markup. Simple, and works well…

    if ( $metadata['width'] >= $metadata['height'] ) {
    $max_side = apply_filters( 'wp_thumbnail_max_side_length', 150, $attachment_id, $file );
    } else {
    $max_side = apply_filters( 'wp_thumbnail_max_side_length', 200, $attachment_id, $file );
    }

    Does this keep the image ratio consistant?

    If it does, is their a way to remove it? in order to crop the thumbs into squares?

    This does keep the ratio — I haven’t looked into squares

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Thumbnail Size in 2.3 – X & Y Issues’ is closed to new replies.