Commit e23e10f18d9fe65163196a5aeae1df7c5cedd8e9
1 parent
3fa93d74
Brand server without requiring access to FS
PT: 1243391 Changed GD Methods to accept extention for type. Fixes image/x-png and similar mime type issues from rendering as unsupported. Updated by: Charl Joseph Mert
Showing
1 changed file
with
38 additions
and
51 deletions
plugins/ktcore/admin/manageBranding.php
| ... | ... | @@ -231,7 +231,7 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 231 | 231 | |
| 232 | 232 | $logoFile = 'var'.DIRECTORY_SEPARATOR.'branding'.DIRECTORY_SEPARATOR.'logo'.DIRECTORY_SEPARATOR.$logoFileName; |
| 233 | 233 | $ext = end(explode('.', end(explode(DIRECTORY_SEPARATOR, $logoFile)))); |
| 234 | - $type = $this->getMime($ext); | |
| 234 | + $type = $ext; | |
| 235 | 235 | |
| 236 | 236 | $imageWidth = $this->getImageWidth($logoFile, $type); |
| 237 | 237 | $imageHeight = $this->getImageHeight($logoFile, $type); |
| ... | ... | @@ -398,7 +398,9 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 398 | 398 | $this->errorRedirectToMain("The file you tried to upload is not supported."); |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | - | |
| 401 | + | |
| 402 | + $type = $ext; //GD Methods changed to accept extention as type | |
| 403 | + | |
| 402 | 404 | $logoFileName = 'logo_tmp_'.md5(Date('ymd-hms')).'.'.$ext; //Fighting the browser cache here |
| 403 | 405 | $logoFile = $logoDir.DIRECTORY_SEPARATOR.$logoFileName; |
| 404 | 406 | |
| ... | ... | @@ -439,6 +441,9 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 439 | 441 | |
| 440 | 442 | $logoFileNameCropped = 'logo_tmp_cropped_'.md5(Date('ymd-hms')).'.'.$ext; //Fighting the browser cache here |
| 441 | 443 | $logoFileCropped = $logoDir.DIRECTORY_SEPARATOR.$logoFileNameCropped; |
| 444 | + | |
| 445 | + $default->log->info($logoFileStretched); | |
| 446 | + $default->log->info($logoFileCropped); | |
| 442 | 447 | |
| 443 | 448 | //Creating stretched image |
| 444 | 449 | $res = $this->scaleImage($logoFile, $logoFileStretched, $this->maxLogoWidth, $this->maxLogoHeight, $type, false, false); |
| ... | ... | @@ -510,6 +515,8 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 510 | 515 | return 'jfif-tbnl'; |
| 511 | 516 | case 'image/png': |
| 512 | 517 | return 'png'; |
| 518 | + case 'image/x-png': | |
| 519 | + return 'png'; | |
| 513 | 520 | case 'image/jpeg': |
| 514 | 521 | return 'jpe'; |
| 515 | 522 | case 'image/jpeg': |
| ... | ... | @@ -542,7 +549,7 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 542 | 549 | * - Supported images are jpeg, png and gif |
| 543 | 550 | * |
| 544 | 551 | */ |
| 545 | - public function scaleImage( $origFile, $destFile, $width, $height, $type = 'image/jpeg', $scaleUp = false, $keepProportion = true) { | |
| 552 | + public function scaleImage( $origFile, $destFile, $width, $height, $type = 'jpg', $scaleUp = false, $keepProportion = true) { | |
| 546 | 553 | global $default; |
| 547 | 554 | |
| 548 | 555 | //Requires the GD library if not exit gracefully |
| ... | ... | @@ -552,21 +559,18 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 552 | 559 | } |
| 553 | 560 | |
| 554 | 561 | switch($type) { |
| 555 | - case 'image/jpeg': | |
| 556 | - $orig = imagecreatefromjpeg($origFile); | |
| 557 | - break; | |
| 558 | - case 'image/pjpeg': | |
| 562 | + case 'jpg': | |
| 559 | 563 | $orig = imagecreatefromjpeg($origFile); |
| 560 | 564 | break; |
| 561 | - case 'image/png': | |
| 565 | + case 'png': | |
| 562 | 566 | $orig = imagecreatefrompng($origFile); |
| 563 | 567 | break; |
| 564 | - case 'image/gif': | |
| 568 | + case 'gif': | |
| 565 | 569 | $orig = imagecreatefromgif($origFile); |
| 566 | 570 | break; |
| 567 | 571 | default: |
| 568 | 572 | //Handle Error |
| 569 | - $default->log->error("Tried to scale an unsupported file type: $type"); | |
| 573 | + $default->log->error("Tried to crop an unsupported file type: $type"); | |
| 570 | 574 | return false; |
| 571 | 575 | } |
| 572 | 576 | |
| ... | ... | @@ -600,21 +604,18 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 600 | 604 | imagecopyresampled($image, $orig, 0, 0, 0, 0, $image_x, $image_y, $orig_x, $orig_y); |
| 601 | 605 | |
| 602 | 606 | switch($type) { |
| 603 | - case 'image/jpeg': | |
| 604 | - imagejpeg($image, $destFile); | |
| 605 | - break; | |
| 606 | - case 'image/pjpeg': | |
| 607 | + case 'jpg': | |
| 607 | 608 | imagejpeg($image, $destFile); |
| 608 | 609 | break; |
| 609 | - case 'image/png': | |
| 610 | + case 'png': | |
| 610 | 611 | imagepng($image, $destFile); |
| 611 | 612 | break; |
| 612 | - case 'image/gif': | |
| 613 | + case 'gif': | |
| 613 | 614 | imagegif($image, $destFile); |
| 614 | 615 | break; |
| 615 | 616 | default: |
| 616 | 617 | //Handle Error |
| 617 | - $default->log->error("Tried to scale an unsupported file type: $type"); | |
| 618 | + $default->log->error("Tried to crop an unsupported file type: $type"); | |
| 618 | 619 | return false; |
| 619 | 620 | } |
| 620 | 621 | |
| ... | ... | @@ -700,24 +701,22 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 700 | 701 | } |
| 701 | 702 | |
| 702 | 703 | switch($type) { |
| 703 | - case 'image/jpeg': | |
| 704 | - $orig = imagecreatefromjpeg($origFile); | |
| 705 | - break; | |
| 706 | - case 'image/pjpeg': | |
| 704 | + case 'jpg': | |
| 707 | 705 | $orig = imagecreatefromjpeg($origFile); |
| 708 | 706 | break; |
| 709 | - case 'image/png': | |
| 707 | + case 'png': | |
| 710 | 708 | $orig = imagecreatefrompng($origFile); |
| 711 | 709 | break; |
| 712 | - case 'image/gif': | |
| 710 | + case 'gif': | |
| 713 | 711 | $orig = imagecreatefromgif($origFile); |
| 714 | 712 | break; |
| 715 | 713 | default: |
| 716 | 714 | //Handle Error |
| 717 | - $default->log->error("Tried to determine crop for an unsupported file type: $type"); | |
| 715 | + $default->log->error("Tried to crop an unsupported file type: $type"); | |
| 718 | 716 | return false; |
| 719 | 717 | } |
| 720 | 718 | |
| 719 | + | |
| 721 | 720 | if($orig) { |
| 722 | 721 | /* |
| 723 | 722 | * calculate the size of the new image. |
| ... | ... | @@ -753,21 +752,18 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 753 | 752 | } |
| 754 | 753 | |
| 755 | 754 | switch($type) { |
| 756 | - case 'image/jpeg': | |
| 757 | - $orig = imagecreatefromjpeg($origFile); | |
| 758 | - break; | |
| 759 | - case 'image/pjpeg': | |
| 755 | + case 'jpg': | |
| 760 | 756 | $orig = imagecreatefromjpeg($origFile); |
| 761 | 757 | break; |
| 762 | - case 'image/png': | |
| 758 | + case 'png': | |
| 763 | 759 | $orig = imagecreatefrompng($origFile); |
| 764 | 760 | break; |
| 765 | - case 'image/gif': | |
| 761 | + case 'gif': | |
| 766 | 762 | $orig = imagecreatefromgif($origFile); |
| 767 | 763 | break; |
| 768 | 764 | default: |
| 769 | 765 | //Handle Error |
| 770 | - $default->log->error("Tried to determine crop for an unsupported file type: $type"); | |
| 766 | + $default->log->error("Tried to crop an unsupported file type: $type"); | |
| 771 | 767 | return false; |
| 772 | 768 | } |
| 773 | 769 | |
| ... | ... | @@ -802,21 +798,18 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 802 | 798 | } |
| 803 | 799 | |
| 804 | 800 | switch($type) { |
| 805 | - case 'image/jpeg': | |
| 806 | - $orig = imagecreatefromjpeg($origFile); | |
| 807 | - break; | |
| 808 | - case 'image/pjpeg': | |
| 801 | + case 'jpg': | |
| 809 | 802 | $orig = imagecreatefromjpeg($origFile); |
| 810 | 803 | break; |
| 811 | - case 'image/png': | |
| 804 | + case 'png': | |
| 812 | 805 | $orig = imagecreatefrompng($origFile); |
| 813 | 806 | break; |
| 814 | - case 'image/gif': | |
| 807 | + case 'gif': | |
| 815 | 808 | $orig = imagecreatefromgif($origFile); |
| 816 | 809 | break; |
| 817 | 810 | default: |
| 818 | 811 | //Handle Error |
| 819 | - $default->log->error("Tried to determine crop for an unsupported file type: $type"); | |
| 812 | + $default->log->error("Tried to crop an unsupported file type: $type"); | |
| 820 | 813 | return false; |
| 821 | 814 | } |
| 822 | 815 | |
| ... | ... | @@ -842,7 +835,7 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 842 | 835 | * - Supported images are jpeg, png and gif |
| 843 | 836 | * |
| 844 | 837 | */ |
| 845 | - public function cropImage( $origFile, $destFile, $x1, $y1, $x2, $y2, $type = 'image/jpeg', $scaleUp = true) { | |
| 838 | + public function cropImage( $origFile, $destFile, $x1, $y1, $x2, $y2, $type = 'jpg', $scaleUp = true) { | |
| 846 | 839 | global $default; |
| 847 | 840 | |
| 848 | 841 | $width = $x2 - $x1; |
| ... | ... | @@ -855,16 +848,13 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 855 | 848 | } |
| 856 | 849 | |
| 857 | 850 | switch($type) { |
| 858 | - case 'image/jpeg': | |
| 859 | - $orig = imagecreatefromjpeg($origFile); | |
| 860 | - break; | |
| 861 | - case 'image/pjpeg': | |
| 851 | + case 'jpg': | |
| 862 | 852 | $orig = imagecreatefromjpeg($origFile); |
| 863 | 853 | break; |
| 864 | - case 'image/png': | |
| 854 | + case 'png': | |
| 865 | 855 | $orig = imagecreatefrompng($origFile); |
| 866 | 856 | break; |
| 867 | - case 'image/gif': | |
| 857 | + case 'gif': | |
| 868 | 858 | $orig = imagecreatefromgif($origFile); |
| 869 | 859 | break; |
| 870 | 860 | default: |
| ... | ... | @@ -885,16 +875,13 @@ class ManageBrandDispatcher extends KTAdminDispatcher { |
| 885 | 875 | //imagecopyresized($canvas, $piece, 0,0, $cropLeft, $cropHeight,$newwidth, $newheight, $width, $height); |
| 886 | 876 | |
| 887 | 877 | switch($type) { |
| 888 | - case 'image/jpeg': | |
| 889 | - imagejpeg($image, $destFile); | |
| 890 | - break; | |
| 891 | - case 'image/pjpeg': | |
| 878 | + case 'jpg': | |
| 892 | 879 | imagejpeg($image, $destFile); |
| 893 | 880 | break; |
| 894 | - case 'image/png': | |
| 881 | + case 'png': | |
| 895 | 882 | imagepng($image, $destFile); |
| 896 | 883 | break; |
| 897 | - case 'image/gif': | |
| 884 | + case 'gif': | |
| 898 | 885 | imagegif($image, $destFile); |
| 899 | 886 | break; |
| 900 | 887 | default: | ... | ... |