Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the quality on png images #47

Open
spacedog4 opened this issue Jun 24, 2016 · 1 comment
Open

Change the quality on png images #47

spacedog4 opened this issue Jun 24, 2016 · 1 comment

Comments

@spacedog4
Copy link
Contributor

If I upload an png image it becomes more then 4x the original size, you can't use the quality 0 - 100 on png images, but you can convert it using this code

                // *** Scale quality from 0-100 to 0-9
                $scaleQuality = round(($quality / 100) * 9);

                // *** Invert quality setting as 0 is best, not 9
                $invertScaleQuality = 9 - $scaleQuality;

the intire function:

switch (strtolower($pathinfo['extension'])) {
            case 'gif':
                $createHandler = 'imagecreatefromgif';
                $outputHandler = 'imagegif';
                $quality = null;
                break;
            case 'jpg':
            case 'jpeg':
                $createHandler = 'imagecreatefromjpeg';
                $outputHandler = 'imagejpeg';
                break;
            case 'png':
                $createHandler = 'imagecreatefrompng';
                $outputHandler = 'imagepng';

                // *** Scale quality from 0-100 to 0-9
                $scaleQuality = round(($quality / 100) * 9);

                // *** Invert quality setting as 0 is best, not 9
                $invertScaleQuality = 9 - $scaleQuality;

                $quality = $invertScaleQuality;
                break;
            default:
                return false;
        }
@szajbus
Copy link
Owner

szajbus commented Jun 27, 2016

@spacedog4 looking good, can you please submit a pull request? thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants