This is so simple. I just could not believe that it could be this simple. No complex coding. No javascripting.
Just a piece of CSS code.
I have been trying to automatically resize images posted in a Wordpress powered blog. What I first thought was - it would need a script that would detect and determine the size of the posted image. Based on that, if the image is larger than the required width size (in pixel), it would then automatically resize the image in the specified required size to fit in the post/story column of the Wordpress theme.
I Googled. And came across this and that tips and trick to solve the solution. But none works. I even tried playing around with Chris Messin's WP-Imagefit wordpress plugin. But it could not help me much with the theme to which I was trying to implement. What WP-Imagefit also does is that it proportionally resizes images to fit your blog template -- same as the trick I was hunting around. The drawback? WP-Imagefit plugin is currently compatible only with themes like K2 or Sandbox. The theme I am working with is neither K2 nor is it Sandbox.
Back on the prowl right off, I tried changing the posted story images with CSS's width property. It did not work. Though it does resized images but it works only with images that are larger than the required image size. The drawback to this was that images smaller than the specified required image size were also resized accordingly. I didn't want that either. I wanted those smaller images sizes unchanged. Why? It looks odd and break up the image resolutions, blah blah.
Then CSS max-width property comes to the rescue. And it finally works the way I wanted it to. It didn't resize smaller images. It resize only larger images which are larger than the specified required image size. Here is the CSS code for your Wordpress style.css..storycontent img {
max-width: 460px;
width: expression(this.width > 460 ? 460: true);
}.storycontent: The story content class. Change accordingly.img: For images found inside the .storycontent posted story460px: Change this accordingly (or lesser probably) to the width size of your story content box.width: expression(this.width > 460 ? 460: true); max-width fix for IE. Change the 460 to the appropriate size.
Now that I say is a really simple solution to an imagined big problem. No more manually specifying the dimensions of your posted images. *grins*
Tell me if this solution doesn't work. Or if there are any other workaround simpler and better than this.
Yet Another Website after a long interval
-
Its been more than 2 years that i left Information and Communication
Technology Dept. Govt. of Mizoram where i worked as a Web Content Developer
for about ...
3 days ago

16 comments:
good work K'u Lal. this will be really really helpful for mizo blog-based websites as large no. of them are powered by wordpress. Not only the Mizos, but to all wordpress users. Will try it on my CSS aftr i finished by exams.... keep it up..
sphinx leader: "As large no. of them are powered by wordpress"
huh? So far, the general consensus still seem to be blogspot among the Mizo blogosphere. Like we've always discussed before, wordpress is more powerful that blogspot, but not every average joe can fully utilize that advantage.
Wordpress.org is just amazing. It is not just a blogging tool, but something that can be used beyond what it is known for. And if every average joe RTFM, then only the advantages can be powerfully utilised. There is also a very powerful *blogging* software out there but which is yet to be popular amongst us. If one compares Wordpress.com and Blogspot.com, the latter suits me more. But if the comparison is with Wordpress.org and Blogspot.com, I will most probably choose Wordpress.org. Blogspot software is not downloadable anyway. So how can I.
I just tried this and couldn't get it to work.
where should I put this bit of code? Does it have to go somewhere specific?
Brian: The code needs to be put at style.css in your current Wordpress theme folder.
wp-content/themes/your-theme/style.css
Some said that this trick doesn't work with IE 6 (What browser do you use?) but it works in mine.
IE sucks anyway, now. An advise to cybercafe-runners and users, dump IE. Get firefox or flock or opera.
This was the *perfect* fix for my group blog that uses auto-posting from a text chat room. No plugin required. Thanks so much!
dude, i love you
saved me a ton of time!
oh my God. u r my savior. looking for this hack long2 time ago. there are bunch of wordpress plugins but only resize images that hosted in our server.
this hack is great !!!
I'm facing the problem that when visitors are posting images as comments the my theme is messed up.
Can i use this also for this problem?
hey man! thanx for the hack it worked and fix the shite out of my crap! But dude it's not a valid css when validating it. Any suggestions?!?
i don't think you really need to css validate it when the code is working for you. :-D
also, have you tried out this plugin?
Flexible Upload
great job
it will distort the image ratio when the width and height of the img are already specified. Other than that: nice solution!
I'm having an image resizing/scaling issue with my Wordpress blog which is at http://www.onelargeprawn.co.za.
I've set the max-width of the images in the CSS to 440px, and put in your expression as well. It resizes them fine in Firefox. But the resized image in IE7 looks pretty bad compared to the same resized image in Firefox.
You can see an example of what I'm talking about if you surf to http://www.onelargeprawn.co.za/2009/01/23/the-dark-knight-oscar-snub-god-is-angry/ and see the result in Firefox and IE7.
Any advice would be appreciated.
awsome. i had a blog. +10000 images
and i need a fix for it, moving to worpress. images were too big for the template i wanted. This hack is awsome! works excelent. no need to resize any picture anymore manually.
was looking for this.
Post a Comment