@@ -509,9 +509,10 @@ public function place(Image $image, $left = 0, $top = 0, int $opacity = 100): se
509509 * @param string filename
510510 * @param int quality (0..100 for JPEG and WEBP, 0..9 for PNG)
511511 * @param int optional image type
512- * @return bool TRUE on success or FALSE on failure.
512+ * @return void
513+ * @throws ImageException
513514 */
514- public function save (string $ file = NULL , int $ quality = NULL , int $ type = NULL ): bool
515+ public function save (string $ file = NULL , int $ quality = NULL , int $ type = NULL )
515516 {
516517 if ($ type === NULL ) {
517518 $ extensions = array_flip (self ::$ formats ) + ['jpg ' => self ::JPEG ];
@@ -525,22 +526,29 @@ public function save(string $file = NULL, int $quality = NULL, int $type = NULL)
525526 switch ($ type ) {
526527 case self ::JPEG :
527528 $ quality = $ quality === NULL ? 85 : max (0 , min (100 , (int ) $ quality ));
528- return imagejpeg ($ this ->image , $ file , $ quality );
529+ $ success = imagejpeg ($ this ->image , $ file , $ quality );
530+ break ;
529531
530532 case self ::PNG :
531533 $ quality = $ quality === NULL ? 9 : max (0 , min (9 , (int ) $ quality ));
532- return imagepng ($ this ->image , $ file , $ quality );
534+ $ success = imagepng ($ this ->image , $ file , $ quality );
535+ break ;
533536
534537 case self ::GIF :
535- return imagegif ($ this ->image , $ file );
538+ $ success = imagegif ($ this ->image , $ file );
539+ break ;
536540
537541 case self ::WEBP :
538542 $ quality = $ quality === NULL ? 80 : max (0 , min (100 , (int ) $ quality ));
539- return imagewebp ($ this ->image , $ file , $ quality );
543+ $ success = imagewebp ($ this ->image , $ file , $ quality );
544+ break ;
540545
541546 default :
542547 throw new Nette \InvalidArgumentException ("Unsupported image type ' $ type'. " );
543548 }
549+ if (!$ success ) {
550+ throw new ImageException (error_get_last ()['message ' ]);
551+ }
544552 }
545553
546554
@@ -579,15 +587,16 @@ public function __toString(): string
579587 * Outputs image to browser.
580588 * @param int image type
581589 * @param int quality (0..100 for JPEG and WEBP, 0..9 for PNG)
582- * @return bool TRUE on success or FALSE on failure.
590+ * @return void
591+ * @throws ImageException
583592 */
584- public function send (int $ type = self ::JPEG , int $ quality = NULL ): bool
593+ public function send (int $ type = self ::JPEG , int $ quality = NULL )
585594 {
586595 if (!isset (self ::$ formats [$ type ])) {
587596 throw new Nette \InvalidArgumentException ("Unsupported image type ' $ type'. " );
588597 }
589598 header ('Content-Type: image/ ' . self ::$ formats [$ type ]);
590- return $ this ->save (NULL , $ quality , $ type );
599+ $ this ->save (NULL , $ quality , $ type );
591600 }
592601
593602
0 commit comments