Unstoppable Domains โ€” AI Assistant

Need help with PHP - All my NP$ if you can help me.

Spaceship Spaceship
Watch
Impact
22
Hi,

I just need to combine an upload image script with a thumbnail creation routine. I'm really tired so I just cannot figure it out (and I'm not a professional programmer either). All my NP$ to the first person that can help me get it working. Please PM me and post 'PM sent' if you can help me. Thanks!!. :xf.love:
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Do you know how to do a basic upload? If so, use the function below to create the thumbnail, where $src is the path to the image you just uploaded and $dest is the location where the thumbnail will go

PHP:
	function image_createthumb($src,$dest,$maxWidth,$maxHeight,$quality) { 
		if (file_exists($src)  && isset($dest)) { 
			// path info 
			$destInfo  = pathInfo($dest); 
			
			// image src size 
			$srcSize   = getImageSize($src); 
			   
			// image dest size $destSize[0] = width, $destSize[1] = height 
			$srcRatio  = $srcSize[0]/$srcSize[1]; // width/height ratio 
			$destRatio = $maxWidth/$maxHeight; 
			if ($destRatio > $srcRatio) { 
				$destSize[1] = $maxHeight; 
				$destSize[0] = $maxHeight*$srcRatio; 
			} 
			else { 
				$destSize[0] = $maxWidth; 
				$destSize[1] = $maxWidth/$srcRatio; 
			} 
			
			// path rectification 
			if ($destInfo['extension'] == "gif") { 
				$dest = substr_replace($dest, 'jpg', -3); 
			} 
			
			// true color image, with anti-aliasing 
			$destImage = imagecreatetruecolor($destSize[0],$destSize[1]); 
			imageantialias($destImage,true); 
			
			// src image 
			switch ($srcSize[2]) { 
				case 1: //GIF 
				$srcImage = imagecreatefromgif($src); 
				break; 
				
				case 2: //JPEG 
				$srcImage = imagecreatefromjpeg($src); 
				break; 
				
				case 3: //PNG 
				$srcImage = imagecreatefrompng($src); 
				break; 
				
				default: 
				return false; 
				break; 
			} 
			
			// resampling 
			imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]); 
			
			// generating image 
			switch ($srcSize[2]) { 
				case 1: 
				case 2: 
				imagejpeg($destImage,$dest,$quality); 
				break; 
				
				case 3: 
				imagepng($destImage,$dest); 
				break; 
			} 
			return true; 
		} 
		else { 
			return false; 
		} 
	}
 
0
•••
Thanks, gamex. I had already created much of the code, but there was an error I just couldn't pinpoint. Thanks to the code you posted I could track the error in my code. NP$ sent. :D
 
0
•••
Appraise.net
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back