Changeset 10949
- Timestamp:
- 08/19/08 16:40:48 (5 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfExtendedFileValidatorPlugin/trunk/lib/validator/sfExtendedFileValidator.class.php
r10917 r10949 25 25 return false; 26 26 } 27 else 27 28 /* 29 * $imgData[0] retrieve width 30 * $imgData[1] retrieve height 31 */ 32 $imgData = @getimagesize($value['tmp_name']); 33 34 $min_width = $this->getParameter('min_width'); 35 36 if ($min_width !== null && $min_width > $imgData[0]) 28 37 { 29 $ imgs = $this->context->getRequest()->getFileNames();38 $error = $this->getParameter('min_width_error'); 30 39 31 foreach ($imgs as $img) 32 { 33 $img = $this->context->getRequest()->getFilePath($img); 40 return false; 41 } 34 42 35 /* 36 * $imgData[0] retrieve width 37 * $imgData[1] retrieve height 38 */ 39 $imgData = @getimagesize($img['picture']); 43 $max_width = $this->getParameter('max_width'); 44 if ($max_width !== null && $max_width < $imgData[0]) 45 { 46 $error = $this->getParameter('max_width_error'); 40 47 41 $min_width = $this->getParameter('min_width'); 48 return false; 49 } 42 50 43 if ($min_width !== null && $min_width > $imgData[0]) 44 { 45 $error = $this->getParameter('min_width_error'); 51 $min_height = $this->getParameter('min_height'); 46 52 47 return false; 48 } 53 if ($min_height !== null && $min_height > $imgData[1]) 54 { 55 $error = $this->getParameter('min_height_error'); 49 56 50 $max_width = $this->getParameter('max_width'); 51 if ($max_width !== null && $max_width < $imgData[0]) 52 { 53 $error = $this->getParameter('max_width_error'); 57 return false; 58 } 54 59 55 return false; 56 } 60 $max_height = $this->getParameter('max_height'); 57 61 58 $min_height = $this->getParameter('min_height'); 62 if ($max_height !== null && $max_height < $imgData[1]) 63 { 64 $error = $this->getParameter('max_height_error'); 59 65 60 if ($min_height !== null && $min_height > $imgData[1]) 61 { 62 $error = $this->getParameter('min_height_error'); 66 return false; 67 } 68 69 $exact_width = $this->getParameter('exact_width'); 63 70 64 return false; 65 } 71 if ($exact_width !== null && $exact_width != $imgData[0]) 72 { 73 $error = $this->getParameter('exact_width_error'); 66 74 67 $max_height = $this->getParameter('max_height'); 75 return false; 76 } 68 77 69 if ($max_height !== null && $max_height < $imgData[1]) 70 { 71 $error = $this->getParameter('max_height_error'); 78 $exact_height = $this->getParameter('exact_height'); 72 79 73 return false;74 }75 }80 if ($exact_height !== null && $exact_height != $imgData[1]) 81 { 82 $error = $this->getParameter('exact_height_error'); 76 83 77 return true;84 return false; 78 85 } 86 87 $aspect = $this->getParameter('aspect'); 88 89 if ($aspect !== null && ( is_float($aspect) || is_int($aspect) ) && $aspect != $imgData[0]/$imgData[1]) 90 { 91 $error = $this->getParameter('aspect_error'); 92 93 return false; 94 } 95 96 // If we want to resave jpegs to noninterlaced (unfortunately this cannot be checked), resave the image using imageinterlace(0) and jpeg quality 90 97 // Todo: Check if the image is noninterlaced before resaving 98 if ( $imgData[2]==IMAGETYPE_JPEG && $this->getParameter('resave_to_noninterlaced') ) 99 { 100 $temp_resource = imagecreatefromjpeg($value['tmp_name']); 101 imageinterlace($temp_resource,0); 102 imagejpeg($temp_resource,$value['tmp_name'],90); 103 imagedestroy($temp_resource); 104 } 105 106 return true; 79 107 } 80 108 … … 91 119 $this->setParameter('max_height', null); 92 120 $this->setParameter('max_height_error', 'File has a height too big'); 93 121 $this->setParameter('exact_width', null); 122 $this->setParameter('exact_width_error', 'File has an incorrect width'); 123 $this->setParameter('exact_height', null); 124 $this->setParameter('exact_height_error', 'File has an incorrect height'); 125 $this->setParameter('aspect', null); 126 $this->setParameter('aspect_error', 'File has an incorrect aspect ratio'); 127 $this->setParameter('resave_to_noninterlaced',false); 128 94 129 $this->getParameterHolder()->add($parameters); 95 130