File indexing completed on 2025-01-26 05:29:14
0001 <?php 0002 0003 namespace Intervention\Image\Gd; 0004 0005 class Encoder extends \Intervention\Image\AbstractEncoder 0006 { 0007 /** 0008 * Processes and returns encoded image as JPEG string 0009 * 0010 * @return string 0011 */ 0012 protected function processJpeg() 0013 { 0014 ob_start(); 0015 imagejpeg($this->image->getCore(), null, $this->quality); 0016 $this->image->mime = image_type_to_mime_type(IMAGETYPE_JPEG); 0017 $buffer = ob_get_contents(); 0018 ob_end_clean(); 0019 0020 return $buffer; 0021 } 0022 0023 /** 0024 * Processes and returns encoded image as PNG string 0025 * 0026 * @return string 0027 */ 0028 protected function processPng() 0029 { 0030 ob_start(); 0031 $resource = $this->image->getCore(); 0032 imagealphablending($resource, false); 0033 imagesavealpha($resource, true); 0034 imagepng($resource, null, -1); 0035 $this->image->mime = image_type_to_mime_type(IMAGETYPE_PNG); 0036 $buffer = ob_get_contents(); 0037 ob_end_clean(); 0038 0039 return $buffer; 0040 } 0041 0042 /** 0043 * Processes and returns encoded image as GIF string 0044 * 0045 * @return string 0046 */ 0047 protected function processGif() 0048 { 0049 ob_start(); 0050 imagegif($this->image->getCore()); 0051 $this->image->mime = image_type_to_mime_type(IMAGETYPE_GIF); 0052 $buffer = ob_get_contents(); 0053 ob_end_clean(); 0054 0055 return $buffer; 0056 } 0057 0058 protected function processWebp() 0059 { 0060 if ( ! function_exists('imagewebp')) { 0061 throw new \Intervention\Image\Exception\NotSupportedException( 0062 "Webp format is not supported by PHP installation." 0063 ); 0064 } 0065 0066 ob_start(); 0067 imagewebp($this->image->getCore(), null, $this->quality); 0068 $this->image->mime = defined('IMAGETYPE_WEBP') ? image_type_to_mime_type(IMAGETYPE_WEBP) : 'image/webp'; 0069 $buffer = ob_get_contents(); 0070 ob_end_clean(); 0071 0072 return $buffer; 0073 } 0074 0075 /** 0076 * Processes and returns encoded image as TIFF string 0077 * 0078 * @return string 0079 */ 0080 protected function processTiff() 0081 { 0082 throw new \Intervention\Image\Exception\NotSupportedException( 0083 "TIFF format is not supported by Gd Driver." 0084 ); 0085 } 0086 0087 /** 0088 * Processes and returns encoded image as BMP string 0089 * 0090 * @return string 0091 */ 0092 protected function processBmp() 0093 { 0094 throw new \Intervention\Image\Exception\NotSupportedException( 0095 "BMP format is not supported by Gd Driver." 0096 ); 0097 } 0098 0099 /** 0100 * Processes and returns encoded image as ICO string 0101 * 0102 * @return string 0103 */ 0104 protected function processIco() 0105 { 0106 throw new \Intervention\Image\Exception\NotSupportedException( 0107 "ICO format is not supported by Gd Driver." 0108 ); 0109 } 0110 0111 /** 0112 * Processes and returns encoded image as PSD string 0113 * 0114 * @return string 0115 */ 0116 protected function processPsd() 0117 { 0118 throw new \Intervention\Image\Exception\NotSupportedException( 0119 "PSD format is not supported by Gd Driver." 0120 ); 0121 } 0122 }