Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/06/2010, 08:31
sergi_climent
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 4 meses
Puntos: 10
Crear y Guardar una imagen desde un Archivo PHP

Hola, me ha surgido una duda.

uso el siguiente codigo para generar codigo de barras:
Código PHP:
Ver original
  1. <?php
  2. /*===========================================================================*/
  3. /*      PHP Barcode Image Generator v1.0 [9/28/2000]
  4.         Copyright (C)2000 by Charles J. Scheffold - [email protected]
  5. //-----------------------------------------------------------------------------
  6. // Startup code
  7. //-----------------------------------------------------------------------------
  8. */
  9.  
  10.  
  11. if(isset($_GET["text"])) $text=$_GET["text"];
  12. if(isset($_GET["format"])) $format=$_GET["format"];
  13. if(isset($_GET["quality"])) $quality=$_GET["quality"];
  14. if(isset($_GET["width"])) $width=$_GET["width"];
  15. if(isset($_GET["height"])) $height=$_GET["height"];
  16. if(isset($_GET["type"])) $type=$_GET["type"];
  17. if(isset($_GET["barcode"])) $barcode=$_GET["barcode"];
  18.  
  19.  
  20.  
  21.  
  22. if (!isset ($text)) $text = 1;
  23. if (!isset ($type)) $type = 1;
  24. if (empty ($quality)) $quality = 100;
  25. if (empty ($width)) $width = 160;
  26. if (empty ($height)) $height = 80;
  27. if (!empty ($format)) $format = strtoupper ($format);
  28.         else $format="PNG";
  29.  
  30.  
  31. switch ($type)
  32. {
  33.         default:
  34.                 $type = 1;
  35.         case 1:
  36.                 Barcode39 ($barcode, $width, $height, $quality, $format, $text);
  37.                 break;          
  38. }
  39.  
  40.  
  41. //-----------------------------------------------------------------------------
  42. // Generate a Code 3 of 9 barcode
  43. //-----------------------------------------------------------------------------
  44. function Barcode39 ($barcode, $width, $height, $quality, $format, $text)
  45. {
  46.         switch ($format)
  47.         {
  48.                 default:
  49.                         $format = "JPEG";
  50.                 case "JPEG":
  51.                         header ("Content-type: image/jpeg");
  52.                         break;
  53.                 case "PNG":
  54.                         header ("Content-type: image/png");
  55.                         break;
  56.                 case "GIF":
  57.                         header ("Content-type: image/gif");
  58.                         break;
  59.         }
  60.  
  61.  
  62.         $im = ImageCreate ($width, $height)
  63.     or die ("Cannot Initialize new GD image stream");
  64.         $White = ImageColorAllocate ($im, 255, 255, 255);
  65.         $Black = ImageColorAllocate ($im, 0, 0, 0);
  66.         //ImageColorTransparent ($im, $White);
  67.         ImageInterLace ($im, 1);
  68.  
  69.  
  70.  
  71.         $NarrowRatio = 20;
  72.         $WideRatio = 55;
  73.         $QuietRatio = 35;
  74.  
  75.  
  76.         $nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio));
  77.         $Pixels = $width / $nChars;
  78.         $NarrowBar = (int)(20 * $Pixels);
  79.         $WideBar = (int)(55 * $Pixels);
  80.         $QuietBar = (int)(35 * $Pixels);
  81.  
  82.  
  83.         $ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2);
  84.        
  85.         if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0))
  86.         {
  87.                 ImageString ($im, 1, 0, 0, "Image is too small!", $Black);
  88.                 OutputImage ($im, $format, $quality);
  89.                 exit;
  90.         }
  91.        
  92.         $CurrentBarX = (int)(($width - $ActualWidth) / 2);
  93.         $Color = $White;
  94.         $BarcodeFull = "*".strtoupper ($barcode)."*";
  95.         settype ($BarcodeFull, "string");
  96.        
  97.         $FontNum = 3;
  98.         $FontHeight = ImageFontHeight ($FontNum);
  99.         $FontWidth = ImageFontWidth ($FontNum);
  100.         if ($text != 0)
  101.         {
  102.                 $CenterLoc = (int)(($width-1) / 2) - (int)(($FontWidth * strlen($BarcodeFull)) / 2);
  103.                 ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$BarcodeFull", $Black);
  104.         }
  105.         else
  106.         {
  107.             $FontHeight=-2;
  108.         }
  109.  
  110.  
  111.         for ($i=0; $i<strlen($BarcodeFull); $i++)
  112.         {
  113.                 $StripeCode = Code39 ($BarcodeFull[$i]);
  114.  
  115.  
  116.                 for ($n=0; $n < 9; $n++)
  117.                 {
  118.                         if ($Color == $White) $Color = $Black;
  119.                         else $Color = $White;
  120.  
  121.  
  122.                         switch ($StripeCode[$n])
  123.                         {
  124.                                 case '0':
  125.                                         ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$NarrowBar, $height-1-$FontHeight-2, $Color);
  126.                                         $CurrentBarX += $NarrowBar;
  127.                                         break;
  128.  
  129.  
  130.                                 case '1':
  131.                                         ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$WideBar, $height-1-$FontHeight-2, $Color);
  132.                                         $CurrentBarX += $WideBar;
  133.                                         break;
  134.                         }
  135.                 }
  136.  
  137.  
  138.                 $Color = $White;
  139.                 ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$QuietBar, $height-1-$FontHeight-2, $Color);
  140.                 $CurrentBarX += $QuietBar;
  141.         }
  142.  
  143.  
  144.         OutputImage ($im, $format, $quality);
  145. }
  146.  
  147.  
  148. //-----------------------------------------------------------------------------
  149. // Output an image to the browser
  150. //-----------------------------------------------------------------------------
  151. function OutputImage ($im, $format, $quality)
  152. {
  153.         switch ($format)
  154.         {
  155.                 case "JPEG":
  156.                         ImageJPEG ($im, "", $quality);
  157.                         break;
  158.                 case "PNG":
  159.                         ImagePNG ($im);
  160.                         break;
  161.                 case "GIF":
  162.                         ImageGIF ($im);
  163.                         break;
  164.         }
  165. }
  166.  
  167.  
  168. //-----------------------------------------------------------------------------
  169. // Returns the Code 3 of 9 value for a given ASCII character
  170. //-----------------------------------------------------------------------------
  171. function Code39 ($Asc)
  172. {
  173.         switch ($Asc)
  174.         {
  175.                 case ' ':
  176.                         return "011000100";    
  177.                 case '$':
  178.                         return "010101000";            
  179.                 case '%':
  180.                         return "000101010";
  181.                 case '*':
  182.                         return "010010100"; // * Start/Stop
  183.                 case '+':
  184.                         return "010001010";
  185.                 case '|':
  186.                         return "010000101";
  187.                 case '.':
  188.                         return "110000100";
  189.                 case '/':
  190.                         return "010100010";
  191.                 case '-':
  192.                         return "010000101";
  193.                 case '0':
  194.                         return "000110100";
  195.                 case '1':
  196.                         return "100100001";
  197.                 case '2':
  198.                         return "001100001";
  199.                 case '3':
  200.                         return "101100000";
  201.                 case '4':
  202.                         return "000110001";
  203.                 case '5':
  204.                         return "100110000";
  205.                 case '6':
  206.                         return "001110000";
  207.                 case '7':
  208.                         return "000100101";
  209.                 case '8':
  210.                         return "100100100";
  211.                 case '9':
  212.                         return "001100100";
  213.                 case 'A':
  214.                         return "100001001";
  215.                 case 'B':
  216.                         return "001001001";
  217.                 case 'C':
  218.                         return "101001000";
  219.                 case 'D':
  220.                         return "000011001";
  221.                 case 'E':
  222.                         return "100011000";
  223.                 case 'F':
  224.                         return "001011000";
  225.                 case 'G':
  226.                         return "000001101";
  227.                 case 'H':
  228.                         return "100001100";
  229.                 case 'I':
  230.                         return "001001100";
  231.                 case 'J':
  232.                         return "000011100";
  233.                 case 'K':
  234.                         return "100000011";
  235.                 case 'L':
  236.                         return "001000011";
  237.                 case 'M':
  238.                         return "101000010";
  239.                 case 'N':
  240.                         return "000010011";
  241.                 case 'O':
  242.                         return "100010010";
  243.                 case 'P':
  244.                         return "001010010";
  245.                 case 'Q':
  246.                         return "000000111";
  247.                 case 'R':
  248.                         return "100000110";
  249.                 case 'S':
  250.                         return "001000110";
  251.                 case 'T':
  252.                         return "000010110";
  253.                 case 'U':
  254.                         return "110000001";
  255.                 case 'V':
  256.                         return "011000001";
  257.                 case 'W':
  258.                         return "111000000";
  259.                 case 'X':
  260.                         return "010010001";
  261.                 case 'Y':
  262.                         return "110010000";
  263.                 case 'Z':
  264.                         return "011010000";
  265.                 default:
  266.                         return "011000100";
  267.         }
  268. }
  269.  
  270. ?>

como puedo hacer para guardarme la imagen que me crea en un archivo?


Saludos y gracias
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier