@@ -203,11 +203,7 @@ public function imageCreateJpegfromExif($filename)
203
203
}
204
204
205
205
if ($ orientation === 5 || $ orientation === 4 || $ orientation === 7 ) {
206
- if (function_exists ('imageflip ' )) {
207
- imageflip ($ img , IMG_FLIP_HORIZONTAL );
208
- } else {
209
- $ this ->imageFlip ($ img , IMG_FLIP_HORIZONTAL );
210
- }
206
+ imageflip ($ img , IMG_FLIP_HORIZONTAL );
211
207
}
212
208
213
209
return $ img ;
@@ -455,12 +451,12 @@ public function resizeToLongSide($max_long, $allow_enlarge = false)
455
451
{
456
452
if ($ this ->getSourceHeight () > $ this ->getSourceWidth ()) {
457
453
$ ratio = $ max_long / $ this ->getSourceHeight ();
458
- $ short = $ this ->getSourceWidth () * $ ratio ;
454
+ $ short = ( int ) ( $ this ->getSourceWidth () * $ ratio) ;
459
455
460
456
$ this ->resize ($ short , $ max_long , $ allow_enlarge );
461
457
} else {
462
458
$ ratio = $ max_long / $ this ->getSourceWidth ();
463
- $ short = $ this ->getSourceHeight () * $ ratio ;
459
+ $ short = ( int ) ( $ this ->getSourceHeight () * $ ratio) ;
464
460
465
461
$ this ->resize ($ max_long , $ short , $ allow_enlarge );
466
462
}
@@ -478,7 +474,7 @@ public function resizeToLongSide($max_long, $allow_enlarge = false)
478
474
public function resizeToHeight ($ height , $ allow_enlarge = false )
479
475
{
480
476
$ ratio = $ height / $ this ->getSourceHeight ();
481
- $ width = $ this ->getSourceWidth () * $ ratio ;
477
+ $ width = ( int ) ( $ this ->getSourceWidth () * $ ratio) ;
482
478
483
479
$ this ->resize ($ width , $ height , $ allow_enlarge );
484
480
@@ -495,7 +491,7 @@ public function resizeToHeight($height, $allow_enlarge = false)
495
491
public function resizeToWidth ($ width , $ allow_enlarge = false )
496
492
{
497
493
$ ratio = $ width / $ this ->getSourceWidth ();
498
- $ height = $ this ->getSourceHeight () * $ ratio ;
494
+ $ height = ( int ) ( $ this ->getSourceHeight () * $ ratio) ;
499
495
500
496
$ this ->resize ($ width , $ height , $ allow_enlarge );
501
497
@@ -518,11 +514,11 @@ public function resizeToBestFit($max_width, $max_height, $allow_enlarge = false)
518
514
519
515
$ ratio = $ this ->getSourceHeight () / $ this ->getSourceWidth ();
520
516
$ width = $ max_width ;
521
- $ height = $ width * $ ratio ;
517
+ $ height = ( int ) ( $ width * $ ratio) ;
522
518
523
519
if ($ height > $ max_height ) {
524
520
$ height = $ max_height ;
525
- $ width = (int ) round ($ height / $ ratio );
521
+ $ width = (int ) ($ height / $ ratio );
526
522
}
527
523
528
524
return $ this ->resize ($ width , $ height , $ allow_enlarge );
@@ -536,8 +532,8 @@ public function resizeToBestFit($max_width, $max_height, $allow_enlarge = false)
536
532
*/
537
533
public function scale ($ scale )
538
534
{
539
- $ width = $ this ->getSourceWidth () * $ scale / 100 ;
540
- $ height = $ this ->getSourceHeight () * $ scale / 100 ;
535
+ $ width = ( int ) ( $ this ->getSourceWidth () * $ scale / 100 ) ;
536
+ $ height = ( int ) ( $ this ->getSourceHeight () * $ scale / 100 ) ;
541
537
542
538
$ this ->resize ($ width , $ height , true );
543
539
@@ -608,7 +604,7 @@ public function crop($width, $height, $allow_enlarge = false, $position = self::
608
604
if ($ ratio_dest < $ ratio_source ) {
609
605
$ this ->resizeToHeight ($ height , $ allow_enlarge );
610
606
611
- $ excess_width = ($ this ->getDestWidth () - $ width ) / $ this ->getDestWidth () * $ this ->getSourceWidth ( );
607
+ $ excess_width = (int ) (( $ this ->getDestWidth () - $ width ) * $ this ->getSourceWidth () / $ this ->getDestWidth () );
612
608
613
609
$ this ->source_w = $ this ->getSourceWidth () - $ excess_width ;
614
610
$ this ->source_x = $ this ->getCropPosition ($ excess_width , $ position );
@@ -617,7 +613,7 @@ public function crop($width, $height, $allow_enlarge = false, $position = self::
617
613
} else {
618
614
$ this ->resizeToWidth ($ width , $ allow_enlarge );
619
615
620
- $ excess_height = ($ this ->getDestHeight () - $ height ) / $ this ->getDestHeight () * $ this ->getSourceHeight ( );
616
+ $ excess_height = (int ) (( $ this ->getDestHeight () - $ height ) * $ this ->getSourceHeight () / $ this ->getDestHeight () );
621
617
622
618
$ this ->source_h = $ this ->getSourceHeight () - $ excess_height ;
623
619
$ this ->source_y = $ this ->getCropPosition ($ excess_height , $ position );
@@ -727,60 +723,13 @@ protected function getCropPosition($expectedSize, $position = self::CROPCENTER)
727
723
return $ size ;
728
724
}
729
725
730
- /**
731
- * Flips an image using a given mode if PHP version is lower than 5.5
732
- *
733
- * @param resource $image
734
- * @param integer $mode
735
- * @return null
736
- */
737
- public function imageFlip ($ image , $ mode )
738
- {
739
- switch ($ mode ) {
740
- case self ::IMG_FLIP_HORIZONTAL : {
741
- $ max_x = imagesx ($ image ) - 1 ;
742
- $ half_x = $ max_x / 2 ;
743
- $ sy = imagesy ($ image );
744
- $ temp_image = imageistruecolor ($ image )? imagecreatetruecolor (1 , $ sy ): imagecreate (1 , $ sy );
745
- for ($ x = 0 ; $ x < $ half_x ; ++$ x ) {
746
- imagecopy ($ temp_image , $ image , 0 , 0 , $ x , 0 , 1 , $ sy );
747
- imagecopy ($ image , $ image , $ x , 0 , $ max_x - $ x , 0 , 1 , $ sy );
748
- imagecopy ($ image , $ temp_image , $ max_x - $ x , 0 , 0 , 0 , 1 , $ sy );
749
- }
750
- break ;
751
- }
752
- case self ::IMG_FLIP_VERTICAL : {
753
- $ sx = imagesx ($ image );
754
- $ max_y = imagesy ($ image ) - 1 ;
755
- $ half_y = $ max_y / 2 ;
756
- $ temp_image = imageistruecolor ($ image )? imagecreatetruecolor ($ sx , 1 ): imagecreate ($ sx , 1 );
757
- for ($ y = 0 ; $ y < $ half_y ; ++$ y ) {
758
- imagecopy ($ temp_image , $ image , 0 , 0 , 0 , $ y , $ sx , 1 );
759
- imagecopy ($ image , $ image , 0 , $ y , 0 , $ max_y - $ y , $ sx , 1 );
760
- imagecopy ($ image , $ temp_image , 0 , $ max_y - $ y , 0 , 0 , $ sx , 1 );
761
- }
762
- break ;
763
- }
764
- case self ::IMG_FLIP_BOTH : {
765
- $ sx = imagesx ($ image );
766
- $ sy = imagesy ($ image );
767
- $ temp_image = imagerotate ($ image , 180 , 0 );
768
- imagecopy ($ image , $ temp_image , 0 , 0 , 0 , 0 , $ sx , $ sy );
769
- break ;
770
- }
771
- default :
772
- return null ;
773
- }
774
- imagedestroy ($ temp_image );
775
- }
776
-
777
726
/**
778
727
* Enable or not the gamma color correction on the image, enabled by default
779
728
*
780
729
* @param bool $enable
781
730
* @return static
782
731
*/
783
- public function gamma ($ enable = true )
732
+ public function gamma ($ enable = false )
784
733
{
785
734
$ this ->gamma_correct = $ enable ;
786
735
0 commit comments