WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Thumbnail Size in 2.3 - X & Y Issues (7 posts)

  1. travelvice
    Member
    Posted 6 years ago #

    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?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  3. travelvice
    Member
    Posted 6 years ago #

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

  4. travelvice
    Member
    Posted 6 years ago #

    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 );
        }
  5. travelvice
    Member
    Posted 6 years ago #

    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 );
    }
  6. Chad_Coleman
    Member
    Posted 6 years ago #

    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?

  7. travelvice
    Member
    Posted 6 years ago #

    This does keep the ratio -- I haven't looked into squares

Topic Closed

This topic has been closed to new replies.

About this Topic