Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function compress_image($source_url, $destination_url, $quality) {
- $info = getimagesize($source_url);
- if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source_url);
- elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source_url);
- elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source_url);
- //save it
- imagejpeg($image, $destination_url, $quality);
- //return destination file url
- return $destination_url;
- }
- $source_photo = 'uploads/im.png';
- $dest_photo = 'uploads/im.png';
- $d = compress_image($source_photo, $dest_photo, 50); //50 merupakan berapa persen mau di kecilin pixelnya,semakin kecil persennya semakin besar pixel yg di tampilkan
- echo '
- <div style="float:left;margin-right:10px">
- <img src="'.$source_photo.'" alt="" />
- <br />'.filesize($source_photo).' Bytes
- </div>
- <div style="float:left;">
- <img src="'.$dest_photo.'" alt="" />
- <br />'.filesize($dest_photo).' Bytes
- </div>
- ';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement