Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] img -> txt
zYm3N
post
Post #1





Grupa: Zarejestrowani
Postów: 49
Pomógł: 0
Dołączył: 29.08.2004
Skąd: POLAND

Ostrzeżenie: (0%)
-----


Może komuś się przyda/kogoś zainteresuje..

nie miałem gdzie tego rzucić:-)

http://imagelab.pl/zymen/ascii/

Działa dla jpg/png. Nad gif-ami pracuję :-)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Paul
post
Post #2





Grupa: Zarejestrowani
Postów: 636
Pomógł: 0
Dołączył: 22.10.2003
Skąd: Katowice

Ostrzeżenie: (0%)
-----


Moze troche OT bedzie (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) :

Napisalem kiedys troche inny skrypt, robiacy z obrazka htmlowa tabelke (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Cytat(spenalzo @ 2004-11-03 02:01:20)
mozilla przy 512 Ram ledwo chodzi...

Hehe... Mozilla wysiada (zaczyna żreć 150MB ramu i zwisa) na moim skrypcie przy obazkach 400x400 (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Nie mowiac juz o IE ktory powyzej 300x300 zaczyna gubic kolory w polowie komorek (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
  1. <?php
  2. function tohex($color){
  3. $color = dechex($color);
  4. if(strlen($color) == 1){
  5. $color = '0' . $color;
  6. }
  7. return $color;
  8. }
  9. $error = '';
  10. if( !empty($_GET['path']) ) { 
  11. $imgsize = @getimagesize($_GET['path']);
  12. list($szer, $wys) = $imgsize;
  13. switch($imgsize[ 'mime' ]) {
  14. case 'image/jpeg':
  15.  $img = imagecreatefromjpeg($_GET['path']);
  16. break;
  17. case 'image/png':
  18.  $img = imagecreatefrompng($_GET['path']);
  19. break;
  20. case 'image/gif':
  21.  $img = imagecreatefromgif($_GET['path']);
  22. break;
  23. default:
  24.  $error = '<b>Zły format pliku lub plik nie istnieje</b><br><br>';
  25. }
  26. $pixels = $szer * $wys;
  27. $wiersz = 0;
  28. $kolumna = 0;
  29. $px_szer = intval($_GET['px_szer']);
  30. $px_wys = intval($_GET['px_wys']);
  31. $cellspacing = intval($_GET['cellspacing']);
  32. if($px_szer < 1) {
  33. $px_szer = 1;
  34. }
  35. if($px_wys < 1) {
  36. $px_wys = 1;
  37. }
  38. if($cellspacing < 0) {
  39. $cellspacing = 0;
  40. }
  41. }
  42. echo '<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title></title><style type=\"text/css\">table, td{border: none;padding: 0px;color:#fff;font-family:verdana;font-size:10pt;}'. (isset($img) ? 'td{width:'. $px_wys .';height: '. $px_szer .';}' : '') .'body{background-color:#000;margin:0;padding:0;}a{color:#fff;}</style><meta http-equiv=\"Content-type\" content=\"text/html; charset=iso-8859-2\"></head><body><table style=\"width:100%;height:100%;\"><tr><td align=\"center\" style=\"width:100%;height:100%;\">';
  43.  
  44. if(!empty($error) || empty($_GET['path'])) {
  45. echo $error . '<form action=\"?\" style=\"margin:0;\"><table width=\"400\"><tr><td>Wpisz ścieżkę pliku (*.jpg, *.png, *.gif):</td><td><input type=\"text\" name=\"path\" value=\"'. (isset($_GET['path']) ? $_GET['path'] : '') .'\"></td></tr><tr><td>Szerokość piksela:</td><td><input type=\"text\" name=\"px_szer\" value=\"'. (isset($_GET['px_szer']) ? $_GET['px_szer'] : '') .'\"></td></tr><tr><td>Wysokość piksela:</td><td><input type=\"text\" name=\"px_wys\" value=\"'. (isset($_GET['px_wys']) ? $_GET['px_wys'] : '') .'\"></td></tr><tr><td>Odstęp między pikselami:</td><td><input type=\"text\" name=\"cellspacing\" value=\"'. (isset($_GET['cellspacing']) ? $_GET['cellspacing'] : '') .'\"></td></tr></table> <input type=\"submit\" value=\"OK\"></form>';
  46. } else {
  47.  echo '<table cellspacing=\"'. $cellspacing .'\"><tr>';
  48.  for($i=0; $i < $pixels; $i++) {
  49. $rgb = imagecolorsforindex($img, imagecolorat($img, $kolumna, $wiersz));
  50. echo '<td bgcolor=\"#'. tohex($rgb['red']) . tohex($rgb['green']) . tohex($rgb['blue']).'\"></td>';
  51. if($kolumna == $szer - 1) {
  52.  $wiersz++;
  53.  $kolumna = 0;
  54.  echo '</tr>';
  55.  if($i + 1 < $pixels) {
  56.  echo '<tr>';
  57.  }
  58.  
  59. } else {
  60.  $kolumna++;
  61. }
  62.  }
  63.  echo '</table><br><br><a href=\"javascript:history.back();\">Wróć</a>';
  64. }
  65. echo '</td></tr></table></body></html>';
  66. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 09:59