| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | abstract class Upload | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-27 10:30:13 +04:00
										 |  |  |     const PATH_ROOT = '/var/www/10ballov/face/htdocs'; | 
					
						
							|  |  |  |     public static function getGreagwarImage($file_path) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         require_once PATH . '/lib/GreagwarImage/GreagwarImage.php'; | 
					
						
							|  |  |  |         $greagwar_image = new GreagwarImage($file_path); | 
					
						
							|  |  |  |         $greagwar_image->setCacheDir(self::PATH_ROOT . '/media/cache/images'); | 
					
						
							|  |  |  |         return $greagwar_image; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param $file array (ex. ['tmp_name' => '...', 'name' => '...', 'type' => '...']) | 
					
						
							| 
									
										
										
										
											2013-05-27 10:30:13 +04:00
										 |  |  |      * @param $force_create_variants bool | 
					
						
							| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  |      * @return Image | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2013-05-27 10:30:13 +04:00
										 |  |  |     public static function image($file, $force_create_variants = true) | 
					
						
							| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  |     { | 
					
						
							|  |  |  |         $image = new Image; | 
					
						
							|  |  |  |         $image->original_filename = $file['name']; | 
					
						
							| 
									
										
										
										
											2013-05-27 10:30:13 +04:00
										 |  |  |         $greagwar_image = self::getGreagwarImage($file['tmp_name']); | 
					
						
							| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  |         self::saveImage($image, $greagwar_image); | 
					
						
							| 
									
										
										
										
											2013-05-27 10:30:13 +04:00
										 |  |  |         if ($force_create_variants) { | 
					
						
							|  |  |  |             foreach (Image::$sizes as $size) { | 
					
						
							|  |  |  |                 $size_parts = explode('x', $size); | 
					
						
							|  |  |  |                 self::saveImage($image->getVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  |         } | 
					
						
							|  |  |  |         return $image; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param $image Image | 
					
						
							|  |  |  |      * @param $greagwar_image GreagwarImage | 
					
						
							|  |  |  |      * @param null $width | 
					
						
							|  |  |  |      * @param null $height | 
					
						
							|  |  |  |      * @param bool $crop | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2013-05-27 10:30:13 +04:00
										 |  |  |     public static function saveImage($image, $greagwar_image, $width = null, $height = null, $crop = true) | 
					
						
							| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-05-27 12:49:32 +04:00
										 |  |  |         $greagwar_image = clone($greagwar_image); | 
					
						
							| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  |         if ($width || $height) { | 
					
						
							|  |  |  |             $greagwar_image->resize($width, $height, 0xffffff, false, false, $crop); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-05-27 12:49:32 +04:00
										 |  |  |         $image->type = $greagwar_image->guessType(); | 
					
						
							|  |  |  |         $file_path = $greagwar_image->cacheFile($image->type, 87, true); | 
					
						
							| 
									
										
										
										
											2013-05-27 10:30:13 +04:00
										 |  |  |         $image->size = filesize($file_path); | 
					
						
							| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  |         $path_parts = pathinfo($file_path); | 
					
						
							| 
									
										
										
										
											2013-05-27 10:30:13 +04:00
										 |  |  |         $image->path = preg_replace('#^' . self::PATH_ROOT . '/#', '', $path_parts['dirname']); | 
					
						
							| 
									
										
										
										
											2013-05-24 13:27:47 +04:00
										 |  |  |         $image->filename = $path_parts['basename']; | 
					
						
							|  |  |  |         $image->width = $greagwar_image->width(); | 
					
						
							|  |  |  |         $image->height = $greagwar_image->height(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |