Last active
April 10, 2019 13:41
-
-
Save ryanapil/0b3735c0da33e507194beba28885a590 to your computer and use it in GitHub Desktop.
PHP Image Compression Function
This file contains 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 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