Perad Posted January 31, 2008 Share Posted January 31, 2008 What I want to do is allow users on my website to upload images. The problem is that large images will break my website and look terrible. As a result I want to limit the the size of the images. I already know how to do this. The problem I am having is working out how I can actually insert this code. Currently I am using an array which is then shipped off into a preg_match statement as follows. $this->MatchReplace = array ( '/\[img\](.*?)\[\/img\]/is' => '<img src="$1" />', // Image ); foreach($this->MatchReplace as $key => $val) { $this->str = preg_replace ($key, $val, $this->str); } I need to change this to allow me to run the following fuction. public function imageResize($url, $maxwidth, $maxheight) { $fetch = getimagesize($url); $width = $fetch[0]; $height = $fetch[1]; if ($width > $maxwidth || $height > $maxheight) { if ($width > $height) { $percentage = ($maxwidth / $width); } else { $percentage = ($maxheight / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); //returns the new sizes in html image tag format...this is so you $this->imageDimensions = "width=\"$width\" height=\"$height\""; } } Would I need to use preg_match to do this? If so could someone demonstrate how this would be done? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.