@@ -87,16 +87,25 @@ private function saveImage($to, $image, $quality)
8787
8888 switch ($ extension ) {
8989 case 'gif ' :
90- $ image = imagegif ($ image , $ to, $ quality );
90+ $ image = imagegif ($ image , $ to );
9191 break ;
9292 case 'jpg ' :
9393 case 'jpeg ' :
94+ if (isset ($ quality ) && ($ quality < -1 && $ quality > 100 )) {
95+ throw new \InvalidArgumentException (sprintf ('The %s quality is out of range ' , $ quality ));
96+ }
9497 $ image = imagejpeg ($ image , $ to , $ quality );
9598 break ;
9699 case 'png ' :
100+ if (isset ($ quality ) && ($ quality < -1 && $ quality > 9 )) {
101+ throw new \InvalidArgumentException (sprintf ('The %s quality is out of range ' , $ quality ));
102+ }
97103 $ image = imagepng ($ image , $ to , $ quality );
98104 break ;
99105 case 'webp ' :
106+ if (isset ($ quality ) && ($ quality < 0 || $ quality > 100 )) {
107+ throw new \InvalidArgumentException (sprintf ('The %s quality is out of range ' , $ quality ));
108+ }
100109 $ image = imagewebp ($ image , $ to , $ quality );
101110 break ;
102111 default :
@@ -167,5 +176,5 @@ private function makeDirectory($to)
167176 */
168177function convert ($ from , $ to , $ quality = -1 ) {
169178 $ converter = new ImageConverter ();
170- return $ converter ->convert ($ from , $ to , 5 );
179+ return $ converter ->convert ($ from , $ to , $ quality );
171180}
0 commit comments