WordPress.org

Ready to get started?Download WordPress

Forums

Images attached to posts, size issue (9 posts)

  1. oMIKEo
    Member
    Posted 8 years ago #

    Hi,

    Is it possible to set say if an image is bigger than a certain size then make it a set maximum size?

    e.g if a user attaches an image to a post that is massive and it messes the layout up is there an automatic way of shrinking it?

    Cheers, Mike

  2. altjira
    Member
    Posted 8 years ago #

    If you're using the img button to insert the image, you'll end up seeing the html code for the link i.e. img src="..." alt="..."

    Just add another attribute inside the tags - width="XXX". I've done it before and used 640 - the pixel width I wanted, which worked fine for me using two sidebars and 1024x768 resolution. Don't worry about height - your browser with scale it with the same aspect ratio.

    Note that the image download will be slower as your browser resizes the large image to fit the sixe you specify.

  3. oMIKEo
    Member
    Posted 8 years ago #

    ok,

    This needs to be automatic but the main problem will be if the image is smaller than that width as it will become distorted, is there a way to set a 'maximum width' size rather than just a 'width' size?

    Thanks guys.

  4. Kafkaesqui

    Posted 8 years ago #

    Maximum width through css:
    http://www.w3schools.com/css/pr_dim_max-width.asp

    You assign this to an img declaration in your stylesheet, typically nested under whichever class or id your posts are in. An *example* would be:

    #content img {
    max-width: 640px;
    }

    Note that max-width does not work in Internet Explorer 6-. For ways around that:
    http://www.svendtofte.com/code/max_width_in_ie/

  5. oMIKEo
    Member
    Posted 8 years ago #

    Thanks :)

    That sounds perfect. Will look into that.

    Mike

  6. oMIKEo
    Member
    Posted 8 years ago #

    ok,

    getting a little confused with the Internet Explorer fix, the FF one worked great.

    If I add this into the style sheet:

    p {
    border:0px;
    width:expression(
    document.body.clientWidth > (500/12) *
    parseInt(document.body.currentStyle.fontSize)?
    "30em":
    "auto" );
    }

    and then add < p > < / p > around the img will that work? Or is that only for text and not images? Or where am I going wrong?

    Thanks.

  7. oMIKEo
    Member
    Posted 8 years ago #

    anyone? please.

  8. Kafkaesqui

    Posted 8 years ago #

    I'm not sure I completely understand what you're after, but the width value would act upon the paragraph (p), and not the image. For that you would need to modify the declaration to:

    p img {

  9. oMIKEo
    Member
    Posted 8 years ago #

    ok,

    All im looking for is the Internet Explorer version of that maximum width script.

    Thanks, Mike

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags