PDA

View Full Version : help: getimagesize function in forum code


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...

Steven.Bentley
September 2nd, 2004, 06:33 PM
The code looks reasonable to me, what is it doing instead of what you want it to?

glorybloodyhell
September 3rd, 2004, 02:54 AM
hi Steven,
thanks for your reply...
problem is that it didn't do nothing, didn't resize the big picture i enclose in img tag for testing... my thought is the 2 functions i added might not work the way i want them to... and since they are not working correctly, they return the wrong value back when i call imgwidth()... since this is the wrong value (i think this value less then maxwidth), the if..else statement failed to perform the correct action...
do you have any idea?

MishY
September 3rd, 2004, 03:55 AM
On some servers, calls to getimagesize() to check image dimensions may fail and AFAIK the problem has not been isolated.

Not much help, but I thought you might want to know as you aren't the only one with this problem.