@@ -100,7 +100,7 @@ gdImagePtr gdImageCreateFromWebpCtx (gdIOCtx * infile)
100100 return im ;
101101}
102102
103- void gdImageWebpCtx (gdImagePtr im , gdIOCtx * outfile , int quantization )
103+ void gdImageWebpCtx (gdImagePtr im , gdIOCtx * outfile , int quality )
104104{
105105 uint8_t * argb ;
106106 int x , y ;
@@ -117,8 +117,8 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization)
117117 return ;
118118 }
119119
120- if (quantization == -1 ) {
121- quantization = 80 ;
120+ if (quality == -1 ) {
121+ quality = 80 ;
122122 }
123123
124124 if (overflow2 (gdImageSX (im ), 4 )) {
@@ -151,7 +151,13 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization)
151151 * (p ++ ) = a ;
152152 }
153153 }
154- out_size = WebPEncodeRGBA (argb , gdImageSX (im ), gdImageSY (im ), gdImageSX (im ) * 4 , quantization , & out );
154+
155+ if (quality >= gdWebpLossless ) {
156+ out_size = WebPEncodeLosslessRGBA (argb , gdImageSX (im ), gdImageSY (im ), gdImageSX (im ) * 4 , & out );
157+ } else {
158+ out_size = WebPEncodeRGBA (argb , gdImageSX (im ), gdImageSY (im ), gdImageSX (im ) * 4 , quality , & out );
159+ }
160+
155161 if (out_size == 0 ) {
156162 zend_error (E_ERROR , "gd-webp encoding failed" );
157163 goto freeargb ;
@@ -163,10 +169,10 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization)
163169 gdFree (argb );
164170}
165171
166- void gdImageWebpEx (gdImagePtr im , FILE * outFile , int quantization )
172+ void gdImageWebpEx (gdImagePtr im , FILE * outFile , int quality )
167173{
168174 gdIOCtx * out = gdNewFileCtx (outFile );
169- gdImageWebpCtx (im , out , quantization );
175+ gdImageWebpCtx (im , out , quality );
170176 out -> gd_free (out );
171177}
172178
@@ -188,11 +194,11 @@ void * gdImageWebpPtr (gdImagePtr im, int *size)
188194 return rv ;
189195}
190196
191- void * gdImageWebpPtrEx (gdImagePtr im , int * size , int quantization )
197+ void * gdImageWebpPtrEx (gdImagePtr im , int * size , int quality )
192198{
193199 void * rv ;
194200 gdIOCtx * out = gdNewDynamicCtx (2048 , NULL );
195- gdImageWebpCtx (im , out , quantization );
201+ gdImageWebpCtx (im , out , quality );
196202 rv = gdDPExtractData (out , size );
197203 out -> gd_free (out );
198204 return rv ;
0 commit comments