Jump to content

Best cropping method?


atholon

Recommended Posts

Here is part of a script I made awhile ago that will resize to a max width or height (depending on the layout of the image) and keep the ratio:

<?php
	$maxWidth = 300;
	$maxHeight = 225;
	move_uploaded_file($_FILES['upfile']['tmp_name'], "images/".$_FILES['upfile']['name']);
	$imgSize = getimagesize("images/".$_FILES['upfile']['name']);
	if ($imgSize[0] > $maxWidth && $imgSize[0] > $imgSize[1])
	{
		$newWidth = $maxWidth;
		$newHeight = ($maxWidth/$imgSize[0])*$imgSize[1];
	}
	else if ($imgSize[1] > $maxHeight)
	{
		$newWidth = ($maxHeight/$imgSize[1])*$imgSize[0];
		$newHeight = $maxHeight;
	}
	else
	{
		$newWidth = $imgSize[0];
		$newHeight = $imgSize[1];
	}
?>

Link to comment
https://forums.phpfreaks.com/topic/120272-best-cropping-method/#findComment-619632
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.