Encoder.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Intervention\Image\Gd;
  3. class Encoder extends \Intervention\Image\AbstractEncoder
  4. {
  5. /**
  6. * Processes and returns encoded image as JPEG string
  7. *
  8. * @return string
  9. */
  10. protected function processJpeg()
  11. {
  12. ob_start();
  13. imagejpeg($this->image->getCore(), null, $this->quality);
  14. $this->image->mime = image_type_to_mime_type(IMAGETYPE_JPEG);
  15. $buffer = ob_get_contents();
  16. ob_end_clean();
  17. return $buffer;
  18. }
  19. /**
  20. * Processes and returns encoded image as PNG string
  21. *
  22. * @return string
  23. */
  24. protected function processPng()
  25. {
  26. ob_start();
  27. $resource = $this->image->getCore();
  28. imagealphablending($resource, false);
  29. imagesavealpha($resource, true);
  30. imagepng($resource, null, -1);
  31. $this->image->mime = image_type_to_mime_type(IMAGETYPE_PNG);
  32. $buffer = ob_get_contents();
  33. ob_end_clean();
  34. return $buffer;
  35. }
  36. /**
  37. * Processes and returns encoded image as GIF string
  38. *
  39. * @return string
  40. */
  41. protected function processGif()
  42. {
  43. ob_start();
  44. imagegif($this->image->getCore());
  45. $this->image->mime = image_type_to_mime_type(IMAGETYPE_GIF);
  46. $buffer = ob_get_contents();
  47. ob_end_clean();
  48. return $buffer;
  49. }
  50. /**
  51. * Processes and returns encoded image as TIFF string
  52. *
  53. * @return string
  54. */
  55. protected function processTiff()
  56. {
  57. throw new \Intervention\Image\Exception\NotSupportedException(
  58. "TIFF format is not supported by Gd Driver."
  59. );
  60. }
  61. /**
  62. * Processes and returns encoded image as BMP string
  63. *
  64. * @return string
  65. */
  66. protected function processBmp()
  67. {
  68. throw new \Intervention\Image\Exception\NotSupportedException(
  69. "BMP format is not supported by Gd Driver."
  70. );
  71. }
  72. /**
  73. * Processes and returns encoded image as ICO string
  74. *
  75. * @return string
  76. */
  77. protected function processIco()
  78. {
  79. throw new \Intervention\Image\Exception\NotSupportedException(
  80. "ICO format is not supported by Gd Driver."
  81. );
  82. }
  83. /**
  84. * Processes and returns encoded image as PSD string
  85. *
  86. * @return string
  87. */
  88. protected function processPsd()
  89. {
  90. throw new \Intervention\Image\Exception\NotSupportedException(
  91. "PSD format is not supported by Gd Driver."
  92. );
  93. }
  94. }