Location: PHPKode > projects > PHP SiteBuilder > include/class.thumbnail.php
<?php
/*		@file	class.thumbnail.php
		@date	2000-06-19
		@ver	initial version

*		$Id: class.thumbnail.php,v 1.3 2001/09/06 10:31:46 zaiborg Exp $		
*/

class thumbnail
{
#	var thumbnailsize	= "80";		// thumbnail max size
#	var cropBorder 		= "10%";		// 10% is cropped away before making thumbnail
	
#	cropRules ... 
#	no_croping		// sv. til at hele billedet er med
#	agressive?		0-10%
	
#	max_dim_crop	//		
#	full_cropping	//		skærer alt af ned til mindste billed bredde
	
	
	//et croppet motiv kan aldrig blive formindsket.
		
	
	
	
	function agressiveCropping() {
	/*	1 normal i dimensioner
		2	hvis lang/kort > 2
		
		længste side $lang
		skalering = ceil( $lang/thumb_dim)
		
		definer "firkant"
		imageCrop 
		
		
	*/	
	}
	
	function createThumb(	$im, $maxSize, $square=false) {
#							$im, array $dimensions [x,y])
#							$im, $maxX, $maxY, $createMaxSize
#							$im, $maxX, $maxY, $cropRules
/*		loadimage
		getImageSize($im);

		any cropping rules?
		
		send to cropImage

		cropImage
		
		
		
		resize image
		
		imageInterlace();
*/	}

	
	
	/**
	 * If only $b1       : left=right=top=bottom = $b1
	 * if $b1 & $b2      : top=bottom = $b1, left=right = $b2
	 * if $b1, $b2 & $b3 : top = $b1, left=right = $b2, bottom = $b3
	 * if $b1 - $b4      : top = $b1, right = $b2, bottom = $b3, left = $b4
	 */
	function imageCropBorder ($im, $b1, $b2=false, $b3=false, $b4=false) {
		if     (!$b2) {$b2 = $b1; $b3 = $b1; $b4 = $b1; }
		elseif (!$b3) {$b3 = $b1; $b4 = $b2; }
		elseif (!$b4) {$b4 = $b2; }

		$borders = Array( 'top' => $b1, 'right' => $b2, 'bottom' => $b3, 'left' => $b4 );
		$srcSize = getImageSize($im);
		$dstW = $srcSize[0] - $borders['left'] - $borders['right'];
		$dstH = $srcSize[1] - $borders['top'] - $borders['bottom'];
		$dest_im = imageCreate( $dstW, $dstH );


		imageCopy($dst_im, $im, 0,0, $scrX,$scrY, $dstW,$dstH );
		return $dst_im;
	}


	// x,y coordinates compared to old image. 
	// (0,0) is upper left corner of original.
	// x,y = (0,0) => no cropping on upper + left border, 
	function cropImage ($im, $srcX,$srcY, $W,$H )
	{
		$dst_im = imageCreate($dstW, $dstH);
		# imageCopyResized($dst_im, $im, 0,0, $dstX,$dstY, $dstW,$dstH, $dstW,$dstH);
		imageCopy($dst_im, $im, 0,0, $scrX,$scrY, $W,$H);
		return $dst_im;
	}


	function imageResize($im, $dstW, $dstH) {
		$dst_im = imageCreate($dstW, $dstH);
		$arr = getImageSize($im);
		$srcW = $arr[0]; 
		$srcH = $arr[1];
		
		# $dst_im ought to be passed as reference, no?
		# imageCopyResized($dst_im, $im, 0,0, 0,0, $dstW, $dstH, $srcW, $srcH);
		imageCopyResized(&$dst_im, $im, 0,0, 0,0, $dstW, $dstH, $srcW, $srcH);
		return $dst_im;
	}
	

	function createSquareAndPutImageOnTop($im, $dim) {
		getImageSize($im);
		$srcW = $arr[0]; 
		$srcH = $arr[1];

		$long ($srcW > $srcH) ? "x":"y";
		$dst_im = ImageCreate($dim, $dim);
		ImageColorTransparent();		// ???


		// $im må max være $dim på den bredeste led. Ellers bliver den det!
/* buggy
		if ($long == "x") {
				ImageCopy($dst_im, $im,  dstX=0, dstY=0,  src_x,  src_y,  dstW, dstH, src_w,src_h); }
		elseif ($long == "y") {
				ImageCopy($dst_im, $im,  dstX=0, dstY=0,  src_x,  src_y,  dstW, dstH, src_w,src_h); }
		else {
			# wrong... 	
		}
*/ //end buggy
		return $dst_im;
	}

} //end class

/*		PROTOTYPES...
imagecopyresized ( dst_im,  src_im,  dstX,  dstY,  srcX,  srcY,  dstW,  dstH,  srcW,  srcH)

ImageCopyResized() copies a rectangular portion of one image to another image. Dst_im is the destination image, src_im is the source image identifier. If the source and destination coordinates and width and heights differ, appropriate stretching or shrinking of the image fragment will be performed. The coordinates refer to the upper left corner. This function can be used to copy regions within the same image (if dst_im is the same as src_im) but if the regions overlap the results will be unpredictable. 

imageCopy ($dst_im, $im,  dstX=0, dstY=0,  src_x,  src_y,  dstW, dstH, src_w,src_h); }


*/












Return current item: PHP SiteBuilder