Image tag Resizing :
In a WYSIWYG editor, User can upload picture with any width.
as developer it our duty to resize the image show at fix width like (600px) or less.
here is regular expression to do so:
Regular Expression :
PHP code
// this will take all the width which is longer than 1000px and above
$replacement = array ('width="600px"','width="600px"');
// it will replace all the element which have width over 600px and replace it with 600px and deletes the height attribute.
echo preg_replace($pattern, $replacement, $user_text);
This nice but if there no width tag it will not work? very big sized image can be without any kind of width attribute !! PHP has that nice function getimagesize(); but I did not like to code that much to so this small job. I used a bit of JQuery to solve the issue.
// you have to include JQuery to use this code $(function(){ var a =$('.blog_body img'); for(var i=0;i600) { $(a[i]).attr('width','600'); } } });
If the browser runs the JS, it will work.

09/10/2009 at 8:53 am Permalink
kool tip
29/10/2009 at 3:39 am Permalink
thanks for the nice post. but where should i put it?