Conditions | 6 |
Paths | 8 |
Total Lines | 60 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
152 | protected function expandFrame($i) { |
||
153 | /** |
||
154 | * Disposal method |
||
155 | * Values : |
||
156 | * 0 - No disposal specified. The decoder is not required to take any action. |
||
157 | * 1 - Do not dispose. The graphic is to be left in place. |
||
158 | * 2 - Restore to background color. The area used by the graphic must be restored to the background color. |
||
159 | * 3 - Restore to previous. The decoder is required to restore the area overwritten by the graphic with |
||
160 | * what was there prior to rendering the graphic. |
||
161 | */ |
||
162 | $thisFrame = $this->frames[$i]; |
||
163 | if (!$this->expandFrame) { |
||
164 | return $thisFrame->gdImage = $thisFrame->createGDImage(); |
||
165 | } |
||
166 | |||
167 | if ($i === 0) { |
||
168 | // This is first frame |
||
169 | $sizeX = $this->maxWidth; |
||
170 | $sizeY = $this->height; |
||
171 | // $sizeX = $thisFrame->getSize()->getWidth() + $thisFrame->getOffset()->getX(); |
||
172 | // $sizeY = $thisFrame->getSize()->getHeight() + $thisFrame->getOffset()->getY(); |
||
173 | } else { |
||
174 | $prevFrame = $this->frames[$i - 1]; |
||
175 | if (!in_array($prevFrame->getDisposalMethod(), [0, 1, 2])) { |
||
176 | die("Disposal method {$prevFrame->getDisposalMethod()} does not supported yet"); |
||
177 | } |
||
178 | |||
179 | // Creating detached copy of previous frame image |
||
180 | $sizeX = imagesx($prevFrame->gdImage); |
||
181 | $sizeY = imagesy($prevFrame->gdImage); |
||
182 | } |
||
183 | $newGdImage = imagecreatetruecolor($sizeX, $sizeY); |
||
184 | imagealphablending($newGdImage, false); |
||
185 | imagesavealpha($newGdImage, true); |
||
186 | $color = imagecolorallocatealpha($newGdImage, 0, 0, 0, 127); |
||
187 | imagefill($newGdImage, 0, 0, $color); |
||
188 | |||
189 | if ($i !== 0) { |
||
190 | imagecopy($newGdImage, $prevFrame->gdImage, |
||
191 | 0, 0, |
||
192 | 0, 0, imagesx($prevFrame->gdImage), imagesy($prevFrame->gdImage) |
||
193 | ); |
||
194 | |||
195 | if ($prevFrame->getDisposalMethod() === 2) { |
||
196 | imagefilledrectangle($newGdImage, |
||
197 | $prevFrame->getOffset()->getX(), $prevFrame->getOffset()->getY(), |
||
198 | $prevFrame->getOffset()->getX() + ($prevFrame->getSize()->getWidth() - 1), |
||
199 | $prevFrame->getOffset()->getY() + ($prevFrame->getSize()->getHeight() - 1), |
||
200 | $color |
||
201 | ); |
||
202 | } |
||
203 | } |
||
204 | |||
205 | $anImage = $thisFrame->createGDImage(); |
||
206 | imagecopy($newGdImage, $anImage, |
||
207 | $thisFrame->getOffset()->getX(), $thisFrame->getOffset()->getY(), |
||
208 | 0, 0, imagesx($anImage), imagesy($anImage) |
||
209 | ); |
||
210 | |||
211 | return $thisFrame->gdImage = $newGdImage; |
||
212 | } |
||
215 |