Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added include-blank-lines to preserve formatting #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion escimages.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"output-dir:",
"png",
"pbm",
"help"
"help",
"include-blank-lines"
);
$options = getopt($shortopts, $longopts);
$usage = "Usage: " . $argv[0] . " OPTIONS --file 'filename'\n";
Expand All @@ -34,6 +35,8 @@
// Default
$outputPng = true;
}
// Include blank lines
$blankLines = array_key_exists("include-blank-lines", $options);

if (empty($options) || ( $inputFile === null && !$showHelp)) {
// Incorrect usage shows error and quits nonzero
Expand All @@ -51,6 +54,7 @@
Output options:

-o, --output-dir DIRECTORY The directory to write output files to.
--include-blank-lines Output a 24px tall, 1px wide image for each line of text encountered.

Output format:

Expand Down Expand Up @@ -113,6 +117,26 @@
$bufferedImg = null;
}
}
if ($blankLines) {
if ($cmd -> isAvailableAs('LineBreak')) {
$imgNo = $imgNo + 1;
$outpFilename = $outputDir . '/' . "$receiptName-" . sprintf('%02d', $imgNo);
echo "[ Image $imgNo: 1x24 ]\n";
if ($outputPbm) {
$data = "P4\n1 24\n 0000 0000 0000 0000 0000 0000";
file_put_contents($outpFilename.'.pbm',$data);
}
if ($outputPng) {
ob_start();
$png_image = imagecreate(1, 24);
imagecolorallocate($png_image, 255, 255, 255);
imagepng($png_image);
$data = ob_get_clean();
imagedestroy($png_image);
file_put_contents($outpFilename.'.png',$data);
}
}
}
}

// Just for debugging
Expand Down