Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Source: http://www.binarytides.com/compress-images-php-using-gd/
- function compress_image($src, $dest , $quality)
- {
- $info = getimagesize($src);
- if ($info['mime'] == 'image/jpeg')
- {
- $image = imagecreatefromjpeg($src);
- }
- elseif ($info['mime'] == 'image/gif')
- {
- $image = imagecreatefromgif($src);
- }
- elseif ($info['mime'] == 'image/png')
- {
- $image = imagecreatefrompng($src);
- }
- else
- {
- die('Unknown image file format');
- }
- //compress and save file to jpg
- imagejpeg($image, $dest, $quality);
- //return destination file
- return $dest;
- }
- //usage
- $compressed = compress_image('boy.jpg', 'destination.jpg', 50);
Add Comment
Please, Sign In to add comment