less duplication again
git-svn-id: file:///home/shish/svn/shimmie2/trunk@14 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
		
							parent
							
								
									d45e3af215
								
							
						
					
					
						commit
						5614a7f7da
					
				| @ -113,9 +113,6 @@ class ImageIO extends Extension { | |||||||
| 		$width = $info[0]; | 		$width = $info[0]; | ||||||
| 		$height = $info[1]; | 		$height = $info[1]; | ||||||
| 
 | 
 | ||||||
| 		$max_width  = $config->get_int('thumb_width'); |  | ||||||
| 		$max_height = $config->get_int('thumb_height'); |  | ||||||
| 
 |  | ||||||
| 		$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024); | 		$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024); | ||||||
| 		$memory_limit = get_memory_limit(); | 		$memory_limit = get_memory_limit(); | ||||||
| 		 | 		 | ||||||
| @ -129,21 +126,13 @@ class ImageIO extends Extension { | |||||||
| 		} | 		} | ||||||
| 		else { | 		else { | ||||||
| 			$image = imagecreatefromstring($this->read_file($tmpname)); | 			$image = imagecreatefromstring($this->read_file($tmpname)); | ||||||
|  | 			$tsize = get_thumbnail_size($width, $height); | ||||||
| 
 | 
 | ||||||
| 			$xscale = ($max_height / $height); | 			$thumb = imagecreatetruecolor($tsize[0], $tsize[1]); | ||||||
| 			$yscale = ($max_width / $width); |  | ||||||
| 			$scale = ($xscale < $yscale) ? $xscale : $yscale; |  | ||||||
| 
 |  | ||||||
| 			if($scale >= 1) { |  | ||||||
| 				$thumb = $image; |  | ||||||
| 			} |  | ||||||
| 			else { |  | ||||||
| 				$thumb = imagecreatetruecolor($width*$scale, $height*$scale); |  | ||||||
| 			imagecopyresampled( | 			imagecopyresampled( | ||||||
| 					$thumb, $image, 0, 0, 0, 0, | 					$thumb, $image, 0, 0, 0, 0, | ||||||
| 						$width*$scale, $height*$scale, $width, $height | 					$tsize[0], $tsize[1], $width, $height | ||||||
| 					); | 					); | ||||||
| 			} |  | ||||||
| 			return $thumb; | 			return $thumb; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -125,7 +125,22 @@ function tag_explode($tags) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | function get_thumbnail_size($orig_width, $orig_height) { | ||||||
|  | 	global $config; | ||||||
|  | 	$max_width  = $config->get_int('thumb_width'); | ||||||
|  | 	$max_height = $config->get_int('thumb_height'); | ||||||
| 
 | 
 | ||||||
|  | 	$xscale = ($max_height / $orig_height); | ||||||
|  | 	$yscale = ($max_width / $orig_width); | ||||||
|  | 	$scale = ($xscale < $yscale) ? $xscale : $yscale; | ||||||
|  | 
 | ||||||
|  | //	if($scale >= 1) {
 | ||||||
|  | //		return array($orig_width, $orig_height);
 | ||||||
|  | //	}
 | ||||||
|  | //	else {
 | ||||||
|  | 		return array($orig_width*$scale, $orig_height*$scale); | ||||||
|  | //	}
 | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # $db is the connection object
 | # $db is the connection object
 | ||||||
|  | |||||||
| @ -90,9 +90,6 @@ class RegenThumb extends Extension { | |||||||
| 		$width = $info[0]; | 		$width = $info[0]; | ||||||
| 		$height = $info[1]; | 		$height = $info[1]; | ||||||
| 
 | 
 | ||||||
| 		$max_width  = $config->get_int('thumb_width'); |  | ||||||
| 		$max_height = $config->get_int('thumb_height'); |  | ||||||
| 
 |  | ||||||
| 		$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024); | 		$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024); | ||||||
| 		$memory_limit = get_memory_limit(); | 		$memory_limit = get_memory_limit(); | ||||||
| 		 | 		 | ||||||
| @ -106,21 +103,13 @@ class RegenThumb extends Extension { | |||||||
| 		} | 		} | ||||||
| 		else { | 		else { | ||||||
| 			$image = imagecreatefromstring($this->read_file($tmpname)); | 			$image = imagecreatefromstring($this->read_file($tmpname)); | ||||||
|  | 			$tsize = get_thumbnail_size($width, $height); | ||||||
| 
 | 
 | ||||||
| 			$xscale = ($max_height / $height); | 			$thumb = imagecreatetruecolor($tsize[0], $tsize[1]); | ||||||
| 			$yscale = ($max_width / $width); |  | ||||||
| 			$scale = ($xscale < $yscale) ? $xscale : $yscale; |  | ||||||
| 
 |  | ||||||
| 			if($scale >= 1) { |  | ||||||
| 				$thumb = $image; |  | ||||||
| 			} |  | ||||||
| 			else { |  | ||||||
| 				$thumb = imagecreatetruecolor($width*$scale, $height*$scale); |  | ||||||
| 			imagecopyresampled( | 			imagecopyresampled( | ||||||
| 					$thumb, $image, 0, 0, 0, 0, | 					$thumb, $image, 0, 0, 0, 0, | ||||||
| 						$width*$scale, $height*$scale, $width, $height | 					$tsize[0], $tsize[1], $width, $height | ||||||
| 					); | 					); | ||||||
| 			} |  | ||||||
| 			return $thumb; | 			return $thumb; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user