Auto-Resize Large Images in Wordpress

I was looking for an easy way to automatically resize the images in the blog posts, so that large images won’t break the Wordpress theme. A few plugins are available, but most of them are either outdated or with lots of other functionalities which I do not need.

Finally I stumbled upon a blog entry describing an easy way of doing it with a single stylesheet edit. So, this what you need to do to get it done.

  1. Open your Wordpress theme’s Style sheet file in a text editor like notepad ( or use your webhost’s online editor). The file is located in your theme’s folder: /wp-content/themes/<your theme>/style.css
  2. Search for img in this file to get your post content wrapper’s image settings. It looks like the following in my case.
  3. .postContent img {
    margin: 10px;
    border: 3px solid #CCC;
    }

  4. Append the following content to it. Specify the size you require in pixels. I used the value 500.
  5. max-width: 500px;
    width: expression(this.width > 500 ? 500: true);

  6. The resulting code is quoted below.
  7. .postContent img {
    margin: 10px;
    border: 3px solid #CCC;
    max-width: 500px;
    width: expression(this.width > 500 ? 500: true);
    }

  8. Save the file and Refresh your blog page with a high resolution image.

Bingo!! We are done

Related Articles:

  • Wordpress: “Fatal error: Cannot redeclare pclziputilpathreduction()” in class-pclzip.php
  • Add scrollbars in Wordpress <code> blocks
  • Upgraded to Wordpress 2.51
  • Here’s a 700MB picture….. 22620×15200
  • The new Sony Ericsson- T650i and T250i
  • { 9 comments… read them below or add one }

    Sunit September 29, 2008 at 6:35 pm

    Great… I am surely gonna use it on my blog…

    Reply

    andrew January 9, 2009 at 1:00 am

    Thanks for the tip. I used it on wordpress 2.7 at it worked like a charm. I also used the same idea to control the height…this helped me with squished images

    Reply

    xSaimex February 1, 2009 at 10:07 pm

    Awesome post mate. I was looking for this and came across your site. Thank you.

    Reply

    flippy07 March 23, 2009 at 3:54 pm

    it didn’t worked. :(

    Reply

    Hemanth March 25, 2009 at 6:39 pm

    @flippy07:

    It should work in all standard wordpress themes. If your theme is is customized too much this fix won’t work. Check it in another theme and see if it’s working.

    Reply

    Chris May 3, 2009 at 11:49 pm

    This worked at treat for my website, thanks alot.

    Reply

    onjefu October 5, 2009 at 10:08 pm

    what browsers is this working with?

    Reply

    Milan T October 29, 2009 at 5:36 am

    works, but my pictures become warped so that the height and the width dont correspond…

    Reply

    Dan Sensecall January 16, 2010 at 12:07 am

    Wow. Thanks very much for this… works a treat ;)

    Reply

    Leave a Comment