Advertisement
Guest User

Simple LED/FlipDot Display Generator

a guest
Sep 8th, 2012
1,819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2. // Aufruf: php lcdgen.php schwarzweissbild.png on.png off.png zieldateiname.png
  3.  
  4. $im = imagecreatefromstring(file_get_contents($argv[1]));
  5. $on = imagecreatefromstring(file_get_contents($argv[2]));
  6. $off = imagecreatefromstring(file_get_contents($argv[3]));
  7.  
  8. $imsize = getimagesize($argv[1]);
  9. $onoffsize = getimagesize($argv[2]);
  10.  
  11. $result = imagecreatetruecolor($imsize[0] * $onoffsize[0], $imsize[1] * $onoffsize[1]);
  12.  
  13. for ($y = 0; $y < $imsize[1]; $y++) {
  14.     for ($x = 0; $x < $imsize[0]; $x++) {
  15.         $black = (imagecolorat($im, $x, $y) == 0);
  16.         echo $black ? "1" : "0";
  17.         imagecopy(
  18.             $result,
  19.             $black ? $on : $off,
  20.             // dest_x, dest_y,
  21.             $x * $onoffsize[0], $y * $onoffsize[1],
  22.             // src_x, src_y, src_w, src_h
  23.             0, 0, $onoffsize[0], $onoffsize[1]
  24.         );
  25.     }
  26.     echo "\n";
  27. }
  28.  
  29. imagepng($result, $argv[4]);
  30.  
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement