QRimage

The Gravity Forms QRimage class.

Defined (1)

The class is defined in the following location(s).

/includes/phpqrcode/phpqrcode.php  
  1. class QRimage { 
  2.  
  3. //---------------------------------------------------------------------- 
  4. public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint=FALSE) 
  5. $image = self::image($frame, $pixelPerPoint, $outerFrame); 
  6.  
  7. if ($filename === false) { 
  8. Header("Content-type: image/png"); 
  9. ImagePng($image); 
  10. } else { 
  11. if($saveandprint===TRUE) { 
  12. ImagePng($image, $filename); 
  13. header("Content-type: image/png"); 
  14. ImagePng($image); 
  15. }else{ 
  16. ImagePng($image, $filename); 
  17.  
  18. ImageDestroy($image); 
  19.  
  20. //---------------------------------------------------------------------- 
  21. public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) 
  22. $image = self::image($frame, $pixelPerPoint, $outerFrame); 
  23.  
  24. if ($filename === false) { 
  25. Header("Content-type: image/jpeg"); 
  26. ImageJpeg($image, null, $q); 
  27. } else { 
  28. ImageJpeg($image, $filename, $q); 
  29.  
  30. ImageDestroy($image); 
  31.  
  32. //---------------------------------------------------------------------- 
  33. private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) 
  34. $h = count($frame); 
  35. $w = strlen($frame[0]); 
  36.  
  37. $imgW = $w + 2*$outerFrame; 
  38. $imgH = $h + 2*$outerFrame; 
  39.  
  40. $base_image =ImageCreate($imgW, $imgH); 
  41.  
  42. $col[0] = ImageColorAllocate($base_image, 255, 255, 255); 
  43. $col[1] = ImageColorAllocate($base_image, 0, 0, 0); 
  44.  
  45. imagefill($base_image, 0, 0, $col[0]); 
  46.  
  47. for($y=0; $y<$h; $y++) { 
  48. for($x=0; $x<$w; $x++) { 
  49. if ($frame[$y][$x] == '1') { 
  50. ImageSetPixel($base_image, $x+$outerFrame, $y+$outerFrame, $col[1]); 
  51.  
  52. $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); 
  53. ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); 
  54. ImageDestroy($base_image); 
  55.  
  56. return $target_image;