Currently, people can post links to images in an application I am using but
they can post something outrageous like 1000X800 pixels and it messes thing
up on the format. I was sent this as a solution but it really bogs down
especially on images from certain servers. Is there a better way to do
this?
The $modSettings come from a settings file and are set by me, so 250X100 for
example.
$maxwidth = $modSettings['maxwidth'];
$maxheight = $modSettings['maxheight'];
if(!($maxwidth=="0" && $maxheight=="0")){
preg_match_all('/<img src="(http:\/\/.+?)" alt="" border="0">/is',
$message, $imgmatches, PREG_PATTERN_ORDER);
for($i=0; $i<count($imgmatches[1]); $i++){
$imagesize = @getimagesize($imgmatches[1][$i]);
$width = $imagesize[0];
$height = $imagesize[1];
if($width>$maxwidth || $height>$maxheight){
if($width>$maxwidth && $maxwidth!="0"){
$height = floor($maxwidth/$width*$height);
$width = $maxwidth;
if($height>$maxheight && $maxheight!="0"){
$width = floor($maxheight/$height*$width);
$height = $maxheight;
}
}else{
if($height>$maxheight && $maxheight!="0"){
$width = floor($maxheight/$height*$width);
$height = $maxheight;
}
}
}
$imgnew[$i] = "<img src=\"" . $imgmatches[1][$i] . "\" width=\"$width\"
height=\"$height\" alt=\"\" border=\"0\">";
}
$message = str_replace($imgmatches[0], $imgnew, $message);
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php