Skip to content

Commit

Permalink
Added ptouch-img
Browse files Browse the repository at this point in the history
  • Loading branch information
talpadk committed Dec 5, 2015
1 parent 6b897bd commit 9394922
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ Usage: ptouch-img path_to_file

The image file may be a .png .jpg or .gif.
It must currently be 128 pixels high.
Only the red value of the pixels are considered in order to determine if a black pixel should be printed
Only the red value of the pixels are considered in order to determine if a black pixel should be printed

As an example from a fresh git clone:

sudo ./ptouch-utils/ptouch-img test/test.png
50 changes: 50 additions & 0 deletions ptouch-utils/ptouch-img
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/php
<?php


require_once('PtouchPrinter.php');


if (count($argv)!=2){
die("Usage: ptouch-img image_file_to_print\nP.s. the image must be 128 pixels tall\n");
}

$imageFile = $argv[1];

if (preg_match('/^(.*)\.(png|gif|jpg|jpeg)$/i', $imageFile, $matches)){
$image = false;
$suffix = strtolower($matches[2]);
switch ($suffix){
case 'png':
$image = imagecreatefrompng($imageFile);
break;
case 'gif':
$image = imagecreatefromgif($imageFile);
break;
case 'jpeg':
case 'jpg':
$image = imagecreatefromjpeg($imageFile);
break;
}

if ($image === false){
die("Failed to open image '$imageFile'\n");
}

$printer = new PtouchPrinter(false);
$errors = $printer->open();
if (is_null($errors)){
$printer->printImage($image);
}
else {
$printer->close();
die($errors);
}
$printer->close();
}
else {
die ("Unable to determine type type (png, gif or jpg) from '$filename'\n");
}


?>

0 comments on commit 9394922

Please sign in to comment.