Skip to content

Commit

Permalink
Merge pull request #60 from robmachado/master
Browse files Browse the repository at this point in the history
[UPD] Algumas correções
  • Loading branch information
robmachado committed Jun 1, 2016
2 parents 04d962e + 20b7e89 commit 5bc85ff
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Graphics/Graphics.php
Expand Up @@ -60,9 +60,9 @@ public function __construct($filename = null, $width = null, $height = null)
/**
* Return a string of bytes
* for inclusion on printer commands
* This method change image to Black and White and
* This method change image to Black and White and
* reducing the color resolution of 1 bit per pixel
*
*
* @return string
*/
public function getRasterImage()
Expand Down Expand Up @@ -214,18 +214,18 @@ public function convert2BMP($filename = null)
public function loadBMP($filename)
{
//open file as binary
if(! $f1 = fopen($filename,"rb")) {
if (! $f1 = fopen($filename, "rb")) {
throw InvalidArgumentException('Can not open file.');
}
//get properties from image file
$file = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14));
$file = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14));
if ($file['file_type'] != 19778) {
throw InvalidArgumentException('This file is not a BMP image.');
}
//get properties form image
$bmp = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.
'/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
'/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1,40));
'/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40));
//check deep of colors
$bmp['colors'] = pow(2, $bmp['bits_per_pixel']);
if ($bmp['size_bitmap'] == 0) {
Expand Down Expand Up @@ -273,7 +273,7 @@ public function loadBMP($filename)

/**
* Get byte color form BMP
*
*
* @param integer $bpp bytes_per_pixel
* @param string $img bytes read of file
* @param string $vide
Expand All @@ -295,17 +295,17 @@ private function getBMPColor($bpp, $img, $vide, $p, $palette)
$color[1] = $red * 65536 + $green * 256 + $blue;
return $color;
break;
case 8:
case 8:
$color = unpack("n", $vide.substr($img, $p, 1));
$color[1] = $palette[$color[1]+1];
return $color;
break;
case 4:
$color = unpack("n", $vide.substr($img, floor($p), 1));
if (($p*2)%2 == 0) {
$color[1] = ($color[1] >> 4) ;
$color[1] = ($color[1] >> 4) ;
} else {
$color[1] = ($color[1] & 0x0F);
$color[1] = ($color[1] & 0x0F);
}
$color[1] = $palette[$color[1]+1];
return $color;
Expand Down Expand Up @@ -508,7 +508,7 @@ public function saveImage($filename = null, $data = null, $type = 'PNG', $qualit
case 'GIF':
$result = imagegif($data, $filename);
break;
default :
default:
$result = imagepng($data, $filename);
break;
}
Expand Down

0 comments on commit 5bc85ff

Please sign in to comment.