Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/Zpl/ImageSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Binary file added spec/test_85.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions spec/test_85.txt
Original file line number Diff line number Diff line change
@@ -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,,:::::::::
14 changes: 14 additions & 0 deletions src/Zpl/GdDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,3 +132,4 @@ public function getBitAt(int $x, int $y): int
return (imagecolorat($this->image, $x, $y) & 0xFF) < 127 ? 1 : 0;
}
}