@@ -512,9 +512,10 @@ public function place(Image $image, $left = 0, $top = 0, int $opacity = 100): se
512
512
* @param string filename
513
513
* @param int quality (0..100 for JPEG and WEBP, 0..9 for PNG)
514
514
* @param int optional image type
515
- * @return bool TRUE on success or FALSE on failure.
515
+ * @return void
516
+ * @throws ImageException
516
517
*/
517
- public function save (string $ file = NULL , int $ quality = NULL , int $ type = NULL ): bool
518
+ public function save (string $ file = NULL , int $ quality = NULL , int $ type = NULL )
518
519
{
519
520
if ($ type === NULL ) {
520
521
$ extensions = array_flip (self ::$ formats ) + ['jpg ' => self ::JPEG ];
@@ -528,22 +529,29 @@ public function save(string $file = NULL, int $quality = NULL, int $type = NULL)
528
529
switch ($ type ) {
529
530
case self ::JPEG :
530
531
$ quality = $ quality === NULL ? 85 : max (0 , min (100 , (int ) $ quality ));
531
- return imagejpeg ($ this ->image , $ file , $ quality );
532
+ $ success = imagejpeg ($ this ->image , $ file , $ quality );
533
+ break ;
532
534
533
535
case self ::PNG :
534
536
$ quality = $ quality === NULL ? 9 : max (0 , min (9 , (int ) $ quality ));
535
- return imagepng ($ this ->image , $ file , $ quality );
537
+ $ success = imagepng ($ this ->image , $ file , $ quality );
538
+ break ;
536
539
537
540
case self ::GIF :
538
- return imagegif ($ this ->image , $ file );
541
+ $ success = imagegif ($ this ->image , $ file );
542
+ break ;
539
543
540
544
case self ::WEBP :
541
545
$ quality = $ quality === NULL ? 80 : max (0 , min (100 , (int ) $ quality ));
542
- return imagewebp ($ this ->image , $ file , $ quality );
546
+ $ success = imagewebp ($ this ->image , $ file , $ quality );
547
+ break ;
543
548
544
549
default :
545
550
throw new Nette \InvalidArgumentException ("Unsupported image type ' $ type'. " );
546
551
}
552
+ if (!$ success ) {
553
+ throw new ImageException (error_get_last ()['message ' ]);
554
+ }
547
555
}
548
556
549
557
@@ -582,9 +590,10 @@ public function __toString(): string
582
590
* Outputs image to browser.
583
591
* @param int image type
584
592
* @param int quality (0..100 for JPEG and WEBP, 0..9 for PNG)
585
- * @return bool TRUE on success or FALSE on failure.
593
+ * @return void
594
+ * @throws ImageException
586
595
*/
587
- public function send (int $ type = self ::JPEG , int $ quality = NULL ): bool
596
+ public function send (int $ type = self ::JPEG , int $ quality = NULL )
588
597
{
589
598
if (!isset (self ::$ formats [$ type ])) {
590
599
throw new Nette \InvalidArgumentException ("Unsupported image type ' $ type'. " );
0 commit comments