• 0

Image Resizing + Sending to DB


Question

What i'm tryng to do is have images resized to a width of 200 or height of 80, if it's greater in either of those.

It keeps it's proportions.

Here is what i've gotten so far:

//Define the maximum height and width
$maxheight = 80;
$maxwidth = 200;

//Find image's size
	$imgsize = getimagesize($_POST['imgurl']);
	$imgheight = $imgsize[1];
	$imgwidth = $imgsize[0];

	//Calculate the size factor
	if (($imgheight >= ($maxheight + 1)) or ($imgwidth >= ($maxwidth + 1))) 
	{   
  if ($imgheight >= $imgwidth) 
  { 
  	$sizefactor = (double) ($maxheight / $imgheight);
  } 
  else 
  {
  	$sizefactor = (double) ($maxwidth / $imgwidth);
  }
	}    

	//Figure out new dimensions
	$newwidth = (int) ($imgwidth * $sizefactor);
	$newheight = (int) ($imgheight * $sizefactor);

$_POST['imgurl'] is the url to the image, for example:

http://images.neowin.net/style_images/Neo3Blue/neologo.gif

What i've gotten it to do is find the original dimensions, and calculate what the new dimensions will be.

What I don't know how to do is to make it resize the image.

Can anyone help with that code?

BTW it has to be able to distinguish between gif, png, and jpg (i'll limit it to those file types) if relevant.

If someone can tell me how to insert it into a database instead of creating a new file that would be a bonus. :)

Thanks for any help! :)

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.