Merge pull request #393 from shish/resize_tweak
pass already fetched image object into resize()
This commit is contained in:
		
						commit
						f88ba20319
					
				| @ -84,7 +84,7 @@ class ResizeImage extends Extension { | |||||||
| 			} | 			} | ||||||
| 			if($isanigif == 0){ | 			if($isanigif == 0){ | ||||||
| 				try { | 				try { | ||||||
| 					$this->resize_image($event->image_id, $width, $height); | 					$this->resize_image($image_obj, $width, $height); | ||||||
| 				} catch (ImageResizeException $e) { | 				} catch (ImageResizeException $e) { | ||||||
| 					$this->theme->display_resize_error($page, "Error Resizing", $e->error); | 					$this->theme->display_resize_error($page, "Error Resizing", $e->error); | ||||||
| 				} | 				} | ||||||
| @ -107,7 +107,7 @@ class ResizeImage extends Extension { | |||||||
| 			// Try to get the image ID
 | 			// Try to get the image ID
 | ||||||
| 			$image_id = int_escape($event->get_arg(0)); | 			$image_id = int_escape($event->get_arg(0)); | ||||||
| 			if (empty($image_id)) { | 			if (empty($image_id)) { | ||||||
| 				$image_id = isset($_POST['image_id']) ? $_POST['image_id'] : null; | 				$image_id = isset($_POST['image_id']) ? int_escape($_POST['image_id']) : null; | ||||||
| 			} | 			} | ||||||
| 			if (empty($image_id)) { | 			if (empty($image_id)) { | ||||||
| 				throw new ImageResizeException("Can not resize Image: No valid Image ID given."); | 				throw new ImageResizeException("Can not resize Image: No valid Image ID given."); | ||||||
| @ -134,7 +134,7 @@ class ResizeImage extends Extension { | |||||||
| 					 | 					 | ||||||
| 					/* Attempt to resize the image */ | 					/* Attempt to resize the image */ | ||||||
| 					try { | 					try { | ||||||
| 						$this->resize_image($image_id, $width, $height); | 						$this->resize_image($image, $width, $height); | ||||||
| 						 | 						 | ||||||
| 						//$this->theme->display_resize_page($page, $image_id);
 | 						//$this->theme->display_resize_page($page, $image_id);
 | ||||||
| 						 | 						 | ||||||
| @ -157,19 +157,14 @@ class ResizeImage extends Extension { | |||||||
| 		This function could be made much smaller by using the ImageReplaceEvent | 		This function could be made much smaller by using the ImageReplaceEvent | ||||||
| 		ie: Pretend that we are replacing the image with a resized copy. | 		ie: Pretend that we are replacing the image with a resized copy. | ||||||
| 	*/ | 	*/ | ||||||
| 	private function resize_image(/*int*/ $image_id, /*int*/ $width, /*int*/ $height) { | 	private function resize_image(Image $image_obj, /*int*/ $width, /*int*/ $height) { | ||||||
| 		global $config, $user, $page, $database; | 		global $config, $user, $page, $database; | ||||||
| 		 | 		 | ||||||
| 		if ( ($height <= 0) && ($width <= 0) ) { | 		if ( ($height <= 0) && ($width <= 0) ) { | ||||||
| 			throw new ImageResizeException("Invalid options for height and width. ($width x $height)"); | 			throw new ImageResizeException("Invalid options for height and width. ($width x $height)"); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		$image_obj = Image::by_id($image_id); |  | ||||||
| 		$hash = $image_obj->hash; | 		$hash = $image_obj->hash; | ||||||
| 		if (is_null($hash)) { |  | ||||||
| 			throw new ImageResizeException("Image does not have a hash associated with it - Aborting Resize."); |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		$image_filename  = warehouse_path("images", $hash); | 		$image_filename  = warehouse_path("images", $hash); | ||||||
| 		$info = getimagesize($image_filename); | 		$info = getimagesize($image_filename); | ||||||
| 		/* Get the image file type */ | 		/* Get the image file type */ | ||||||
| @ -310,11 +305,11 @@ class ResizeImage extends Extension { | |||||||
| 				",
 | 				",
 | ||||||
| 				array( | 				array( | ||||||
| 					"filename"=>$new_filename, "filesize"=>$new_size, "hash"=>$new_hash, | 					"filename"=>$new_filename, "filesize"=>$new_size, "hash"=>$new_hash, | ||||||
| 					"width"=>$new_width, "height"=>$new_height,	"id"=>$image_id | 					"width"=>$new_width, "height"=>$new_height,	"id"=>$image_obj->id | ||||||
| 				) | 				) | ||||||
| 		); | 		); | ||||||
| 		 | 		 | ||||||
| 		log_info("resize", "Resized Image #{$image_id} - New hash: {$new_hash}"); | 		log_info("resize", "Resized Image #{$image_obj->id} - New hash: {$new_hash}"); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| ?>
 | ?>
 | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user