Created
August 21, 2013 16:16
-
-
Save Boztown/6296607 to your computer and use it in GitHub Desktop.
PHP image compress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function compressImage($source, $destination, $quality) { | |
$info = getimagesize($source); | |
switch($info['mime']) { | |
case "image/jpeg": | |
$image = imagecreatefromjpeg($source); | |
imagejpeg($image, $destination, $quality); | |
break; | |
case "image/gif": | |
$image = imagecreatefromgif($source); | |
imagegif($image, $destination, $quality); | |
break; | |
case "image/png": | |
$image = imagecreatefrompng($source); | |
imagepng($image, $destination, $quality); | |
break; | |
} | |
} | |
compressImage('source.png', 'destination.png', 85); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment