• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

Image Resizing + Sending to DB


rossco_2004    0

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);
  	$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:


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! :)

Share this post

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.