Complex classes like Graphics often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Graphics, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class Graphics extends Basic |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Image prixels in BW |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $imgData = null; |
||
| 29 | /** |
||
| 30 | * Image Raster bit |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $imgRasterData = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Constructor |
||
| 38 | * Load a image, if passed a path to file and adjust dimentions |
||
| 39 | * |
||
| 40 | * @param string $filename |
||
| 41 | * @param int $width |
||
| 42 | * @param int $height |
||
| 43 | * @throws RuntimeException |
||
| 44 | */ |
||
| 45 | 12 | public function __construct($filename = null, $width = null, $height = null) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Return a string of bytes |
||
| 62 | * for inclusion on printer commands |
||
| 63 | * This method change image to Black and White and |
||
| 64 | * reducing the color resolution of 1 bit per pixel |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | 2 | public function getRasterImage() |
|
| 75 | |||
| 76 | /** |
||
| 77 | * load |
||
| 78 | * Load image file and adjust dimentions |
||
| 79 | * |
||
| 80 | * @param string $filename path to image file |
||
| 81 | * @param float $width |
||
| 82 | * @param float $height |
||
| 83 | * @throws InvalidArgumentException |
||
| 84 | * @throws RuntimeException |
||
| 85 | */ |
||
| 86 | 9 | public function load($filename, $width = null, $height = null) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Converts a true color image to Black and white |
||
| 120 | * even if the image have transparency (alpha channel) |
||
| 121 | */ |
||
| 122 | public function convertBW() |
||
| 123 | { |
||
| 124 | $newimg = imagecreatetruecolor($this->imgWidth, $this->imgHeight); |
||
| 125 | imagealphablending($newimg, false); |
||
| 126 | imagesavealpha($newimg, true); |
||
| 127 | imagecopyresampled( |
||
| 128 | $newimg, |
||
| 129 | $this->img, |
||
| 130 | 0, |
||
| 131 | 0, |
||
| 132 | 0, |
||
| 133 | 0, |
||
| 134 | $this->imgWidth, |
||
| 135 | $this->imgHeight, |
||
| 136 | $this->imgWidth, |
||
| 137 | $this->imgHeight |
||
| 138 | ); |
||
| 139 | $bcg = imagecolorallocate($newimg, 255, 255, 255); |
||
| 140 | imagefill($newimg, 0, 0, $bcg); |
||
| 141 | imagefilter($newimg, IMG_FILTER_GRAYSCALE); |
||
| 142 | imagefilter($newimg, IMG_FILTER_CONTRAST, -1000); |
||
| 143 | $this->img = $newimg; |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Save image to file |
||
| 148 | * |
||
| 149 | * @param string $filename |
||
| 150 | * @param string $type PNG, JPG, GIF, BMP |
||
| 151 | * @param integer $quality 0 - 100 default 75 |
||
| 152 | * @return boolean |
||
| 153 | */ |
||
| 154 | 4 | public function save($filename = null, $type = 'PNG', $quality = 75) |
|
| 155 | { |
||
| 156 | 4 | $type = strtoupper($type); |
|
| 157 | 4 | if ($type == 'BMP') { |
|
| 158 | 2 | $this->saveBMP($filename); |
|
| 159 | 1 | return true; |
|
| 160 | } |
||
| 161 | 2 | $aTypes = ['PNG', 'JPG', 'JPEG', 'GIF']; |
|
| 162 | 2 | if (! in_array($type, $aTypes)) { |
|
| 163 | throw InvalidArgumentException('This file type is not supported.'); |
||
| 164 | } |
||
| 165 | 2 | return $this->saveImage($filename, $this->img, $type, $quality); |
|
| 166 | } |
||
| 167 | |||
| 168 | /** |
||
| 169 | * resizeImage |
||
| 170 | * Resize an image |
||
| 171 | * NOTE: the width is always set to the multiple of 8 more |
||
| 172 | * next, why? printers have a resolution of 8 dots per mm |
||
| 173 | * |
||
| 174 | * @param float $width |
||
| 175 | * @param float $height |
||
| 176 | * @throws InvalidArgumentException |
||
| 177 | */ |
||
| 178 | 3 | public function resizeImage($width = null, $height = null) |
|
| 197 | |||
| 198 | /** |
||
| 199 | * Creates a GD QRCode image |
||
| 200 | * |
||
| 201 | * @param string $dataText |
||
| 202 | * @param int $width |
||
| 203 | * @param int $padding |
||
| 204 | * @param string $errCorretion LOW, MEDIUM, QUARTILE, HIGH |
||
| 205 | * @return void |
||
| 206 | */ |
||
| 207 | 1 | public function imageQRCode( |
|
| 208 | $dataText = 'NADA NADA NADA NADA NADA NADA NADA NADA NADA NADA NADA NADA', |
||
| 209 | $width = 200, |
||
| 210 | $padding = 10, |
||
| 211 | $errCorretion = 'MEDIUM' |
||
| 212 | ) { |
||
| 213 | //adjust width for a closest multiple of 8 |
||
| 214 | 1 | $width = $this->closestMultiple($width, 8); |
|
| 215 | 1 | $qrCode = new QrCode(); |
|
| 216 | 1 | $qrCode->setText($dataText) |
|
| 217 | 1 | ->setImageType('png') |
|
| 218 | 1 | ->setSize($width) |
|
| 219 | 1 | ->setPadding($padding) |
|
| 220 | 1 | ->setErrorCorrection($errCorretion) |
|
| 221 | 1 | ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0)) |
|
| 222 | 1 | ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0)) |
|
| 223 | 1 | ->setLabel('') |
|
| 224 | 1 | ->setLabelFontSize(8); |
|
| 225 | 1 | $this->img = $qrCode->getImage(); |
|
| 226 | 1 | $this->getDimImage(); |
|
| 227 | 1 | } |
|
| 228 | |||
| 229 | /** |
||
| 230 | * loadBMP |
||
| 231 | * Create a GD image from BMP file |
||
| 232 | * |
||
| 233 | * @param string $filename |
||
| 234 | * @return boolean |
||
| 235 | */ |
||
| 236 | 1 | protected function loadBMP($filename) |
|
| 237 | { |
||
| 238 | //open file as binary |
||
| 239 | 1 | if (! $f1 = fopen($filename, "rb")) { |
|
| 240 | throw InvalidArgumentException('Can not open file.'); |
||
| 241 | } |
||
| 242 | //get properties from image file |
||
| 243 | 1 | $file = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14)); |
|
| 244 | 1 | if ($file['file_type'] != 19778) { |
|
| 245 | throw InvalidArgumentException('This file is not a BMP image.'); |
||
| 246 | } |
||
| 247 | //get properties form image |
||
| 248 | 1 | $bmp = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'. |
|
| 249 | 1 | '/Vcompression/Vsize_bitmap/Vhoriz_resolution'. |
|
| 250 | 1 | '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40)); |
|
| 251 | //check deep of colors |
||
| 252 | 1 | $bmp['colors'] = pow(2, $bmp['bits_per_pixel']); |
|
| 253 | 1 | if ($bmp['size_bitmap'] == 0) { |
|
| 254 | 1 | $bmp['size_bitmap'] = $file['file_size'] - $file['bitmap_offset']; |
|
| 255 | 1 | } |
|
| 256 | 1 | $bmp['bytes_per_pixel'] = $bmp['bits_per_pixel']/8; |
|
| 257 | 1 | $bmp['bytes_per_pixel2'] = ceil($bmp['bytes_per_pixel']); |
|
| 258 | 1 | $bmp['decal'] = ($bmp['width']*$bmp['bytes_per_pixel']/4); |
|
| 259 | 1 | $bmp['decal'] -= floor($bmp['width']*$bmp['bytes_per_pixel']/4); |
|
| 260 | 1 | $bmp['decal'] = 4-(4*$bmp['decal']); |
|
| 261 | 1 | if ($bmp['decal'] == 4) { |
|
| 262 | $bmp['decal'] = 0; |
||
| 263 | } |
||
| 264 | 1 | $palette = array(); |
|
| 265 | 1 | if ($bmp['colors'] < 16777216) { |
|
| 266 | $palette = unpack('V'.$bmp['colors'], fread($f1, $bmp['colors']*4)); |
||
| 267 | } |
||
| 268 | //read all data form image but not the header |
||
| 269 | 1 | $img = fread($f1, $bmp['size_bitmap']); |
|
| 270 | 1 | fclose($f1); |
|
| 271 | //create a true color GD resource |
||
| 272 | 1 | $vide = chr(0); |
|
| 273 | 1 | $res = imagecreatetruecolor($bmp['width'], $bmp['height']); |
|
| 274 | 1 | $p = 0; |
|
| 275 | 1 | $y = $bmp['height']-1; |
|
| 276 | //read all bytes form original file |
||
| 277 | 1 | while ($y >= 0) { |
|
| 278 | 1 | $x=0; |
|
| 279 | 1 | while ($x < $bmp['width']) { |
|
| 280 | //get byte color from BMP |
||
| 281 | 1 | $color = $this->getBMPColor($bmp['bits_per_pixel'], $img, $vide, $p, $palette); |
|
|
|
|||
| 282 | 1 | if ($color === false) { |
|
| 283 | throw RuntimeException('Fail during conversion from BMP number bit per pixel incorrect!'); |
||
| 284 | } |
||
| 285 | 1 | imagesetpixel($res, $x, $y, $color[1]); |
|
| 286 | 1 | $x++; |
|
| 287 | 1 | $p += $bmp['bytes_per_pixel']; |
|
| 288 | 1 | } |
|
| 289 | 1 | $y--; |
|
| 290 | 1 | $p += $bmp['decal']; |
|
| 291 | 1 | } |
|
| 292 | 1 | $this->img = $res; |
|
| 293 | 1 | return true; |
|
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Convert a GD image into a BMP string representation |
||
| 298 | * |
||
| 299 | * @param string $filename |
||
| 300 | * @return string |
||
| 301 | */ |
||
| 302 | 2 | protected function saveBMP($filename = null) |
|
| 303 | { |
||
| 304 | 2 | if (! is_resource($this->img)) { |
|
| 305 | return ''; |
||
| 306 | } |
||
| 307 | //to remove alpha color and put white instead |
||
| 308 | 2 | $img = $this->img; |
|
| 309 | 2 | $imageX = imagesx($img); |
|
| 310 | 2 | $imageY = imagesy($img); |
|
| 311 | 2 | $bmp = ''; |
|
| 312 | 2 | for ($yInd = ($imageY - 1); $yInd >= 0; $yInd--) { |
|
| 313 | 2 | $thisline = ''; |
|
| 314 | 2 | for ($xInd = 0; $xInd < $imageX; $xInd++) { |
|
| 315 | 2 | $argb = self::getPixelColor($img, $xInd, $yInd); |
|
| 316 | 2 | $thisline .= chr($argb['blue']).chr($argb['green']).chr($argb['red']); |
|
| 317 | 2 | } |
|
| 318 | 2 | while (strlen($thisline) % 4) { |
|
| 319 | 2 | $thisline .= "\x00"; |
|
| 320 | 2 | } |
|
| 321 | 2 | $bmp .= $thisline; |
|
| 322 | 2 | } |
|
| 323 | 2 | $bmpSize = strlen($bmp) + 14 + 40; |
|
| 324 | // bitMapHeader [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp |
||
| 325 | 2 | $bitMapHeader = 'BM'; // WORD bfType; |
|
| 326 | 2 | $bitMapHeader .= self::littleEndian2String($bmpSize, 4); // DWORD bfSize; |
|
| 327 | 2 | $bitMapHeader .= self::littleEndian2String(0, 2); // WORD bfReserved1; |
|
| 328 | 2 | $bitMapHeader .= self::littleEndian2String(0, 2); // WORD bfReserved2; |
|
| 329 | 2 | $bitMapHeader .= self::littleEndian2String(54, 4); // DWORD bfOffBits; |
|
| 330 | // bitMapInfoHeader - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp |
||
| 331 | 2 | $bitMapInfoHeader = self::littleEndian2String(40, 4); // DWORD biSize; |
|
| 332 | 2 | $bitMapInfoHeader .= self::littleEndian2String($imageX, 4); // LONG biWidth; |
|
| 333 | 2 | $bitMapInfoHeader .= self::littleEndian2String($imageY, 4); // LONG biHeight; |
|
| 334 | 2 | $bitMapInfoHeader .= self::littleEndian2String(1, 2); // WORD biPlanes; |
|
| 335 | 2 | $bitMapInfoHeader .= self::littleEndian2String(24, 2); // WORD biBitCount; |
|
| 336 | 2 | $bitMapInfoHeader .= self::littleEndian2String(0, 4); // DWORD biCompression; |
|
| 337 | 2 | $bitMapInfoHeader .= self::littleEndian2String(0, 4); // DWORD biSizeImage; |
|
| 338 | 2 | $bitMapInfoHeader .= self::littleEndian2String(2835, 4); // LONG biXPelsPerMeter; |
|
| 339 | 2 | $bitMapInfoHeader .= self::littleEndian2String(2835, 4); // LONG biYPelsPerMeter; |
|
| 340 | 2 | $bitMapInfoHeader .= self::littleEndian2String(0, 4); // DWORD biClrUsed; |
|
| 341 | 2 | $bitMapInfoHeader .= self::littleEndian2String(0, 4); // DWORD biClrImportant; |
|
| 342 | 2 | $data = $bitMapHeader.$bitMapInfoHeader.$bmp; |
|
| 343 | 2 | $this->saveImage($filename, $data); |
|
| 344 | 1 | return $data; |
|
| 345 | } |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Convert image from GD resource |
||
| 349 | * into Black and White pixels image |
||
| 350 | * |
||
| 351 | * @return string Representation of bytes image in BW |
||
| 352 | */ |
||
| 353 | 1 | protected function convertPixelBW() |
|
| 354 | { |
||
| 355 | // Make a string of 1's and 0's |
||
| 356 | 1 | $this->imgData = str_repeat("\0", $this->imgHeight * $this->imgWidth); |
|
| 357 | 1 | for ($yInd = 0; $yInd < $this->imgHeight; $yInd++) { |
|
| 358 | 1 | for ($xInd = 0; $xInd < $this->imgWidth; $xInd++) { |
|
| 359 | //get colors from byte image |
||
| 360 | 1 | $cols = imagecolorsforindex($this->img, imagecolorat($this->img, $xInd, $yInd)); |
|
| 361 | //convert to greyness color 1 for white, 0 for black |
||
| 362 | 1 | $greyness = (int)(($cols['red'] + $cols['green'] + $cols['blue']) / 3) >> 7; |
|
| 363 | //switch to Black and white |
||
| 364 | //1 for black, 0 for white, taking into account transparency color |
||
| 365 | 1 | $black = (1 - $greyness) >> ($cols['alpha'] >> 6); |
|
| 366 | 1 | $this->imgData[$yInd * $this->imgWidth + $xInd] = $black; |
|
| 367 | 1 | } |
|
| 368 | 1 | } |
|
| 369 | 1 | return $this->imgData; |
|
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Output the image in raster (row) format. |
||
| 374 | * This can result in padding on the right of the image, |
||
| 375 | * if its width is not divisible by 8. |
||
| 376 | * |
||
| 377 | * @throws RuntimeException Where the generated data is |
||
| 378 | * unsuitable for the printer (indicates a bug or oversized image). |
||
| 379 | * @return string The image in raster format. |
||
| 380 | */ |
||
| 381 | 2 | protected function convertRaster() |
|
| 382 | { |
||
| 383 | 2 | if (! is_null($this->imgRasterData)) { |
|
| 384 | 1 | return $this->imgRasterData; |
|
| 385 | } |
||
| 386 | 2 | if (is_null($this->imgData)) { |
|
| 387 | $this->convertPixelBW(); |
||
| 388 | } |
||
| 389 | //get width in Pixels |
||
| 390 | 2 | $widthPixels = $this->getWidth(); |
|
| 391 | //get heightin in Pixels |
||
| 392 | 2 | $heightPixels = $this->getHeight(); |
|
| 393 | //get width in Bytes |
||
| 394 | 2 | $widthBytes = $this->getWidthBytes(); |
|
| 395 | //initialize vars |
||
| 396 | 2 | $xCount = $yCount = $bit = $byte = $byteVal = 0; |
|
| 397 | //create a string for converted bytes |
||
| 398 | 2 | $data = str_repeat("\0", $widthBytes * $heightPixels); |
|
| 399 | 2 | if (strlen($data) == 0) { |
|
| 400 | return $data; |
||
| 401 | } |
||
| 402 | /* Loop through and convert format */ |
||
| 403 | do { |
||
| 404 | 2 | $byteVal |= (int) $this->imgData[$yCount * $widthPixels + $xCount] << (7 - $bit); |
|
| 405 | 2 | $xCount++; |
|
| 406 | 2 | $bit++; |
|
| 407 | 2 | if ($xCount >= $widthPixels) { |
|
| 408 | 2 | $xCount = 0; |
|
| 409 | 2 | $yCount++; |
|
| 410 | 2 | $bit = 8; |
|
| 411 | 2 | if ($yCount >= $heightPixels) { |
|
| 412 | 2 | $data[$byte] = chr($byteVal); |
|
| 413 | 2 | break; |
|
| 414 | } |
||
| 415 | 2 | } |
|
| 416 | 2 | if ($bit >= 8) { |
|
| 417 | 2 | $data[$byte] = chr($byteVal); |
|
| 418 | 2 | $byteVal = 0; |
|
| 419 | 2 | $bit = 0; |
|
| 420 | 2 | $byte++; |
|
| 421 | 2 | } |
|
| 422 | 2 | } while (true); |
|
| 423 | 2 | if (strlen($data) != ($this->getWidthBytes() * $this->getHeight())) { |
|
| 424 | throw new RuntimeException("Bug in " . __FUNCTION__ . ", wrong number of bytes."); |
||
| 425 | } |
||
| 426 | 2 | $this->imgRasterData = $data; |
|
| 427 | 2 | return $this->imgRasterData; |
|
| 428 | } |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Save safety binary image file |
||
| 432 | * |
||
| 433 | * @param string $filename |
||
| 434 | * @param resource|string|null $data |
||
| 435 | * @param string $type PNG, JPG, GIF, BMP |
||
| 436 | * @param integer $quality |
||
| 437 | * @return boolean |
||
| 438 | * @throws InvalidArgumentException |
||
| 439 | * @throws RuntimeException |
||
| 440 | */ |
||
| 441 | 4 | protected function saveImage($filename = null, $data = null, $type = 'PNG', $quality = 75) |
|
| 442 | { |
||
| 443 | 4 | if (empty($filename) || empty($data)) { |
|
| 444 | return false; |
||
| 445 | } |
||
| 446 | 4 | if (is_resource($data)) { |
|
| 447 | //use GD to save image to file |
||
| 448 | switch ($type) { |
||
| 449 | 2 | case 'JPG': |
|
| 450 | 2 | case 'JPEG': |
|
| 451 | $result = imagejpeg($data, $filename, $quality); |
||
| 452 | break; |
||
| 453 | 2 | case 'GIF': |
|
| 454 | $result = imagegif($data, $filename); |
||
| 455 | break; |
||
| 456 | 2 | default: |
|
| 457 | 2 | $result = imagepng($data, $filename); |
|
| 458 | 2 | break; |
|
| 459 | 2 | } |
|
| 460 | 2 | if (!$result) { |
|
| 461 | throw new InvalidArgumentException("Fail to write in $filename."); |
||
| 462 | } |
||
| 463 | 2 | return true; |
|
| 464 | } |
||
| 465 | 2 | $handle = @fopen($filename, 'w'); |
|
| 466 | 2 | if (!is_resource($handle)) { |
|
| 467 | 1 | throw new InvalidArgumentException("Cant open file $filename. Check permissions."); |
|
| 468 | } |
||
| 469 | 1 | $nbytes = fwrite($handle, $data); |
|
| 470 | 1 | fclose($handle); |
|
| 471 | 1 | if (!$nbytes) { |
|
| 472 | throw new RuntimeException("Fail to write in $filename."); |
||
| 473 | } |
||
| 474 | 1 | return true; |
|
| 475 | } |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Get byte color form BMP |
||
| 479 | * |
||
| 480 | * @param integer $bpp bytes_per_pixel |
||
| 481 | * @param string $img bytes read of file |
||
| 482 | * @param string $vide |
||
| 483 | * @param integer $p |
||
| 484 | * @param integer $palette |
||
| 485 | * @return integer|boolean |
||
| 486 | */ |
||
| 487 | private function getBMPColor($bpp, $img, $vide, $p, $palette) |
||
| 488 | { |
||
| 489 | switch ($bpp) { |
||
| 490 | case 24: |
||
| 491 | return unpack("V", substr($img, $p, 3).$vide); |
||
| 492 | break; |
||
| 493 | case 16: |
||
| 494 | $color = unpack("v", substr($img, $p, 2)); |
||
| 495 | $blue = ($color[1] & 0x001f) << 3; |
||
| 496 | $green = ($color[1] & 0x07e0) >> 3; |
||
| 497 | $red = ($color[1] & 0xf800) >> 8; |
||
| 498 | $color[1] = $red * 65536 + $green * 256 + $blue; |
||
| 499 | return $color; |
||
| 500 | break; |
||
| 501 | case 8: |
||
| 502 | $color = unpack("n", $vide.substr($img, $p, 1)); |
||
| 503 | $color[1] = $palette[$color[1]+1]; |
||
| 504 | return $color; |
||
| 505 | break; |
||
| 506 | case 4: |
||
| 507 | $color = unpack("n", $vide.substr($img, floor($p), 1)); |
||
| 508 | if (($p*2)%2 == 0) { |
||
| 509 | $color[1] = ($color[1] >> 4) ; |
||
| 510 | } else { |
||
| 511 | $color[1] = ($color[1] & 0x0F); |
||
| 512 | } |
||
| 513 | $color[1] = $palette[$color[1]+1]; |
||
| 514 | return $color; |
||
| 515 | break; |
||
| 516 | case 1: |
||
| 517 | $color = unpack("n", $vide.substr($img, floor($p), 1)); |
||
| 518 | if (($p*8)%8 == 0) { |
||
| 519 | $color[1] = $color[1]>>7; |
||
| 520 | } elseif (($p*8)%8 == 1) { |
||
| 521 | $color[1] = ($color[1] & 0x40)>>6; |
||
| 522 | } elseif (($p*8)%8 == 2) { |
||
| 523 | $color[1] = ($color[1] & 0x20)>>5; |
||
| 524 | } elseif (($p*8)%8 == 3) { |
||
| 525 | $color[1] = ($color[1] & 0x10)>>4; |
||
| 526 | } elseif (($P*8)%8 == 4) { |
||
| 527 | $color[1] = ($color[1] & 0x8)>>3; |
||
| 528 | } elseif (($p*8)%8 == 5) { |
||
| 529 | $color[1] = ($color[1] & 0x4)>>2; |
||
| 530 | } elseif (($p*8)%8 == 6) { |
||
| 531 | $color[1] = ($color[1] & 0x2)>>1; |
||
| 532 | } elseif (($p*8)%8 == 7) { |
||
| 533 | $color[1] = ($color[1] & 0x1); |
||
| 534 | } |
||
| 535 | $color[1] = $palette[$color[1]+1]; |
||
| 536 | return $color; |
||
| 537 | break; |
||
| 538 | default: |
||
| 539 | return false; |
||
| 540 | } |
||
| 541 | } |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Converts Litte Endian Bytes do String |
||
| 545 | * |
||
| 546 | * @param int $number |
||
| 547 | * @param int $minbytes |
||
| 548 | * @return string |
||
| 549 | */ |
||
| 550 | 2 | private static function littleEndian2String($number, $minbytes = 1) |
|
| 551 | { |
||
| 552 | 2 | $intstring = ''; |
|
| 553 | 2 | while ($number > 0) { |
|
| 554 | 2 | $intstring = $intstring.chr($number & 255); |
|
| 555 | 2 | $number >>= 8; |
|
| 556 | 2 | } |
|
| 557 | 2 | return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 558 | } |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Get pixel colors |
||
| 562 | * |
||
| 563 | * @param resource $img |
||
| 564 | * @param int $x |
||
| 565 | * @param int $y |
||
| 566 | * @return array |
||
| 567 | */ |
||
| 568 | 2 | private static function getPixelColor($img, $x, $y) |
|
| 572 | |||
| 573 | /** |
||
| 574 | * Ajusta o numero para o multiplo mais proximo de base |
||
| 575 | * |
||
| 576 | * @param float $num |
||
| 577 | * @param int $num |
||
| 578 | * @return int |
||
| 579 | */ |
||
| 580 | 3 | private function closestMultiple($num = 0, $base = 8) |
|
| 581 | { |
||
| 582 | 3 | $iNum = ceil($num); |
|
| 588 | } |
||
| 589 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: