Skip to content

Instantly share code, notes, and snippets.

@Boztown
Created August 21, 2013 16:16
Show Gist options
  • Save Boztown/6296607 to your computer and use it in GitHub Desktop.
Save Boztown/6296607 to your computer and use it in GitHub Desktop.
PHP image compress.
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