Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Change the quality on png images #47

@spacedog4

Description

@spacedog4

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;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions