diff --git a/spec/Zpl/ImageSpec.php b/spec/Zpl/ImageSpec.php index 85e4cbc..7cb7c6b 100644 --- a/spec/Zpl/ImageSpec.php +++ b/spec/Zpl/ImageSpec.php @@ -26,6 +26,14 @@ function it_converts_large_images_to_compressed_ascii_hexadecimal_bitmaps() $this->toAscii()->shouldReturn(file_get_contents(__DIR__ . '/../test_1000.txt')); } + + function it_interpets_transparent_as_white() + { + $decoder = GdDecoder::fromPath(__DIR__ . '/../test_85.png'); + $this->beConstructedWith($decoder); + + $this->toAscii()->shouldReturn(trim(file_get_contents(__DIR__ . '/../test_85.txt'))); + } function it_gets_the_height_of_the_image_in_rows() { diff --git a/spec/test_85.png b/spec/test_85.png new file mode 100644 index 0000000..56bc2b9 Binary files /dev/null and b/spec/test_85.png differ diff --git a/spec/test_85.txt b/spec/test_85.txt new file mode 100644 index 0000000..72a1b3e --- /dev/null +++ b/spec/test_85.txt @@ -0,0 +1 @@ +Q03,Q078,Q0DC,Q09C,P019A,P0369,P036C8,P02EC8,K01EI07EC4,K01FC005EC4,K01C700DEC2,K0259C0DFC2,K026E70FF4,K026F18BFC1,K0237CDBEC1,K0237F7BEC,K021BFBDEC,K020DFDEEC08,K020EFEF6C08,K02067F76C08,K02033FBA808,K02019FDD808,K0200EFFD8080FFC,K020073EF8087IF,K020039E7009JFC,K02I0E5F00KFE,K02I07A301LF,K03I01C107LF8,K01J0C08MFC,K01L01MFC,K01L03MFE,K018K03MFE,L08K01NF,L08K011MF,L08K01F7FF7IF,L04L03DFF9IF8,L02M07F4EIF8,L018L01F43BFF8,M06M0740EFF8,M01CL01C03BF8,N03F8N0FF8,Y07F8,Y01F,,U04,U0406,Q08001013,Q0E0010218,Q0AJ021C,I03F8J01AJ021C,001IFJ01FK01C,007IF8I01F8I022C,00JFEI03E8J064,03KFI03F4J0DC,03KF8007FAJ07C,07KFC007FDJ038,0LFC007FE8,0LFE00FFEC,1LFE00IF4,1LFE00IFC,3MF01IF,1MF01IF,1JFE1F01IF8,1JF80600IFC,3JFK0IFA,3JFK0DFFD,3JFK07IF8,7JFK06IF8,7JFK03IF8,7JF8J01FFEC,7JF8K0IFC,7JFCK07BE8,KFCK03FF8,KF8L0FF,JFE,:KF,KF8,7JF8,7JFC,::3JF4,3JFC,1JF8,0IFD,0JF,07IF,01FFE,007F8,,::::::::: diff --git a/src/Zpl/GdDecoder.php b/src/Zpl/GdDecoder.php index 2d974b2..5e893d9 100644 --- a/src/Zpl/GdDecoder.php +++ b/src/Zpl/GdDecoder.php @@ -29,6 +29,19 @@ public function __construct($image) imagepalettetotruecolor($image); } + // Converts transparancy to white. + $width = imagesx($image); + $height = imagesy($image); + $newImage = imagecreatetruecolor($width, $height); + $white = imagecolorallocate($newImage, 255, 255, 255); + imagefill($newImage, 0, 0, $white); + imagecopyresampled( + $newImage, $image, + 0, 0, 0, 0, + $width, $height, + $width, $height); + $image = $newImage; + imagefilter($image, IMG_FILTER_GRAYSCALE); $this->image = $image; @@ -119,3 +132,4 @@ public function getBitAt(int $x, int $y): int return (imagecolorat($this->image, $x, $y) & 0xFF) < 127 ? 1 : 0; } } +