Skip to content

Instantly share code, notes, and snippets.

@ryanapil
Last active April 10, 2019 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanapil/0b3735c0da33e507194beba28885a590 to your computer and use it in GitHub Desktop.
Save ryanapil/0b3735c0da33e507194beba28885a590 to your computer and use it in GitHub Desktop.
PHP Image Compression Function
function compress($source, $destination, $quality) {
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($source);
} elseif ($info['mime'] == 'image/gif') {
$image = imagecreatefromgif($source);
} elseif ($info['mime'] == 'image/png') {
$image = imagecreatefrompng($source);
}
imagejpeg($image, $destination, $quality);
return $destination;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment