All pastes #122284 Raw Edit

Unnamed

public php v1 · immutable
·published 2006-08-08 16:04 UTC
rendered paste body
######################################################################################function sizedownApplySizeDown ( $fileName , $newFileName="" ) {	$imageInformation = @GetImageSize( $fileName );	$imageType = $imageInformation[2];	if ($imageType == 2) {		$main_img_obj = imagecreatefromjpeg ( $fileName  );	}	//We won't bother with GIF's for now	else if ($imageType == 1) {		//$main_img_obj = @imagecreatefromgif ( $fileName  );	}	# calculate our images dimensions11	if ($main_img_obj) {		$main_img_obj_w	= imagesx( $main_img_obj );		$main_img_obj_h	= imagesy( $main_img_obj );	}			if ( $main_img_obj && ($main_img_obj_w >= 1024 or $main_img_obj_h >= (1024*1)) ) {		if ($main_img_obj_w > 1024 and $main_img_obj_h > (1024*1)) {			$newWidth = 1024;			$widthRatio = 1024 / $main_img_obj_w;			if ($debug) { print "widthRatio is $widthRatio <br>"; }			$newHeight = (int) ($widthRatio * $main_img_obj_h);			//If the height still exceeds our limits - resize it once again according to height.			if ($newHeight > (1024*1)) {				$heightRatio = (1024*1) / $newHeight;				$newHeight = (1024*1);				if ($debug) { print "heightRatio is $heightRatio <br>"; }				$newWidth = (int) ($heightRatio * $newWidth);			}		} 		//If it's the width that exceeds our limits		else if ($main_img_obj_w > 1024) {			$newWidth = 1024;			$widthRatio = 1024 / $main_img_obj_w;			if ($debug) { print "widthRatio is $widthRatio <br>"; }			$thumbSizeHeight = (int) ($widthRatio * $main_img_obj_w);		}					//If it's the height that exceeds our limits		else if ($main_img_obj_w > (1024*1)) {			$thumbSizeHeight = (1024*1);			$heightRatio = (1024*1) / $main_img_obj_w;			$newWidth = (int) ($heightRatio * $main_img_obj_w);		}					//None of the dimensions exceed our limits.		else {			$newWidth = $main_img_obj_w;			$newHeight = $main_img_obj_h;		}		$return_img	= imagecreatetruecolor( $newWidth, $newHeight );		//imagecopyresized ( $return_img, $main_img_obj, 0, 0, 0, 0, $newWidth, $newHeight, $main_img_obj_w, $main_img_obj_h);		imagecopyresampled ( $return_img, $main_img_obj, 0, 0, 0, 0, $newWidth, $newHeight, $main_img_obj_w, $main_img_obj_h);		///////////////////////////////////////////////////////////////////		if ($newFileName=="") {			imagejpeg ( $return_img, $fileName, 100 );		} else {			imagejpeg ( $return_img, $newFileName, 100 );		}			}}