glorybloodyhell
September 1st, 2004, 07:59 PM
this is the function defines how to display image in the forum soft that i am using img tag...
function upbcode($text) {
if(substr_count($text,"[") > 0 && substr_count($text,"]") > 0) {
//other upb code here...
$text = preg_replace('=\[img\](http:[^\[]*|[^\[:]*)\[/img\]=si','<img src="$1" border="0">',$text); }
return $text;
}
i want to change the code, using php function getimagesize () to determine the width and height of the image... then, compare the width to the re-defined maxwidth (ex: 480)... if the width > maxwidth then resize the image width to maxwidth, resize the image height to be equal to height times 480 then divided by width...
the following is the change i make for the img code above, first i added 2 more functions, then changed the code:
function imgwidth($link) {
$size = getimagesize("$link");
$width=$size[0];
return $width;
}
function imgheight($link) {
$size = getimagesize("$link");
$height=$size[1];
return $height;
}
function upbcode($text) {
if(substr_count($text,"[") > 0 && substr_count($text,"]") > 0) {
//other upb code here...
$text = preg_replace('=\[img\](http:[^\[]*|[^\[:]*)\[/img\]=si', ((imgwidth("$1")>480) ? '<img src="$1" border="0" width="480" height=((imgheight("$1"))*480/(imgwidth("$1")))>' : '<img src="$1" border="0">'), $text); }
return $text;
}
but it didn't work as i expected... so, where did i do wrong and what is the right coding to do what i wanna do there?
please help me, i'll appreciate so much for your help... thanks in advance...
function upbcode($text) {
if(substr_count($text,"[") > 0 && substr_count($text,"]") > 0) {
//other upb code here...
$text = preg_replace('=\[img\](http:[^\[]*|[^\[:]*)\[/img\]=si','<img src="$1" border="0">',$text); }
return $text;
}
i want to change the code, using php function getimagesize () to determine the width and height of the image... then, compare the width to the re-defined maxwidth (ex: 480)... if the width > maxwidth then resize the image width to maxwidth, resize the image height to be equal to height times 480 then divided by width...
the following is the change i make for the img code above, first i added 2 more functions, then changed the code:
function imgwidth($link) {
$size = getimagesize("$link");
$width=$size[0];
return $width;
}
function imgheight($link) {
$size = getimagesize("$link");
$height=$size[1];
return $height;
}
function upbcode($text) {
if(substr_count($text,"[") > 0 && substr_count($text,"]") > 0) {
//other upb code here...
$text = preg_replace('=\[img\](http:[^\[]*|[^\[:]*)\[/img\]=si', ((imgwidth("$1")>480) ? '<img src="$1" border="0" width="480" height=((imgheight("$1"))*480/(imgwidth("$1")))>' : '<img src="$1" border="0">'), $text); }
return $text;
}
but it didn't work as i expected... so, where did i do wrong and what is the right coding to do what i wanna do there?
please help me, i'll appreciate so much for your help... thanks in advance...